[英]Using Boost Graph Library (BGL) in Fortran program
Is there anyway, I can use the graph data structure using the Boost Graph Library (BGL) inside my FORTRAN program. 无论如何,我可以在FORTRAN程序中使用Boost Graph Library(BGL)来使用图形数据结构。
Could anyone help me or give me a hint. 任何人都可以帮助我或给我一个提示。 I want to do parallel graph structure on several processors in my MPI-FORTRAN code. 我想在我的MPI-FORTRAN代码中的几个处理器上进行并行图结构。 Is it possible to use Boost Graph Library (BGL) for this purpose! 是否可以使用Boost Graph Library(BGL)来达到此目的!
Kind regards, Ziv 亲切的问候,Ziv
You would have to construct an intermediate layer, written in C++, that does all the templating in some special case useful for you and then call it from Fortran. 你必须构建一个用C ++编写的中间层,它在某些特殊情况下对你有用,然后从Fortran调用它。 bind(C)
and iso_c_binding
module are your friends. bind(C)
和iso_c_binding
模块是你的朋友。 I successfully use Boost based library CGAL in Fortran using this approach. 我使用这种方法成功地在Fortran中使用基于Boost的库CGAL。
Something along the lines of: 有点像:
my_bgl.cc: 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: 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
The function make_graph
returns an opaque pointer to a Graph from the points entered. 函数make_graph
从输入的点返回一个指向Graph的不透明指针。
No, boost is a C++ template library. 不,boost是一个C ++模板库。 Unless you port the code to FORTRAN, this is impossible. 除非您将代码移植到FORTRAN,否则这是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.