3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
19
26#ifndef DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
27#define DUMUX_PARALLEL_SCOTCH_PARTITIONER_HH
28
29#include <string>
30#include <vector>
31#include <iostream>
32
33#include <dune/common/exceptions.hh>
35
36namespace Dumux {
37
38#if HAVE_PTSCOTCH
39
45class ScotchGraphMapStrategy
46{
47public:
48 ScotchGraphMapStrategy(std::size_t numProcessors, double imbalanceRatio = 0.0, int flag = SCOTCH_STRATDEFAULT)
49 {
50 if (SCOTCH_stratInit(&strategy_) != 0)
51 DUNE_THROW(Dune::Exception, "Error initializing SCOTCH strategy!");
52
53 if (SCOTCH_stratGraphMapBuild(&strategy_, static_cast<SCOTCH_Num>(flag), static_cast<SCOTCH_Num>(numProcessors), imbalanceRatio) != 0)
54 DUNE_THROW(Dune::Exception, "Error building SCOTCH strategy!");
55 }
56
58 ~ScotchGraphMapStrategy()
59 {
60 SCOTCH_stratExit(&strategy_);
61 }
62
64 SCOTCH_Strat* data()
65 { return &strategy_; }
66
67private:
68 SCOTCH_Strat strategy_;
69};
70
71#endif // HAVE_PTSCOTCH
72
79template<class IndexType = int>
81{
82public:
84 using Graph = std::vector<std::vector<IndexType>>;
85
87 static std::vector<IndexType> partition(const Graph& graph, std::size_t numProcessors)
88 {
89 std::vector<IndexType> targetProcessors;
90 partition(graph, numProcessors, targetProcessors);
91 return targetProcessors;
92 }
93
95 static void partition(const Graph& graph, std::size_t numProcessors,
96 std::vector<IndexType>& targetProcessors)
97 {
98#if HAVE_PTSCOTCH
99 ScotchGraph<IndexType> scotchGraph(graph);
100 ScotchGraphMapStrategy strategy(numProcessors);
101
102 // architecture and graphMap are created and called within graphPart
103 // if specific ones are desired, one has to call them separately and delete the graphPart function call
104 // compute partitioning
105 const auto graphSize = graph.size();
106 std::vector<SCOTCH_Num> scotchPartitions(graphSize);
107 if (SCOTCH_graphPart(scotchGraph.data(), static_cast<SCOTCH_Num>(numProcessors), strategy.data(), scotchPartitions.data()) != 0)
108 DUNE_THROW(Dune::Exception, "Error computing SCOTCH graph mapping!");
109
110 // convert number types
111 targetProcessors = std::vector<IndexType>(
112 scotchPartitions.begin(), scotchPartitions.end()
113 );
114#endif // HAVE_PTSCOTCH
115 }
116};
117
118} // end namespace Dumux
119
120#endif
An interface to the scotch library for matrix reordering.
Definition: adapt.hh:29
Definition: scotchpartitioner.hh:81
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchpartitioner.hh:84
static void partition(const Graph &graph, std::size_t numProcessors, std::vector< IndexType > &targetProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:95
static std::vector< IndexType > partition(const Graph &graph, std::size_t numProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:87