在Fortran程序中使用Boost Graph库(BGL)

Using Boost Graph Library (BGL) in Fortran program

本文关键字:Graph BGL Boost Fortran 程序      更新时间:2023-10-16

无论如何,我可以在我的fortran程序中使用Boost Graph库(BGL)使用图形数据结构。

任何人都可以帮助我或给我一个提示。我想在MPI-Fortran代码中的多个处理器上进行并行图结构。是否可以将Boost Graph库(BGL)用于此目的!

亲切的问候,ziv

您必须构造用C 编写的中间层,该中间层在某些特殊情况下对您有用的所有模板都对您有用,然后从Fortran调用它。bind(C)iso_c_binding模块是您的朋友。我使用这种方法成功地在Fortran中使用了基于Boost的库CGAL。

沿着:

的线条

my_bgl.cc:

  #include <boost/graph/graph_traits.hpp>
  #include <boost/graph/adjacency_list.hpp>
  using namespace boost;
extern "C"{  
  void* make_graph(int num_vertices, int num_edges, int *edge_array)
  {
    // create a typedef for the Graph type
    typedef adjacency_list<vecS, vecS, bidirectionalS> Graph;
    Graph *g = new Graph(num_vertices);
    // add the edges to the graph object
    for (int i = 0; i < num_edges; ++i)
      add_edge(edge_array[2*i], edge_array[2*i+1], *g);
    return g;
  }
}

my_bgl.f90:

module my_bgl
  use iso_c_binding
  interface
    type(c_ptr) function make_graph(num_vertices, num_edges, edge_array) bind(C,name="make_graph")
      import
      integer(c_int), value :: num_vertices
      integer(c_int), value :: num_edges
      integer(c_int) :: edge_array(2, num_edges)
    end function
  end interface
end module

函数make_graph从输入的点返回一个不透明的指针。

no,Boost是C 模板库。除非将代码移植到Fortran,否则这是不可能的。