26#ifndef DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
27#define DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
33#include <dune/common/exceptions.hh>
45class ScotchGraphMapStrategy
48 ScotchGraphMapStrategy(std::size_t numProcessors,
double imbalanceRatio = 0.0,
int flag = SCOTCH_STRATDEFAULT)
50 if (SCOTCH_stratInit(&strategy_) != 0)
51 DUNE_THROW(Dune::Exception,
"Error initializing SCOTCH strategy!");
53 if (SCOTCH_stratGraphMapBuild(&strategy_,
static_cast<SCOTCH_Num
>(flag),
static_cast<SCOTCH_Num
>(numProcessors), imbalanceRatio) != 0)
54 DUNE_THROW(Dune::Exception,
"Error building SCOTCH strategy!");
58 ~ScotchGraphMapStrategy()
60 SCOTCH_stratExit(&strategy_);
65 {
return &strategy_; }
68 SCOTCH_Strat strategy_;
79template<
class IndexType =
int>
84 using Graph = std::vector<std::vector<IndexType>>;
87 static std::vector<IndexType>
partition(
const Graph& graph, std::size_t numProcessors)
89 std::vector<IndexType> targetProcessors;
90 partition(graph, numProcessors, targetProcessors);
91 return targetProcessors;
96 std::vector<IndexType>& targetProcessors)
99 ScotchGraph<IndexType> scotchGraph(graph);
100 ScotchGraphMapStrategy strategy(numProcessors);
105 const auto graphSize = graph.size();
106 std::vector<SCOTCH_Num> scotchPartitions(graphSize);
107 if (SCOTCH_graphPart(scotchGraph.data(),
static_cast<SCOTCH_Num
>(numProcessors), strategy.data(), scotchPartitions.data()) != 0)
108 DUNE_THROW(Dune::Exception,
"Error computing SCOTCH graph mapping!");
111 targetProcessors = std::vector<IndexType>(
112 scotchPartitions.begin(), scotchPartitions.end()
An interface to the scotch library for matrix reordering.
Definition: scotchpartitioner.hh:81
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchpartitioner.hh:84
static void partition(const Graph &graph, std::size_t numProcessors, std::vector< IndexType > &targetProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:95
static std::vector< IndexType > partition(const Graph &graph, std::size_t numProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:87