Search code examples
c++boostmpiboost-graph

Using `make_distributed_property_map` in PBGL


I'm trying to instantiate a property map for P-BGL PageRank. However, the documentation is out of date, as the signatures have changed from

template<typename Key, typename ProcessGroup, typename LocalPropertyMap>
distributed_property_map<ProcessGroup, LocalPropertyMap, Key>
make_distributed_property_map(const ProcessGroup& pg, LocalPropertyMap pmap);

and

template<typename Key, typename ProcessGroup, typename LocalPropertyMap,
         typename Reduce>
distributed_property_map<ProcessGroup, LocalPropertyMap, Key>
make_distributed_property_map(const ProcessGroup& pg, LocalPropertyMap pmap,
                              Reduce reduce);

to

template<typename ProcessGroup, typename GlobalMap, typename StorageMap>
inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>

template<typename ProcessGroup, typename GlobalMap, typename StorageMap,
         typename Reduce>
inline distributed_property_map<ProcessGroup, GlobalMap, StorageMap>
make_distributed_property_map(const ProcessGroup& pg, GlobalMap global,
                              StorageMap storage, Reduce reduce)

as of Boost 1.63, and I cannot seem to instantiate the correct model of the template parameters.

Here is a skeleton code with indicated gaps:

#include <boost/mpi.hpp>
#include <boost/graph/use_mpi.hpp>
#include <boost/graph/distributed/mpi_process_group.hpp>
#include <boost/graph/distributed/adjacency_list.hpp>
#include <boost/graph/erdos_renyi_generator.hpp>
#include <boost/random/linear_congruential.hpp>
#include <boost/graph/page_rank.hpp>

int main(int argc, char * argv[])
{
    boost::mpi::environment  env(argc, argv);
    boost::mpi::communicator comm;

    typedef boost::adjacency_list<boost::vecS,
            boost::distributedS<boost::graph::distributed::mpi_process_group, boost::vecS>,
            boost::directedS,
            // ????
    > Graph;
    typedef boost::erdos_renyi_iterator<boost::minstd_rand, Graph> generator;
    typedef boost::parallel::distributed_property_map<boost::graph::distributed::mpi_process_group,
            // ????
    > PropertyMap;

    boost::minstd_rand gen;

    Graph g(generator(gen, 100, 0.05), generator(), 100);


    auto map = boost::parallel::make_distributed_property_map< // ????
            boost::graph::distributed::mpi_process_group,
            // ???
            >process_group(g), ???);

    boost::graph::page_rank(g, map);

    return 0;
}

Any help is greatly appreciated, there is almost no documentation or examples available.


Solution

  • There's an unadvertised piece of test code example in graph_parallel/test/distributed_rmat_pagerank.cpp that does exactly what I wanted:

    typedef parallel::variant_distribution<mpi_process_group> Distribution;   Distribution distrib = parallel::block(pg, n);
    
    typedef adjacency_list<vecS, 
            distributedS<mpi_process_group, vecS>,
            bidirectionalS> Graph;
    
    Graph g(...);
    
    page_rank(g, make_iterator_property_map(ranks.begin(), get(boost::vertex_index, g)),
                graph::n_iterations(iters), 0.85, n);
    

    The code is available at https://github.com/boostorg/graph_parallel/blob/develop/test/distributed_rmat_pagerank.cpp.