26#ifndef DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
27#define DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
33#include <dune/common/exceptions.hh>
44class ScotchGraphMapStrategy
47 ScotchGraphMapStrategy(std::size_t numProcessors,
double imbalanceRatio = 0.0,
int flag = SCOTCH_STRATDEFAULT)
49 if (SCOTCH_stratInit(&strategy_) != 0)
50 DUNE_THROW(Dune::Exception,
"Error initializing SCOTCH strategy!");
52 if (SCOTCH_stratGraphMapBuild(&strategy_,
static_cast<SCOTCH_Num
>(flag),
static_cast<SCOTCH_Num
>(numProcessors), imbalanceRatio) != 0)
53 DUNE_THROW(Dune::Exception,
"Error building SCOTCH strategy!");
57 ~ScotchGraphMapStrategy()
59 SCOTCH_stratExit(&strategy_);
64 {
return &strategy_; }
67 SCOTCH_Strat strategy_;
77template<
class IndexType =
int>
82 using Graph = std::vector<std::vector<IndexType>>;
85 static std::vector<IndexType>
partition(
const Graph& graph, std::size_t numProcessors)
87 std::vector<IndexType> targetProcessors;
88 partition(graph, numProcessors, targetProcessors);
89 return targetProcessors;
94 std::vector<IndexType>& targetProcessors)
97 ScotchGraph<IndexType> scotchGraph(graph);
98 ScotchGraphMapStrategy strategy(numProcessors);
103 const auto graphSize = graph.size();
104 std::vector<SCOTCH_Num> scotchPartitions(graphSize);
105 if (SCOTCH_graphPart(scotchGraph.data(),
static_cast<SCOTCH_Num
>(numProcessors), strategy.data(), scotchPartitions.data()) != 0)
106 DUNE_THROW(Dune::Exception,
"Error computing SCOTCH graph mapping!");
109 targetProcessors = std::vector<IndexType>(
110 scotchPartitions.begin(), scotchPartitions.end()
An interface to the scotch library for matrix reordering.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A reordering backend using the scotch library.
Definition: scotchpartitioner.hh:79
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchpartitioner.hh:82
static void partition(const Graph &graph, std::size_t numProcessors, std::vector< IndexType > &targetProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:93
static std::vector< IndexType > partition(const Graph &graph, std::size_t numProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:85