16 #include <Teuchos_ParameterEntryValidator.hpp>
23 #ifndef HAVE_ZOLTAN2_SARMA
26 template<
typename Adapter>
32 const RCP<
const Comm<int> > &,
33 const RCP<const base_adapter_t> &) {
34 throw std::runtime_error(
"SARMA requested but not enabled into Zoltan2\n"
35 "Please set CMake flag TPL_ENABLE_SARMA:BOOL=ON");
47 #include <sarma/sarma.hpp>
50 template<
typename Adapter>
51 class AlgSarma :
public Algorithm<Adapter> {
56 using offset_t =
typename Adapter::offset_t;
57 using scalar_t =
typename Adapter::scalar_t;
60 using userCoord_t =
typename Adapter::userCoord_t;
63 const offset_t *offsets;
70 AlgSarma(
const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
71 const RCP<
const IdentifierAdapter <user_t> > &adapter)
72 : env(env), comm(comm), adapter(adapter),
73 algs(sarma::get_algorithm_map<Ordinal, Value>()), orders(sarma::get_order_map()) {
74 throw std::runtime_error(
"Cannot build SARMA from IdentifierAdapter");
77 AlgSarma(
const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
78 const RCP<
const VectorAdapter <user_t> > &adapter)
79 : env(env), comm(comm), adapter(adapter),
80 algs(sarma::get_algorithm_map<Ordinal, Value>()), orders(sarma::get_order_map()) {
81 throw std::runtime_error(
"Cannot build SARMA from VectorAdapter");
85 AlgSarma(
const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
86 const RCP<
const GraphAdapter <user_t, userCoord_t> > &adapter)
87 : env(env), comm(comm), adapter(adapter),
88 algs(sarma::get_algorithm_map<Ordinal, Value>()), orders(sarma::get_order_map()) {
89 throw std::runtime_error(
"Cannot build SARMA from GraphAdapter");
92 AlgSarma(
const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
93 const RCP<
const MeshAdapter <user_t> > &adapter)
94 : env(env), comm(comm), adapter(adapter),
95 algs(sarma::get_algorithm_map<Ordinal, Value>()), orders(sarma::get_order_map()) {
97 throw std::runtime_error(
"Cannot build SARMA from MeshAdapter");
100 AlgSarma(
const RCP<const Environment> &env,
const RCP<
const Comm<int> > &comm,
101 const RCP<
const MatrixAdapter <user_t, userCoord_t> > &adapter)
102 : env(env), comm(comm), adapter(adapter),
103 offsize(1 + adapter->getLocalNumRows()), nnz(adapter->getLocalNumEntries()),
104 algs(sarma::get_algorithm_map<Ordinal, Value>()), orders(sarma::get_order_map()) {
106 if (adapter->CRSViewAvailable()) {
107 offsets =
new offset_t[offsize]();
108 colids =
new gno_t[nnz]();
110 adapter->getCRSView(offsets, colids, vals);
112 throw std::runtime_error(
"NO CRS Available");
115 static void getValidParameters(ParameterList &pl) {
116 RCP<const Teuchos::ParameterEntryValidator> validator;
117 pl.set(
"sarma_parameters", ParameterList(),
"Sarma options", validator);
120 void partition(
const RCP <PartitioningSolution<Adapter>> &solution);
122 const RCP<const Environment> env;
123 const RCP<const Comm<int> > comm;
124 const RCP<const base_adapter_t> adapter;
125 RCP<const CoordinateModel <base_adapter_t> > model;
128 std::string alg =
"pal";
129 sarma::Order order_type = sarma::Order::NAT;
130 std::string order_str =
"nat";
131 Ordinal row_parts = 8, col_parts = 0;
133 int seed = 2147483647;
134 double sparsify = 1.0;
135 bool triangular =
false, use_data =
false;
138 std::map <std::string, std::pair<std::function < std::pair < std::vector < Ordinal>, std::vector<Ordinal>>(
139 const sarma::Matrix <Ordinal, Value> &,
const Ordinal,
const Ordinal,
const Value,
const int)>,
bool>>
141 std::map <std::string, sarma::Order> orders;
149 template<
typename Adapter>
150 void AlgSarma<Adapter>::getParams() {
151 const Teuchos::ParameterList &pl = env->getParameters();
152 const Teuchos::ParameterList &sparams = pl.sublist(
"sarma_parameters");
155 const Teuchos::ParameterEntry *pe = sparams.getEntryPtr(
"alg");
157 config.alg = pe->getValue(&config.alg);
158 pe = sparams.getEntryPtr(
"order");
161 s = pe->getValue(&s);
162 if (orders.find(s) == orders.end()) {
163 throw std::logic_error(
"Wrong order type.");
165 config.order_type = orders.at(s);
166 config.order_str = s;
168 pe = sparams.getEntryPtr(
"row_parts");
170 config.row_parts = pe->getValue(&config.row_parts);
171 pe = sparams.getEntryPtr(
"col_parts");
173 config.col_parts = pe->getValue(&config.col_parts);
174 pe = sparams.getEntryPtr(
"max_load");
176 config.max_load = pe->getValue(&config.max_load);
177 pe = sparams.getEntryPtr(
"sparsify");
179 config.sparsify = pe->getValue(&config.sparsify);
180 pe = sparams.getEntryPtr(
"triangular");
182 config.triangular = pe->getValue(&config.triangular);
183 pe = sparams.getEntryPtr(
"use_data");
185 config.use_data = pe->getValue(&config.use_data);
186 pe = sparams.getEntryPtr(
"seed");
188 config.seed = pe->getValue(&config.seed);
191 template<
typename Adapter>
195 null.setstate(std::ios_base::badbit);
196 auto M = std::make_shared<sarma::Matrix<Ordinal, Value> >(std::move(std::vector<Ordinal>(offsets, offsets + offsize)),
197 std::move(std::vector<Ordinal>(colids, colids + nnz)), std::move(std::vector<Value>(vals, vals + nnz)),
198 1 + *std::max_element(colids, colids + nnz));
199 auto parts = sarma::Run<Ordinal, Value>(algs.at(config.alg).first, null, M, config.order_type, config.row_parts,
200 config.col_parts, config.max_load, config.triangular,
false, config.sparsify,
201 algs.at(config.alg).second, config.use_data, config.seed);
203 unsigned result_size = parts.first.size() + parts.second.size();
204 auto partl = ArrayRCP<int>(
new int[result_size], 0, result_size,
true);
205 for (
size_t i = 0; i < parts.first.size(); ++i) partl[i] = parts.first[i];
206 for (
size_t i = parts.first.size(); i < result_size; ++i)
207 partl[i] = parts.second[i - parts.first.size()];
209 solution->setParts(partl);
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
virtual void partition(const RCP< PartitioningSolution< Adapter > > &)
Partitioning method.
typename Adapter::base_adapter_t base_adapter_t
map_t::global_ordinal_type gno_t
Defines the PartitioningSolution class.
AlgSarma(const RCP< const Environment > &, const RCP< const Comm< int > > &, const RCP< const base_adapter_t > &)
SparseMatrixAdapter_t::part_t part_t
Adapter::scalar_t scalar_t
Algorithm defines the base class for all algorithms.
map_t::local_ordinal_type lno_t
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
Defines the CoordinateModel classes.
A gathering of useful namespace methods.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t