Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
8 | /*! | ||
9 | * \file | ||
10 | * \ingroup Parallel | ||
11 | * \brief An interface to the Scotch library for graph partitioning | ||
12 | * \note You need to have PTSCOTCH installed to use this feature | ||
13 | */ | ||
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> | ||
22 | #include <dumux/linear/scotchbackend.hh> | ||
23 | |||
24 | namespace Dumux { | ||
25 | |||
26 | #if HAVE_PTSCOTCH | ||
27 | |||
28 | /*! | ||
29 | * \ingroup Parallel | ||
30 | * \brief A wrapper around a SCOTCH strategy object | ||
31 | */ | ||
32 | class ScotchGraphMapStrategy | ||
33 | { | ||
34 | public: | ||
35 | 4 | ScotchGraphMapStrategy(std::size_t numProcessors, double imbalanceRatio = 0.0, int flag = SCOTCH_STRATDEFAULT) | |
36 | 4 | { | |
37 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (SCOTCH_stratInit(&strategy_) != 0) |
38 | ✗ | DUNE_THROW(Dune::Exception, "Error initializing SCOTCH strategy!"); | |
39 | |||
40 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | 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 | 4 | } | |
43 | |||
44 | //! Clean-up the strategy | ||
45 | ~ScotchGraphMapStrategy() | ||
46 | 4 | { | |
47 | 4 | SCOTCH_stratExit(&strategy_); | |
48 | } | ||
49 | |||
50 | //! Get the raw point to the data (to pass to C interface) | ||
51 | SCOTCH_Strat* data() | ||
52 | 4 | { return &strategy_; } | |
53 | |||
54 | private: | ||
55 | SCOTCH_Strat strategy_; | ||
56 | }; | ||
57 | |||
58 | #endif // HAVE_PTSCOTCH | ||
59 | |||
60 | /*! | ||
61 | * \ingroup Parallel | ||
62 | * \brief A reordering backend using the scotch library | ||
63 | * \note You need to have PTSCOTCH installed to use this feature | ||
64 | */ | ||
65 | template<class IndexType = int> | ||
66 | class ScotchPartitioner | ||
67 | { | ||
68 | public: | ||
69 | //! the graph type | ||
70 | using Graph = std::vector<std::vector<IndexType>>; | ||
71 | |||
72 | //! Compute graph partition | ||
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 | |||
80 | //! Compute graph partition | ||
81 | 4 | static void partition(const Graph& graph, std::size_t numProcessors, | |
82 | std::vector<IndexType>& targetProcessors) | ||
83 | { | ||
84 | #if HAVE_PTSCOTCH | ||
85 | 4 | ScotchGraph<IndexType> scotchGraph(graph); | |
86 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | 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 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | const auto graphSize = graph.size(); |
92 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
12 | std::vector<SCOTCH_Num> scotchPartitions(graphSize); |
93 |
3/6✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 4 times.
|
8 | 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 |
7/16✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 4 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 4 times.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 4 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
|
16 | targetProcessors = std::vector<IndexType>( |
98 | scotchPartitions.begin(), scotchPartitions.end() | ||
99 | ); | ||
100 | #endif // HAVE_PTSCOTCH | ||
101 | 4 | } | |
102 | }; | ||
103 | |||
104 | } // end namespace Dumux | ||
105 | |||
106 | #endif | ||
107 |