Printing edge list in PBGL

158 views Asked by At

I have a simple program using PBGL (boost 1.58) which creates an undirected graph and prints local edge list for the specified process. However, only for zero process the list (edges(g)) contains edge descriptors, while for non-zero processes the list is empty, which is strange, is it not?

The program text is following:

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

std::size_t nVertices = 16;

int main(int argc, char **argv) {
  boost::mpi::environment env(argc, argv);
  mpi_process_group pg;

  typedef adjacency_list<listS,
                         distributedS<mpi_process_group, vecS>,
                         undirectedS,
                         // Vertex properties
                         no_property,
                         // Edge properties
                         property<edge_weight_t, int> > Graph;
  Graph g(nVertices);

  if (process_id(pg) == 0) {
    std::cout << "MST Boost running..." << std::endl;
    std::cout << "\tnumber of mpi processes is " << num_processes(pg) << std::endl;
    std::cout << "\tnumber of vertices is " << nVertices << std::endl;
    std::cout << "\tnumber of edges is " << /*nEdges*/ nVertices << std::endl;
    std::cout << "Constructing graph...";

    for (int i = 0; i < nVertices; i++) {
      uint64_t s = (i < nVertices/2) ? 0 : nVertices/2;
      //uint64_t s = 0;
      uint64_t d = i;
      uint64_t w = rand();
      add_edge(vertex(s, g), vertex(d, g), w, g);
    }
    std::cout << "...completed" << std::endl;
  }

  synchronize(pg);
  typedef property_map<Graph, edge_weight_t>::type WeightMap;
  WeightMap weight_map = get(edge_weight, g);

  if (process_id(pg) == atoi(argv[1])){
    std::cout << "printing vertices:\n";
    Graph::vertex_iterator v, v_end;
    for (boost::tie(v,v_end) = vertices(g); v != v_end; v++) {
      std::cout << process_id(pg) << ": ("
        << local(*v) << "@" << owner(*v) << ")\n";
    }
    std::cout << "end of vertex list.\n";
    std::cout << "printing edges:\n";
    for (typename Graph::edge_iterator ei = edges(g).first; ei != edges(g).second; ei++) {
      std::cout << process_id(pg) << ": ("
        << local(source(*ei, g)) << "@" << owner(source(*ei,g)) << ","
        << local(target(*ei, g)) << "@" << owner(target(*ei,g)) << ","
        << get(weight_map, *ei) << ")\n";
    }
    std::cout << "end of edge list.\n";
  }

  return 0;
}

The output for process 0:

mpirun -np 2 ./simple_test 0

MST Boost running...
        number of mpi processes is 2
        number of vertices is 16
        number of edges is 16
Constructing graph......completed
printing vertices:
0: (0@0)
0: (1@0)
0: (2@0)
0: (3@0)
0: (4@0)
0: (5@0)
0: (6@0)
0: (7@0)
end of vertex list.
printing edges:
0: (0@0,0@0,1804289383)
0: (0@0,1@0,846930886)
0: (0@0,2@0,1681692777)
0: (0@0,3@0,1714636915)
0: (0@0,4@0,1957747793)
0: (0@0,5@0,424238335)
0: (0@0,6@0,719885386)
0: (0@0,7@0,1649760492)
0: (0@0,0@1,596516649)
0: (0@0,1@1,1189641421)
0: (0@0,2@1,1025202362)
0: (0@0,3@1,1350490027)
0: (0@0,4@1,783368690)
0: (0@0,5@1,1102520059)
0: (0@0,6@1,2044897763)
0: (0@0,7@1,1967513926)
end of edge list.

For process 1:

mpirun -np 2 ./simple_test 1

MST Boost running...
        number of mpi processes is 2
        number of vertices is 16
        number of edges is 16
Constructing graph......completed
printing vertices:
1: (0@1)
1: (1@1)
1: (2@1)
1: (3@1)
1: (4@1)
1: (5@1)
1: (6@1)
1: (7@1)
end of vertex list.
printing edges:
end of edge list.

Is it ok? or there is a bug in the code? Appreciate any help. Thank you.

Best, Alex

0

There are 0 answers