【发布时间】:2014-01-28 13:40:53
【问题描述】:
无论如何,我可以在我的 FORTRAN 程序中使用 Boost Graph Library (BGL) 来使用图形数据结构。
任何人都可以帮助我或给我一个提示。我想在我的 MPI-FORTRAN 代码中的几个处理器上做并行图结构。是否可以为此目的使用 Boost Graph Library (BGL)!
亲切的问候, 齐夫
【问题讨论】:
无论如何,我可以在我的 FORTRAN 程序中使用 Boost Graph Library (BGL) 来使用图形数据结构。
任何人都可以帮助我或给我一个提示。我想在我的 MPI-FORTRAN 代码中的几个处理器上做并行图结构。是否可以为此目的使用 Boost Graph Library (BGL)!
亲切的问候, 齐夫
【问题讨论】:
您必须构建一个中间层,用 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从输入的点返回一个指向图表的不透明指针。
【讨论】:
不,boost 是一个 C++ 模板库。除非您将代码移植到 FORTRAN,否则这是不可能的。
【讨论】: