Is there anyway, I can use the graph data structure using the Boost Graph Library (BGL) inside my FORTRAN program.
Could anyone help me or give me a hint. I want to do parallel graph structure on several processors in my MPI-FORTRAN code. Is it possible to use Boost Graph Library (BGL) for this purpose!
Kind regards, 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. bind(C) and iso_c_binding module are your friends. I successfully use Boost based library CGAL in Fortran using this approach.
Something along the lines of:
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
The function make_graph returns an opaque pointer to a Graph from the points entered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With