Zoltan2
Loading...
Searching...
No Matches
Zoltan2_SphynxProblem.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Sphynx
6// Copyright 2020 National Technology & Engineering
7// Solutions of Sandia, LLC (NTESS).
8//
9// Under the terms of Contract DE-NA0003525 with NTESS,
10// the U.S. Government retains certain rights in this software.
11//
12// Redistribution and use in source and binary forms, with or without
13// modification, are permitted provided that the following conditions are
14// met:
15//
16// 1. Redistributions of source code must retain the above copyright
17// notice, this list of conditions and the following disclaimer.
18//
19// 2. Redistributions in binary form must reproduce the above copyright
20// notice, this list of conditions and the following disclaimer in the
21// documentation and/or other materials provided with the distribution.
22//
23// 3. Neither the name of the Corporation nor the names of the
24// contributors may be used to endorse or promote products derived from
25// this software without specific prior written permission.
26//
27// THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38//
39// Questions? Contact Seher Acer (sacer@sandia.gov)
40// Erik Boman (egboman@sandia.gov)
41// Siva Rajamanickam (srajama@sandia.gov)
42// Karen Devine (kddevin@sandia.gov)
43//
44// ***********************************************************************
45//
46// @HEADER
47#ifndef _ZOLTAN2_SPHYNXPROBLEM_HPP_
48#define _ZOLTAN2_SPHYNXPROBLEM_HPP_
49
50
52// This file contains the implementation of SphynxProblem.
53//
54// SphynxProblem is a subset of PartitioningProblem in Zoltan2Core. This subset
55// only consists of the functionality and data members needed by Sphynx.
56//
57// SphynxProblem acts as an interface between user and the Sphynx algorithm.
58// User creates the SphynxProblem object on her adapter and calls solve() to
59// get a partitioning solution.
60//
62
64#include "Zoltan2_Sphynx.hpp"
66
67namespace Zoltan2 {
68
69
72static void getSphynxValidParameters(ParameterList & pl)
73{
74
75 RCP<Teuchos::StringValidator> sphynx_preconditionner_type_method_Validator =
76 Teuchos::rcp( new Teuchos::StringValidator(Teuchos::tuple<std::string>( "muelu", "jacobi", "polynomial")));
77
78 pl.set("sphynx_preconditioner_type", "polynomial", "Sphynx preconditioner type", sphynx_preconditionner_type_method_Validator);
79
80
81 RCP<Teuchos::StringValidator> sphynx_initial_guess_method_Validator =
82 Teuchos::rcp( new Teuchos::StringValidator(Teuchos::tuple<std::string>( "random", "constants")));
83
84 pl.set("sphynx_initial_guess", "random", "Sphynx initial guess", sphynx_initial_guess_method_Validator);
85
86 RCP<Teuchos::StringValidator> sphynx_problem_type_method_Validator =
87 Teuchos::rcp( new Teuchos::StringValidator(Teuchos::tuple<std::string>( "combinatorial", "normalized", "generalized")));
88
89 pl.set("sphynx_problem_type", "combinatorial", "Sphynx problem type", sphynx_problem_type_method_Validator);
90
91 RCP<Teuchos::EnhancedNumberValidator<int>> sphynx_verbosity_validator =
92 Teuchos::rcp( new Teuchos::EnhancedNumberValidator<int>(0, 1) );
93 pl.set("sphynx_verbosity", 0, "Sphynx verbosity.", sphynx_verbosity_validator);
94
95 // bool parameter
96 pl.set("sphynx_skip_preprocessing", false, "Sphynx skip preprocessing.", Environment::getBoolValidator());
97 pl.set("sphynx_use_full_ortho", true, "Sphynx use full ortho.", Environment::getBoolValidator());
98}
99
101 const Teuchos::ParameterList &plSome, // in: user's parameters
102 const Teuchos::ParameterList &plAll, // in: validators for all params
103 Teuchos::ParameterList &plVal) // out: validators for user's params
104{
105 ParameterList::ConstIterator next = plSome.begin();
106
107 while (next != plSome.end()){
108
109 const std::string &name = next->first;
110 const ParameterEntry &entrySome = plSome.getEntry(name);
111 const ParameterEntry &entryAll = plAll.getEntry(name);
112
113 if (entrySome.isList()){
114 plVal.sublist(name); // create & get
115 // Don't set validators for sublists; sublists are for TPL's parameters
116 }
117 else{
118 plVal.setEntry(name, entryAll);
119 }
120
121 ++next;
122 }
123}
124
125 template <typename Adapter>
126 class SphynxProblem : public PartitioningProblem<Adapter>
127 {
128
129 public:
130
131 using part_t = typename Adapter::part_t;
132 using weight_t = typename Adapter::scalar_t;
133 typedef typename Adapter::base_adapter_t base_adapter_t; // CHeck to Remove
134
138
139 // Constructor where Teuchos communicator is specified
140 SphynxProblem(Adapter *A,
141 Teuchos::ParameterList *p,
142 RCP<Teuchos::ParameterList> sphynxParams,
143 const RCP<const Teuchos::Comm<int> > &comm):
144 PartitioningProblem<Adapter>(A, p, comm), sphynxParams_(sphynxParams)
145 {
146 // Validation of SphynxParameter
147 ParameterList validParams;
148 try{
149 ParameterList allParameters;
150 getSphynxValidParameters(allParameters);
151
152 setSphynxValidatorsInList(*(sphynxParams_.get()), allParameters, validParams);
153 }
155
156 sphynxParams_->validateParametersAndSetDefaults(validParams, 0);
157 this->env_->convertStringToInt(*sphynxParams_.get());
158
159 int nparts = -1;
160 const Teuchos::ParameterEntry *pe = this->params_->getEntryPtr("num_global_parts");
161 if(pe)
162 nparts = pe->getValue<int>(&nparts);
163
164 if(nparts == -1)
165 throw std::runtime_error("\nUser did not set num_global_parts"
166 "in the parameter list!n");
167 }
168
169#ifdef HAVE_ZOLTAN2_MPI
170 // Constructor where MPI communicator can be specified
171 SphynxProblem(Adapter *A, ParameterList *p, RCP<Teuchos::ParameterList> sphynxParams, MPI_Comm mpicomm):
172 SphynxProblem(A, p,sphynxParams,
173 rcp<const Comm<int> >(new Teuchos::MpiComm<int>(
174 Teuchos::opaqueWrapper(mpicomm))))
175 {}
176#endif
177
178 // Constructor where communicator is the Teuchos default.
179 SphynxProblem(Adapter *A, ParameterList *p, RCP<Teuchos::ParameterList> sphynxParams):
180 SphynxProblem(A, p,sphynxParams, Tpetra::getDefaultComm())
181 {}
182
183 // Destructor
185
189
190 void createAlgorithm() override;
191 void processAlgorithmName(const std::string& algorithm, const std::string& defString, const std::string& model,
192 Environment &env, bool& removeSelfEdges, bool& isGraphType, bool& needConsecutiveGlobalIds) override;
193
197
198
199 const PartitioningSolution<Adapter> &getSolution() {
200 return *(this->solution_.getRawPtr());
201 };
202
206
207 private:
208 Teuchos::RCP<Teuchos::ParameterList> envParams_;
209 RCP<ParameterList> sphynxParams_;
210
211
212 };
213
217
218 template <typename Adapter>
220 const std::string &algorithm, const std::string &defString,
221 const std::string &model, Environment &env, bool &removeSelfEdges,
222 bool &isGraphType, bool &needConsecutiveGlobalIds)
223 {
224 this->algName_ = std::string("sphynx");
225 }
226
227 template <typename Adapter>
229 {
230 // Create the algorithm
231 if (this->algName_ == std::string("sphynx")) {
232 this->algorithm_ = Teuchos::rcp(new Zoltan2::Sphynx<Adapter>(this->envConst_,
233 this->params_,
234 this->sphynxParams_,
235 this->comm_,
236 this->inputAdapter_));
237 }
238 else {
239 throw std::logic_error("partitioning algorithm not supported");
240 }
241 }
242
243} // namespace Zoltan2
244
245#endif
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
Defines the PartitioningProblem class.
Defines the PartitioningSolution class.
The user parameters, debug, timing and memory profiling output objects, and error checking methods.
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
PartitioningProblem sets up partitioning problems for the user.
RCP< PartitioningSolution< Adapter > > solution_
RCP< Environment > env_
RCP< ParameterList > params_
typename Adapter::part_t part_t
SphynxProblem(Adapter *A, Teuchos::ParameterList *p, RCP< Teuchos::ParameterList > sphynxParams, const RCP< const Teuchos::Comm< int > > &comm)
SphynxProblem(Adapter *A, ParameterList *p, RCP< Teuchos::ParameterList > sphynxParams)
const PartitioningSolution< Adapter > & getSolution()
void processAlgorithmName(const std::string &algorithm, const std::string &defString, const std::string &model, Environment &env, bool &removeSelfEdges, bool &isGraphType, bool &needConsecutiveGlobalIds) override
Adapter::base_adapter_t base_adapter_t
typename Adapter::scalar_t weight_t
Created by mbenlioglu on Aug 31, 2020.
static void getSphynxValidParameters(ParameterList &pl)
Set up validators specific to this algorithm.
static void setSphynxValidatorsInList(const Teuchos::ParameterList &plSome, const Teuchos::ParameterList &plAll, Teuchos::ParameterList &plVal)