c++ - 在 Fortran 程序中使用 Boost 图形库 (BGL)

标签 c++ boost fortran hybrid

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

谁能帮助我或给我提示。我想在我的 MPI-FORTRAN 代码中在多个处理器上执行并行图结构。是否可以为此目的使用 Boost 图形库 (BGL)!

亲切的问候, 齐夫

最佳答案

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

类似的东西:

我的_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;
  }
}

我的_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 函数从输入的点返回一个指向图形的不透明指针。

关于c++ - 在 Fortran 程序中使用 Boost 图形库 (BGL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21407166/

相关文章:

c++ - 表示 native 有符号和无符号整数大小的数据类型?

c++ - 混合架构?

c++ - c++ 哈希函数对密码来说是否相当安全?

c++ - apache httpd 模块的共享内存权限被拒绝错误

c++ - Boost序列化的向后兼容性问题1:73

c++ - SPEC CPU 基准测试中各种浮点运算的百分比

preprocessor - 适用于不同操作系统的 Gfortran 预处理器指令

c++ - std::random_shuffle 未播种

c++ - 使用一个数字数据成员为类定义所有比较运算符的便捷方法?

C++ Mongodb 驱动程序 v2.2 scons 在 Linux 上安装失败