Skip to content

Commit a34d2ef

Browse files
committed
Make Zoltan's Hyperedge Size Threshold Runtime Controllable
This commit introduces a new hidden runtime parameter, ZoltanPhgEdgeSizeThreshold (--zoltan-phg-edge-size-threshold, double, default value = 0.35) which maps to Zoltan's low-level control parameter PHG_EDGE_SIZE_THRESHOLD that controls which hypergraph edges to omit/discard. We add a new parameter to 'setupZoltanParameters()' and thread the command line parameter through as an argument to this function. This is to enable runtime experimentation with this aspect of the partitioning algorithm, but end-users should typically not alter the default value without good reason.
1 parent 90e9664 commit a34d2ef

7 files changed

Lines changed: 92 additions & 16 deletions

opm/simulators/flow/CpGridVanguard.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag>
316316
{
317317
return this->zoltanParams_;
318318
}
319+
320+
double zoltanPhgEdgeSizeThreshold() const override
321+
{
322+
return this->zoltanPhgEdgeSizeThreshold_;
323+
}
324+
319325
const std::string& metisParams() const override
320326
{
321327
return this->metisParams_;

opm/simulators/flow/FlowGenericVanguard.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ FlowGenericVanguard::FlowGenericVanguard(SimulationModelParams&& params)
124124
partitionMethod_ = Dune::PartitionMethod(Parameters::Get<Parameters::PartitionMethod>());
125125
serialPartitioning_ = Parameters::Get<Parameters::SerialPartitioning>();
126126
zoltanParams_ = Parameters::Get<Parameters::ZoltanParams>();
127-
127+
zoltanPhgEdgeSizeThreshold_ = Parameters::Get<Parameters::ZoltanPhgEdgeSizeThreshold>();
128128
metisParams_ = Parameters::Get<Parameters::MetisParams>();
129129

130130
externalPartitionFile_ = Parameters::Get<Parameters::ExternalPartition>();
@@ -479,6 +479,10 @@ void FlowGenericVanguard::registerParameters_()
479479
"for available Zoltan options.");
480480
Parameters::Register<Parameters::ImbalanceTol<Scalar>>
481481
("Tolerable imbalance of the loadbalancing.");
482+
Parameters::Register<Parameters::ZoltanPhgEdgeSizeThreshold>
483+
("Low-level threshold fraction in the range [0,1] controlling "
484+
"which hypergraph edge to omit. Used if --zoltan-params=\"graph\" "
485+
"or if --zoltan-params=\"hypergraph\".");
482486
Parameters::Register<Parameters::MetisParams>
483487
("Configuration of Metis partitioner. "
484488
"You can request a configuration to be read "
@@ -494,6 +498,7 @@ void FlowGenericVanguard::registerParameters_()
494498

495499
Parameters::Hide<Parameters::ZoltanImbalanceTol<Scalar>>();
496500
Parameters::Hide<Parameters::ZoltanParams>();
501+
Parameters::Hide<Parameters::ZoltanPhgEdgeSizeThreshold>();
497502
#endif // HAVE_MPI
498503

499504
Parameters::Register<Parameters::AllowDistributedWells>

opm/simulators/flow/FlowGenericVanguard.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ struct SerialPartitioning{ static constexpr bool value = false; };
8484
template<class Scalar>
8585
struct ZoltanImbalanceTol { static constexpr Scalar value = 1.1; };
8686

87+
struct ZoltanPhgEdgeSizeThreshold { static constexpr auto value = 0.35; };
88+
8789
struct ZoltanParams { static constexpr auto value = "graph"; };
8890

8991
} // namespace Opm::Parameters
@@ -380,6 +382,7 @@ class FlowGenericVanguard {
380382

381383
bool zoltanImbalanceTolSet_;
382384
double zoltanImbalanceTol_;
385+
double zoltanPhgEdgeSizeThreshold_;
383386
std::string zoltanParams_;
384387

385388
std::string metisParams_;

opm/simulators/flow/GenericCpGridVanguard.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,21 @@ doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod,
158158
const int numJacobiBlocks,
159159
const bool enableEclOutput)
160160
{
161-
if ((partitionMethod == Dune::PartitionMethod::zoltan
162-
|| partitionMethod == Dune::PartitionMethod::zoltanGoG) && !this->zoltanParams().empty())
163-
this->grid_->setPartitioningParams(setupZoltanParams(this->zoltanParams()));
164-
if (partitionMethod == Dune::PartitionMethod::metis && !this->metisParams().empty())
165-
this->grid_->setPartitioningParams(setupMetisParams(this->metisParams()));
161+
if (((partitionMethod == Dune::PartitionMethod::zoltan) ||
162+
(partitionMethod == Dune::PartitionMethod::zoltanGoG)) &&
163+
!this->zoltanParams().empty())
164+
{
165+
this->grid_->setPartitioningParams
166+
(setupZoltanParams(this->zoltanParams(),
167+
this->zoltanPhgEdgeSizeThreshold()));
168+
}
169+
170+
if ((partitionMethod == Dune::PartitionMethod::metis) &&
171+
!this->metisParams().empty())
172+
{
173+
this->grid_->setPartitioningParams
174+
(setupMetisParams(this->metisParams()));
175+
}
166176

167177
const auto mpiSize = this->grid_->comm().size();
168178

opm/simulators/flow/GenericCpGridVanguard.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class GenericCpGridVanguard {
209209

210210
protected:
211211
virtual const std::string& zoltanParams() const = 0;
212+
virtual double zoltanPhgEdgeSizeThreshold() const = 0;
212213
virtual const std::string& metisParams() const = 0;
213214

214215
#endif // HAVE_MPI

opm/simulators/utils/SetupPartitioningParams.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <filesystem>
3434
#include <map>
35+
#include <optional>
3536
#include <stdexcept>
3637
#include <string>
3738
#include <string_view>
@@ -99,6 +100,18 @@ namespace {
99100

100101
namespace {
101102

103+
std::map<std::string, std::string>
104+
applyEdgeSizeThreshold(std::map<std::string, std::string>&& params,
105+
const std::optional<double>& edgeSizeThreshold)
106+
{
107+
if (edgeSizeThreshold.has_value()) {
108+
params.emplace("PHG_EDGE_SIZE_THRESHOLD",
109+
fmt::format("{}", *edgeSizeThreshold));
110+
}
111+
112+
return params;
113+
}
114+
102115
std::map<std::string, std::string>
103116
zoltanGraphParameters(std::string_view graphPackage)
104117
{
@@ -108,9 +121,10 @@ namespace {
108121
};
109122
}
110123

111-
auto zoltanGraphParameters()
124+
auto zoltanGraphParameters(const std::optional<double>& edgeSizeThreshold)
112125
{
113-
return zoltanGraphParameters("PHG");
126+
return applyEdgeSizeThreshold(zoltanGraphParameters("PHG"),
127+
edgeSizeThreshold);
114128
}
115129

116130
auto zoltanScotchParameters()
@@ -119,26 +133,28 @@ namespace {
119133
}
120134

121135
std::map<std::string, std::string>
122-
zoltanHyperGraphParameters()
136+
zoltanHyperGraphParameters(const std::optional<double>& edgeSizeThreshold)
123137
{
124-
return {
138+
return applyEdgeSizeThreshold({
125139
{ "LB_METHOD", "HYPERGRAPH" },
126-
};
140+
{ "HYPERGRAPH_PACKAGE", "PHG" },
141+
}, edgeSizeThreshold);
127142
}
128143

129144
} // Anonymous namespace
130145

131146
// ===========================================================================
132147

133148
std::map<std::string, std::string>
134-
Opm::setupZoltanParams(const std::string& conf)
149+
Opm::setupZoltanParams(const std::string& conf,
150+
const std::optional<double>& edgeSizeThreshold)
135151
{
136152
if (conf == "graph") {
137-
return zoltanGraphParameters();
153+
return zoltanGraphParameters(edgeSizeThreshold);
138154
}
139155

140156
else if (conf == "hypergraph") {
141-
return zoltanHyperGraphParameters();
157+
return zoltanHyperGraphParameters(edgeSizeThreshold);
142158
}
143159

144160
else if (conf == "scotch") {

opm/simulators/utils/SetupPartitioningParams.hpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,47 @@
2121
#define OPM_SETUP_PARTITIONING_PARAMS_HPP
2222

2323
#include <map>
24+
#include <optional>
2425
#include <string>
2526

2627
namespace Opm {
2728

28-
std::map<std::string,std::string> setupZoltanParams(const std::string& conf);
29-
std::map<std::string,std::string> setupMetisParams(const std::string& conf);
29+
/// Form collection of Zoltan partitioning parameters from named configuration
30+
///
31+
/// \param[in] conf Named Zoltan configuration. Must either be the name of a
32+
/// JSON configuration file with the filename extension ".json", or one of
33+
/// the known configuration names
34+
///
35+
/// -* graph Generates configuration parameters for the "GRAPH"
36+
/// load-balancing method, using the "PHG" graph package.
37+
///
38+
/// -* hypergraph Generates configuration parameters for the "HYPERGRAPH"
39+
/// load-balancing method.
40+
///
41+
/// -* scotch Generates configuration parameters for the "GRAPH"
42+
/// load-balancing method, using the "Scotch" graph package.
43+
///
44+
/// \param[in] edgeSizeThreshold Low-level Zoltan partitioning control
45+
/// parameter for when to omit a hyperedge in a hypergraph. Fraction in the
46+
/// range [0,1] representing a threshold above which to omit discard
47+
/// hyperedges. Used for conf="graph" and conf="hypergraph". Nullopt to
48+
/// use the built-in default value.
49+
///
50+
/// \return Collection of Zoltan partitioning parameters.
51+
std::map<std::string, std::string>
52+
setupZoltanParams(const std::string& conf,
53+
const std::optional<double>& edgeSizeThreshold = {});
54+
55+
/// Form collection of METIS partitioning parameters from named configuration
56+
///
57+
/// \param[in] conf Named METIS configuration. Must either be the name of a
58+
/// JSON configuration file with the filename extension ".json", or the
59+
/// known configuration name "default" which uses the built-in default
60+
/// partitioning parameters.
61+
///
62+
/// \return Collection of METIS partitioning parameters.
63+
std::map<std::string, std::string>
64+
setupMetisParams(const std::string& conf);
3065

3166
} // namespace Opm
3267

0 commit comments

Comments
 (0)