26#ifndef DUMUX_SCOTCH_BACKEND_HH
27#define DUMUX_SCOTCH_BACKEND_HH
43#warning "PTSCOTCH was not found on your system. Dumux::ScotchBackend won't do anything."
54template<
class IndexType>
59 using Graph = std::vector<std::vector<IndexType>>;
64 std::size_t numPasses = 5)
67 std::string strategy =
"g{pass= " + std::to_string(numPasses) +
"}";
73 std::string scotchStrategy =
"")
75 std::vector<int> permutation, inversePermutation;
82 std::vector<int>& permutation,
83 std::vector<int>& inversePermutation,
84 std::string scotchStrategy =
"")
88 const SCOTCH_Num vertnbr = graph.size();
92 std::vector<SCOTCH_Num> verttab;
93 verttab.reserve(vertnbr + 1);
94 std::vector<SCOTCH_Num> edgetab;
95 edgetab.reserve(20*vertnbr);
100 SCOTCH_Num edgenbr = 0;
101 verttab.push_back(0);
102 typename Graph::const_iterator vertex;
103 for (vertex = graph.begin(); vertex != graph.end(); ++vertex)
105 edgenbr += vertex->size();
106 verttab.push_back(verttab.back() + vertex->size());
107 edgetab.insert(edgetab.end(), vertex->begin(), vertex->end());
111 verttab.shrink_to_fit();
112 edgetab.shrink_to_fit();
115 SCOTCH_Graph scotchGraph;
118 const SCOTCH_Num baseval = 0;
121 if (SCOTCH_graphInit(&scotchGraph) != 0)
123 std::cerr <<
"Error initializing SCOTCH graph!" << std::endl;
128 if (SCOTCH_graphBuild(&scotchGraph, baseval,
129 vertnbr, &verttab[0], &verttab[1], NULL, NULL,
130 edgenbr, &edgetab[0], NULL))
132 std::cerr <<
"Error building SCOTCH graph!" << std::endl;
138 SCOTCH_stratInit(&strat);
141 if (!scotchStrategy.empty())
142 SCOTCH_stratGraphOrder(&strat, scotchStrategy.c_str());
145 std::vector<SCOTCH_Num> permutationIndices(vertnbr);
146 std::vector<SCOTCH_Num> inversePermutationIndices(vertnbr);
149 SCOTCH_randomReset();
152 if (SCOTCH_graphOrder(&scotchGraph, &strat, permutationIndices.data(),
153 inversePermutationIndices.data(), NULL, NULL, NULL))
155 std::cerr <<
"SCOTCH: Error during reordering graph!" << std::endl;
160 SCOTCH_graphExit(&scotchGraph);
161 SCOTCH_stratExit(&strat);
164 permutation.resize(vertnbr);
165 inversePermutation.resize(vertnbr);
166 std::copy(permutationIndices.begin(), permutationIndices.end(),
167 permutation.begin());
168 std::copy(inversePermutationIndices.begin(), inversePermutationIndices.end(),
169 inversePermutation.begin());
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
Definition: scotchbackend.hh:56
static std::vector< int > computeReordering(const Graph &graph, std::string scotchStrategy="")
Compute graph re-ordering.
Definition: scotchbackend.hh:72
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchbackend.hh:59
static std::vector< int > computeGPSReordering(const Graph &graph, std::size_t numPasses=5)
Definition: scotchbackend.hh:63
static void computeReordering(const Graph &graph, std::vector< int > &permutation, std::vector< int > &inversePermutation, std::string scotchStrategy="")
Compute graph re-ordering.
Definition: scotchbackend.hh:81