在PBGL中打印边缘列表

时间:2015-06-22 16:32:17

标签: boost-graph

我有一个使用PB​​GL(boost 1.58)的简单程序,它创建一个无向图并打印指定进程的本地边列表。但是,仅对于零进程,列表(retcd = conn.Logon(0, False) 'This one DISPLAYS the pop-up )包含边缘描述符,而对于非零进程,列表为空,这很奇怪,不是吗?

程序文本如下:

edges(g)

进程0的输出:

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;
}

对于流程1:

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.

可以吗?或者代码中有错误?感谢任何帮助。谢谢。

最佳,    亚历

0 个答案:

没有答案