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());