Skip to content

Commit e5fce07

Browse files
authored
Merge pull request #6036 from bska/expose-zoltan-phg-edge-size-param
Make Zoltan's Hyperedge Size Threshold Runtime Controllable
2 parents 2e62b6c + fed4a3b commit e5fce07

File tree

7 files changed

+97
-21
lines changed

7 files changed

+97
-21
lines changed

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: 12 additions & 6 deletions
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>();
@@ -468,21 +468,26 @@ void FlowGenericVanguard::registerParameters_()
468468
Parameters::Register<Parameters::SerialPartitioning>
469469
("Perform partitioning for parallel runs on a single process.");
470470
Parameters::Register<Parameters::ZoltanImbalanceTol<Scalar>>
471-
("Tolerable imbalance of the loadbalancing provided by Zoltan. DEPRECATED: Use --imbalance-tol instead");
471+
("Tolerable imbalance of the loadbalancing provided by Zoltan. "
472+
"DEPRECATED: Use --imbalance-tol instead.");
472473
Parameters::Register<Parameters::ZoltanParams>
473474
("Configuration of Zoltan partitioner. "
474475
"Valid options are: graph, hypergraph or scotch. "
475476
"Alternatively, you can request a configuration to be read "
476-
"from a JSON file by giving the filename here, ending with '.json.' "
477+
"from a JSON file by giving the filename here, with extension '.json'. "
477478
"See https://sandialabs.github.io/Zoltan/ug_html/ug.html "
478479
"for available Zoltan options.");
479480
Parameters::Register<Parameters::ImbalanceTol<Scalar>>
480-
("Tolerable imbalance of the loadbalancing (default: 1.1).");
481+
("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\".");
481486
Parameters::Register<Parameters::MetisParams>
482487
("Configuration of Metis partitioner. "
483488
"You can request a configuration to be read "
484-
"from a JSON file by giving the filename here, ending with '.json.' "
485-
"See http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/manual.pdf"
489+
"from a JSON file by giving the filename here, with extension '.json'. "
490+
"See http://glaros.dtc.umn.edu/gkhome/fetch/sw/metis/manual.pdf "
486491
"for available METIS options.");
487492
Parameters::Register<Parameters::ExternalPartition>
488493
("Name of file from which to load an externally generated "
@@ -493,6 +498,7 @@ void FlowGenericVanguard::registerParameters_()
493498

494499
Parameters::Hide<Parameters::ZoltanImbalanceTol<Scalar>>();
495500
Parameters::Hide<Parameters::ZoltanParams>();
501+
Parameters::Hide<Parameters::ZoltanPhgEdgeSizeThreshold>();
496502
#endif // HAVE_MPI
497503

498504
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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,20 @@ 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+
else if ((partitionMethod == Dune::PartitionMethod::metis) &&
170+
!this->metisParams().empty())
171+
{
172+
this->grid_->setPartitioningParams
173+
(setupMetisParams(this->metisParams()));
174+
}
166175

167176
const auto mpiSize = this->grid_->comm().size();
168177

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)