14 #ifndef _ZOLTAN2_MAPPINGPROBLEM_HPP_
15 #define _ZOLTAN2_MAPPINGPROBLEM_HPP_
45 template<
typename Adapter,
47 MachineRepresentation<
typename Adapter::scalar_t,
70 const Teuchos::RCP<
const Teuchos::Comm<int> > &ucomm_,
72 MachineRep *machine_ = NULL) :
73 Problem<Adapter>(A_, p_, ucomm_)
76 createMappingProblem(partition_, machine_);
79 #ifdef HAVE_ZOLTAN2_MPI
85 MachineRep *machine_ = NULL) :
87 rcp<const Comm<int> >(
88 new Teuchos::MpiComm<int>(
89 Teuchos::opaqueWrapper(mpicomm_))),
111 void solve(
bool updateInputData=
true);
119 RCP<Teuchos::StringValidator> mapping_algorithm_Validator =
120 Teuchos::rcp(
new Teuchos::StringValidator(
121 Teuchos::tuple<std::string>(
"geometric",
"default",
"block" )));
122 pl.set(
"mapping_algorithm",
"default",
"mapping algorithm",
123 mapping_algorithm_Validator);
127 pl.set(
"distributed_input_adapter",
true,
128 "Whether the input adapter for mapping is distributed over processes or not",
132 pl.set(
"divide_prime_first",
false,
133 "When partitioning into-non power of two, whether to partition for "
134 "nonpowers of two at the beginning, or at the end",
138 pl.set(
"ranks_per_node", 1,
139 "The number of MPI ranks per node",
141 pl.set(
"reduce_best_mapping",
true,
142 "If true, nodes will calculate different mappings with rotations, and best "
143 "one will be reduced. If not, the result will be the one with longest "
144 "dimension partitioning.",
155 void createMappingProblem(
partsoln_t *partition_, MachineRep *machine_);
157 Teuchos::RCP<mapsoln_t> soln;
159 Teuchos::RCP<partsoln_t> partition;
160 Teuchos::RCP<MachineRep> machine;
169 template <
typename Adapter,
typename MachineRep>
170 void MappingProblem<Adapter, MachineRep>::createMappingProblem(
171 partsoln_t *partition_,
172 MachineRep *machine_)
180 partition = Teuchos::rcp(partition_,
false);
186 partition = rcp(
new partsoln_t(this->env_, this->comm_,
187 this->inputAdapter_->getNumWeightsPerID()));
188 size_t nLocal = this->inputAdapter_->getLocalNumIDs();
190 const part_t *inputPartsView = NULL;
191 this->inputAdapter_->getPartsView(inputPartsView);
192 if (nLocal && inputPartsView == NULL) {
194 int me = this->comm_->getRank();
195 ArrayRCP<part_t> inputParts = arcp(
new part_t[nLocal], 0, nLocal,
true);
196 for (
size_t i = 0; i < nLocal; i++) inputParts[i] = me;
197 partition->setParts(inputParts);
201 ArrayRCP<part_t> inputParts = arcp(const_cast<part_t *>(inputPartsView),
203 partition->setParts(inputParts);
209 machine = Teuchos::rcp(machine_,
false);
212 Teuchos::ParameterList pl = this->env_->getParameters();
214 machine = Teuchos::rcp(
new MachineRep(*(this->comm_), pl));
221 template <
typename Adapter,
typename MachineRep>
228 std::string algName(
"block");
230 Teuchos::ParameterList pl = this->env_->getParametersNonConst();
231 const Teuchos::ParameterEntry *pe = pl.getEntryPtr(
"mapping_algorithm");
232 if (pe) algName = pe->getValue<std::string>(&algName);
235 if (algName ==
"default") {
237 #ifdef KDDKDD_NOT_READH
239 this->comm_, machine,
241 partition, this->envConst_));
242 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
243 this->algorithm_->map(this->soln);
246 else if (algName ==
"block") {
248 this->comm_, machine,
250 partition, this->envConst_));
251 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
252 this->algorithm_->map(this->soln);
254 else if (algName ==
"geometric") {
256 bool is_input_distributed =
true;
257 const Teuchos::ParameterEntry *pe_input_adapter =
258 pl.getEntryPtr(
"distributed_input_adapter");
259 if (pe_input_adapter)
260 is_input_distributed = pe_input_adapter->getValue<
bool>(&is_input_distributed);
263 int ranks_per_node = 1;
264 pe_input_adapter = pl.getEntryPtr(
"ranks_per_node");
265 if (pe_input_adapter)
266 ranks_per_node = pe_input_adapter->getValue<
int>(&ranks_per_node);
268 bool divide_prime_first =
false;
269 pe_input_adapter = pl.getEntryPtr(
"divide_prime_first");
270 if (pe_input_adapter)
271 divide_prime_first = pe_input_adapter->getValue<
bool>(÷_prime_first);
273 bool reduce_best_mapping =
true;
274 pe_input_adapter = pl.getEntryPtr(
"reduce_best_mapping");
275 if (pe_input_adapter)
276 reduce_best_mapping = pe_input_adapter->getValue<
bool>(&reduce_best_mapping);
284 is_input_distributed,
287 reduce_best_mapping));
289 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
291 this->algorithm_->map(this->soln);
295 throw std::logic_error(
"specified mapping_algorithm not supported");
310 MachineRepresentation=NULL
327 MachineRepresentation=NULL
341 MachineRepresentation=NULL
356 MachineRepresentation=NULL
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
PartitionMapping maps a solution or an input distribution to ranks.
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
Adapter::base_adapter_t base_adapter_t
map_t::global_ordinal_type gno_t
void solve(bool updateInputData=true)
Direct the problem to create a solution.
Defines the PartitioningSolution class.
Define a simple mapping of parts to processors assuming parts.
mapsoln_t * getSolution()
Get the solution to the problem.
SparseMatrixAdapter_t::part_t part_t
MappingProblem(Adapter *A_, Teuchos::ParameterList *p_, const Teuchos::RCP< const Teuchos::Comm< int > > &ucomm_, partsoln_t *partition_=NULL, MachineRep *machine_=NULL)
Constructor that takes an Teuchos communicator.
A PartitioningSolution is a solution to a partitioning problem.
Exception thrown when a called base-class method is not implemented.
static void getValidParameters(ParameterList &pl)
Set up validators specific to this Problem.
Problem base class from which other classes (PartitioningProblem, ColoringProblem, OrderingProblem, MatchingProblem, etc.) derive.
Defines the Problem base class.
map_t::local_ordinal_type lno_t
Adapter::scalar_t scalar_t
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyIntValidator()
Exists to make setting up validators less cluttered.
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
MappingSolution< Adapter > mapsoln_t
Defines the MappingSolution class.
Gathering definitions used in software development.
PartitioningSolution< Adapter > partsoln_t
MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
Teuchos::RCP< MachineRep > getMachine()
virtual ~MappingProblem()
Destructor.
#define __func__zoltan2__
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t