Loading [MathJax]/extensions/tex2jax.js
3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
44class ScotchGraphMapStrategy
45{
46public:
47 ScotchGraphMapStrategy(std::size_t numProcessors, double imbalanceRatio = 0.0, int flag = SCOTCH_STRATDEFAULT)
48 {
49 if (SCOTCH_stratInit(&strategy_) != 0)
50 DUNE_THROW(Dune::Exception, "Error initializing SCOTCH strategy!");
51
52 if (SCOTCH_stratGraphMapBuild(&strategy_, static_cast<SCOTCH_Num>(flag), static_cast<SCOTCH_Num>(numProcessors), imbalanceRatio) != 0)
53 DUNE_THROW(Dune::Exception, "Error building SCOTCH strategy!");
54 }
55
57 ~ScotchGraphMapStrategy()
58 {
59 SCOTCH_stratExit(&strategy_);
60 }
61
63 SCOTCH_Strat* data()
64 { return &strategy_; }
65
66private:
67 SCOTCH_Strat strategy_;
68};
69
70#endif // HAVE_PTSCOTCH
71
77template<class IndexType = int>
79{
80public:
82 using Graph = std::vector<std::vector<IndexType>>;
83
85 static std::vector<IndexType> partition(const Graph& graph, std::size_t numProcessors)
86 {
87 std::vector<IndexType> targetProcessors;
88 partition(graph, numProcessors, targetProcessors);
89 return targetProcessors;
90 }
91
93 static void partition(const Graph& graph, std::size_t numProcessors,
94 std::vector<IndexType>& targetProcessors)
95 {
96#if HAVE_PTSCOTCH
97 ScotchGraph<IndexType> scotchGraph(graph);
98 ScotchGraphMapStrategy strategy(numProcessors);
99
100 // architecture and graphMap are created and called within graphPart
101 // if specific ones are desired, one has to call them separately and delete the graphPart function call
102 // compute partitioning
103 const auto graphSize = graph.size();
104 std::vector<SCOTCH_Num> scotchPartitions(graphSize);
105 if (SCOTCH_graphPart(scotchGraph.data(), static_cast<SCOTCH_Num>(numProcessors), strategy.data(), scotchPartitions.data()) != 0)
106 DUNE_THROW(Dune::Exception, "Error computing SCOTCH graph mapping!");
107
108 // convert number types
109 targetProcessors = std::vector<IndexType>(
110 scotchPartitions.begin(), scotchPartitions.end()
111 );
112#endif // HAVE_PTSCOTCH
113 }
114};
115
116} // end namespace Dumux
117
118#endif
An interface to the scotch library for matrix reordering.
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
A reordering backend using the scotch library.
Definition: scotchpartitioner.hh:79
std::vector< std::vector< IndexType > > Graph
the graph type
Definition: scotchpartitioner.hh:82
static void partition(const Graph &graph, std::size_t numProcessors, std::vector< IndexType > &targetProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:93
static std::vector< IndexType > partition(const Graph &graph, std::size_t numProcessors)
Compute graph partition.
Definition: scotchpartitioner.hh:85