version 3.10-dev
scotchpartitioner.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
14#ifndef DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
15#define DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
16
17#include <string>
18#include <vector>
19#include <iostream>
20
21#include <dune/common/exceptions.hh>
23
24namespace Dumux {
25
26#if HAVE_PTSCOTCH
27
32class ScotchGraphMapStrategy
33{
34public:
35 ScotchGraphMapStrategy(std::size_t numProcessors, double imbalanceRatio = 0.0, int flag = SCOTCH_STRATDEFAULT)
36 {
37 if (SCOTCH_stratInit(&strategy_) != 0)
38 DUNE_THROW(Dune::Exception, "Error initializing SCOTCH strategy!");
39
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!");
42 }
43
45 ~ScotchGraphMapStrategy()
46 {
47 SCOTCH_stratExit(&strategy_);
48 }
49
51 SCOTCH_Strat* data()
52 { return &strategy_; }
53
54private:
55 SCOTCH_Strat strategy_;
56};
57
58#endif // HAVE_PTSCOTCH
59
65template<class IndexType = int>
67{
68public:
70 using Graph = std::vector<std::vector<IndexType>>;
71
73 static std::vector<IndexType> partition(const Graph& graph, std::size_t numProcessors)
74 {
75 std::vector<IndexType> targetProcessors;
76 partition(graph, numProcessors, targetProcessors);
77 return targetProcessors;
78 }
79
81 static void partition(const Graph& graph, std::size_t numProcessors,
82 std::vector<IndexType>& targetProcessors)
83 {
84#if HAVE_PTSCOTCH
85 ScotchGraph<IndexType> scotchGraph(graph);
86 ScotchGraphMapStrategy strategy(numProcessors);
87
88 // architecture and graphMap are created and called within graphPart
89 // if specific ones are desired, one has to call them separately and delete the graphPart function call
90 // compute partitioning
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!");
95
96 // convert number types
97 targetProcessors = std::vector<IndexType>(
98 scotchPartitions.begin(), scotchPartitions.end()
99 );
100#endif // HAVE_PTSCOTCH
101 }
102};
103
104} // end namespace Dumux
105
106#endif
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
Definition: adapt.hh:17
An interface to the scotch library for matrix reordering.