Boost logo

Boost Users :

Subject: [Boost-users] Problem with the parallel graph
From: Yeni Lora (yenisleidi.lora_at_[hidden])
Date: 2013-03-05 14:29:49


I am student of Computer Science in Universidad de Oriente from Cuba,
and I have a problem with the parallel graph, when I am adding edge
betwen two procesors and one of them change any property of my edge,
the other processor not update the property .
for example my code is :

#include "mpi.h"
#include <boost/config.hpp>
#include <boost/graph/use_mpi.hpp>
#include <boost/graph/distributed/mpi_process_group.hpp>
#include <boost/graph/distributed/adjacency_list.hpp>
#include <boost/property_map/parallel/distributed_property_map.hpp>
#include <boost/serialization/list.hpp>
#include <list>
using namespace std;

//===============================Vertex================================
struct Vertex{
   int id;
   // Serialization support is required!
   template<typename Archiver>
   void serialize(Archiver& ar, const unsigned int ) {
           ar & id ;
   }
    Vertex(int id = 0): id(id){}
};

//===============================Edge================================
struct Edge{

    int type;
    Edge( int type = 0): type(type){ }
    // Serialization support is required!
    template<typename Archiver>
    void serialize(Archiver& ar,const unsigned int ) {
            ar & type;
    }
};

using namespace boost;
using boost::graph::distributed::mpi_process_group;

typedef adjacency_list < listS, distributedS<mpi_process_group,
listS>, undirectedS, Vertex, Edge > Graph;
typedef typename Graph::edge_descriptor edge_descriptor;
typedef typename Graph::vertex_descriptor vertex_descriptor;

int main (int argc, char ** argv){
    boost::mpi::environment env(argc,argv);
    mpi::communicator world;
    Graph g;
    vertex_descriptor vi,vj;
    property_map<Graph, int Edge::*>::type type1 = get(&Edge::type, g);

    if (g.processor()==0)
        vi = add_vertex(Vertex(1),g);

    if (g.processor()==1)
        vj = add_vertex(Vertex(2),g);

    broadcast(world, vj, 1);
    broadcast(world, vi, 0);

    if (g.processor()==0){
        pair<edge_descriptor,bool> p = add_edge(vi, vj, Edge(1), g);
                std::cout<<"Process "<<g.processor()<<std::endl;
                std::cout<<"Process owner of edge "<<owner(p.first)<<std::endl;
                std::cout<<"Property type of edge
:"<<get(type1,p.first)<<std::endl;
    }
    synchronize(g);

    if (g.processor()==1){
                pair<edge_descriptor,bool> p = edge(vi, vj, g);
                if(p.second){
                        std::cout<<"\nProcess "<<g.processor()<<std::endl;
                        std::cout<<"Process owner of edge
"<<owner(p.first)<<std::endl;
                        put(type1,p.first,3);
                        std::cout<<"Change property type of edge
:"<<get(type1,p.first)<<std::endl;
                }
    }
    synchronize(g);

    if (g.processor()==0){
                pair<edge_descriptor,bool> p = edge(vi, vj, g);
                std::cout<<"\nProcess "<<g.processor()<<std::endl;
                std::cout<<"Property type of edge
:"<<get(type1,p.first)<<std::endl;
    }
    return 0;
}

The output:

Process 0
Process owner of edge 0
Property type of edge :1

Process 1
Process owner of edge 1
Change property type of edge :3

Process 0
Property type of edge :1

What can I do for resolve the problem?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net