14#ifndef DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
15#define DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
21#include <dune/common/exceptions.hh>
32class ScotchGraphMapStrategy
35 ScotchGraphMapStrategy(std::size_t numProcessors,
double imbalanceRatio = 0.0,
int flag = SCOTCH_STRATDEFAULT)
37 if (SCOTCH_stratInit(&strategy_) != 0)
38 DUNE_THROW(Dune::Exception,
"Error initializing SCOTCH strategy!");
40 if (SCOTCH_stratGraphMapBuild(&strategy_,
static_cast<SCOTCH_Num
>(flag),
static_cast<SCOTCH_Num
>(numProcessors), imbalanceRatio) != 0)
41 DUNE_THROW(Dune::Exception,
"Error building SCOTCH strategy!");
45 ~ScotchGraphMapStrategy()
47 SCOTCH_stratExit(&strategy_);
52 {
return &strategy_; }
55 SCOTCH_Strat strategy_;
65template<
class IndexType =
int>
70 using Graph = std::vector<std::vector<IndexType>>;
73 static std::vector<IndexType>
partition(
const Graph& graph, std::size_t numProcessors)
75 std::vector<IndexType> targetProcessors;
76 partition(graph, numProcessors, targetProcessors);
77 return targetProcessors;
82 std::vector<IndexType>& targetProcessors)
85 ScotchGraph<IndexType> scotchGraph(graph);
86 ScotchGraphMapStrategy strategy(numProcessors);
91 const auto graphSize = graph.size();
92 std::vector<SCOTCH_Num> scotchPartitions(graphSize);
93 if (SCOTCH_graphPart(scotchGraph.data(),
static_cast<SCOTCH_Num
>(numProcessors), strategy.data(), scotchPartitions.data()) != 0)
94 DUNE_THROW(Dune::Exception,
"Error computing SCOTCH graph mapping!");
97 targetProcessors = std::vector<IndexType>(
98 scotchPartitions.begin(), scotchPartitions.end()
A reordering backend using the scotch library.
Definition: scotchpartitioner.hh:67
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchpartitioner.hh:70
static void partition(const Graph &graph, std::size_t numProcessors, std::vector< IndexType > &targetProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:81
static std::vector< IndexType > partition(const Graph &graph, std::size_t numProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:73
An interface to the scotch library for matrix reordering.