50#ifndef _ZOLTAN2_ORDERINGPROBLEM_HPP_
51#define _ZOLTAN2_ORDERINGPROBLEM_HPP_
60#ifdef HAVE_ZOLTAN2_OVIS
70using Teuchos::rcp_dynamic_cast;
94template<
typename Adapter>
100 typedef typename Adapter::gno_t
gno_t;
101 typedef typename Adapter::lno_t
lno_t;
105#ifdef HAVE_ZOLTAN2_MPI
106 typedef Teuchos::OpaqueWrapper<MPI_Comm> mpiWrapper_t;
114 const RCP<
const Teuchos::Comm<int> > &comm) :
118 createOrderingProblem();
121#ifdef HAVE_ZOLTAN2_MPI
126 rcp<const Comm<int> >(new
Teuchos::MpiComm<int>(
127 Teuchos::opaqueWrapper(mpicomm))))
142#ifdef INCLUDE_ZOLTAN2_EXPERIMENTAL
146 RCP<Teuchos::StringValidator> order_method_Validator =
147 Teuchos::rcp(
new Teuchos::StringValidator(
148 Teuchos::tuple<std::string>(
"rcm",
"metis",
"minimum_degree",
"natural",
149 "random",
"sorted_degree",
"scotch",
"nd" )));
150 pl.set(
"order_method",
"rcm",
"order algorithm",
151 order_method_Validator);
153 RCP<Teuchos::StringValidator> order_method_type_Validator =
154 Teuchos::rcp(
new Teuchos::StringValidator(
155 Teuchos::tuple<std::string>(
"local",
"global",
"both" )));
156 pl.set(
"order_method_type",
"local",
"local or global or both",
157 order_method_type_Validator);
159 RCP<Teuchos::StringValidator> order_package_Validator = Teuchos::rcp(
160 new Teuchos::StringValidator(
161 Teuchos::tuple<std::string>(
"amd",
"package2",
"package3" )));
162 pl.set(
"order_package",
"amd",
"package to use in ordering",
163 order_package_Validator);
165 RCP<Teuchos::StringValidator> rcm_root_selection_Validator = Teuchos::rcp(
166 new Teuchos::StringValidator(
167 Teuchos::tuple<std::string>(
"pseudoperipheral",
"first",
"smallest_degree" )));
168 pl.set(
"root_method",
"pseudoperipheral",
"method for selecting RCM root",
169 rcm_root_selection_Validator);
188 void solve(
bool updateInputData=
true);
195 if(localOrderingSolution_ == Teuchos::null) {
196 throw std::logic_error(
"OrderingProblem was not created with local"
197 " ordering. Set parameter order_method_type to local or both."
198 " Or use getGlobalOrderingSolution()." );
200 return setupSolution(localOrderingSolution_);
208 if(globalOrderingSolution_ == Teuchos::null) {
209 throw std::logic_error(
"OrderingProblem was not created with global"
210 " ordering. Set parameter order_method_type to global or both."
211 " Or use getLocalOrderingSolution()." );
213 return setupSolution(globalOrderingSolution_);
217 template<
typename ordering_solution_t>
218 ordering_solution_t *setupSolution(RCP<ordering_solution_t> solution) {
222 if (!(solution->havePerm()))
223 solution->computePerm();
224 if (!(solution->haveInverse()))
225 solution->computeInverse();
226 return solution.getRawPtr();
229 void createOrderingProblem();
232 RCP<LocalOrderingSolution<lno_t> > localOrderingSolution_;
233 RCP<GlobalOrderingSolution<gno_t> > globalOrderingSolution_;
235 size_t localNumObjects_;
239template <
typename Adapter>
247 std::string method_type = this->params_->template
248 get<std::string>(
"order_method_type",
"local");
250 if(method_type ==
"local" || method_type ==
"both") {
251 localOrderingSolution_ = rcp(
new LocalOrderingSolution<lno_t>(localNumObjects_));
253 if(method_type ==
"global" || method_type ==
"both") {
254 globalOrderingSolution_ = rcp(
new GlobalOrderingSolution<gno_t>(localNumObjects_));
263 std::string method = this->params_->template
264 get<std::string>(
"order_method",
"rcm");
273 #define ZOLTAN2_COMPUTE_ORDERING \
274 if(localOrderingSolution_ != Teuchos::null) { \
275 alg.localOrder(localOrderingSolution_); \
277 if(globalOrderingSolution_ != Teuchos::null) { \
278 alg.globalOrder(globalOrderingSolution_); \
285 if (method.compare(
"rcm") == 0) {
286 AlgRCM<base_adapter_t> alg(this->baseInputAdapter_, this->params_,
287 this->comm_, this->envConst_, graphFlags);
290 else if (method.compare(
"natural") == 0) {
291 AlgNatural<base_adapter_t> alg(this->baseInputAdapter_, this->params_,
292 this->comm_, this->envConst_);
295 else if (method.compare(
"random") == 0) {
296 AlgRandom<base_adapter_t> alg(this->baseInputAdapter_, this->params_,
297 this->comm_, this->envConst_);
300 else if (method.compare(
"sorted_degree") == 0) {
301 AlgSortedDegree<base_adapter_t> alg(this->baseInputAdapter_, this->params_,
302 this->comm_, this->envConst_,
306 else if (method.compare(
"metis") == 0) {
307 AlgMetis<base_adapter_t> alg(this->baseInputAdapter_, this->params_,
308 this->comm_, this->envConst_, graphFlags);
311 else if (method.compare(
"minimum_degree") == 0) {
312 std::string pkg = this->params_->template get<std::string>(
313 "order_package",
"amd");
314 if (pkg.compare(
"amd") == 0)
316 AlgAMD<base_adapter_t> alg(this->baseInputAdapter_,
317 this->params_, this->comm_, this->envConst_, graphFlags);
321 else if (method.compare(
"scotch") == 0) {
322 AlgPTScotch<Adapter> alg(this->envConst_, this->comm_,
323 this->baseInputAdapter_);
327#ifdef INCLUDE_ZOLTAN2_EXPERIMENTAL
328 else if (method.compare(
"nd") == 0) {
329 AlgND<base_adapter_t> alg(this->envConst_, this->comm_, this->baseInputAdapter_, graphFlags);
351template <
typename Adapter>
355 using Teuchos::ParameterList;
363 std::string method = this->params_->template
364 get<std::string>(
"order_method",
"rcm");
366 if ((method == std::string(
"rcm")) ||
367 (method == std::string(
"sorted_degree")) ||
368 (method == std::string(
"metis")) ||
369 (method == std::string(
"minimum_degree"))) {
373#ifdef INCLUDE_ZOLTAN2_EXPERIMENTAL
374 if ((method == std::string(
"nd")))
390 const auto adapterType = this->baseInputAdapter_->adapterType();
400 localNumObjects_ = this->baseInputAdapter_->getLocalNumIDs();
406 const auto ia =
dynamic_cast<const GraphAdapter<user_t> *
>(&(*(this->baseInputAdapter_)));
407 localNumObjects_ = ia->getLocalNumVertices();
413 const auto ia =
dynamic_cast<const MeshAdapter<user_t> *
>(&(*(this->baseInputAdapter_)));
414 localNumObjects_ = ia->getLocalNumOf(ia->getPrimaryEntityType());
427 localNumObjects_ = this->baseInputAdapter_->getLocalNumIDs();
435 <<
" Model type " << modelType <<
" not yet supported."
Defines the Zoltan2_EvaluateOrdering.hpp class.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
#define __func__zoltan2__
Defines the GraphModel interface.
#define ZOLTAN2_COMPUTE_ORDERING
Defines the OrderingSolution class.
Defines the Problem base class.
static void getValidParameters(ParameterList &pl)
Set up validators specific to this algorithm.
OrderingProblem sets up ordering problems for the user.
Adapter::scalar_t scalar_t
virtual ~OrderingProblem()
Destructor.
Adapter::base_adapter_t base_adapter_t
void solve(bool updateInputData=true)
Direct the problem to create a solution.
LocalOrderingSolution< lno_t > * getLocalOrderingSolution()
Get the local ordering solution to the problem.
OrderingProblem(Adapter *A, ParameterList *p, const RCP< const Teuchos::Comm< int > > &comm)
static void getValidParameters(ParameterList &pl)
Set up validators specific to this Problem.
OrderingProblem(Adapter *A, ParameterList *p)
Constructor that uses a default communicator.
GlobalOrderingSolution< gno_t > * getGlobalOrderingSolution()
Get the global ordering solution to the problem.
Problem base class from which other classes (PartitioningProblem, ColoringProblem,...
Created by mbenlioglu on Aug 31, 2020.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
ModelType
An identifier for the general type of model.
@ GraphAdapterType
graph data
@ MatrixAdapterType
matrix data
@ MeshAdapterType
mesh data
@ REMOVE_SELF_EDGES
algorithm requires no self edges
@ BUILD_LOCAL_GRAPH
model represents graph within only one rank