50 #ifndef _ZOLTAN2_MAPPINGPROBLEM_HPP_
51 #define _ZOLTAN2_MAPPINGPROBLEM_HPP_
80 template<
typename Adapter,
82 MachineRepresentation<
typename Adapter::scalar_t,
89 typedef typename Adapter::gno_t
gno_t;
90 typedef typename Adapter::lno_t
lno_t;
91 typedef typename Adapter::user_t
user_t;
105 const Teuchos::RCP<
const Teuchos::Comm<int> > &ucomm_,
106 partsoln_t *partition_ = NULL, MachineRep *machine_ = NULL) :
107 Problem<Adapter>(A_, p_, ucomm_)
110 createMappingProblem(partition_, machine_);
113 #ifdef HAVE_ZOLTAN2_MPI
118 partsoln_t *partition_ = NULL, MachineRep *machine_ = NULL) :
120 rcp<const Comm<int> >(new
Teuchos::MpiComm<int>(
121 Teuchos::opaqueWrapper(mpicomm_))),
122 partition_, machine_)
142 void solve(
bool updateInputData=
true);
149 RCP<Teuchos::StringValidator> mapping_algorithm_Validator =
150 Teuchos::rcp(
new Teuchos::StringValidator(
151 Teuchos::tuple<std::string>(
"geometric",
"default",
"block" )));
152 pl.set(
"mapping_algorithm",
"default",
"mapping algorithm",
153 mapping_algorithm_Validator);
157 pl.set(
"distributed_input_adapter",
true,
158 "Whether the input adapter for mapping is distributed over processes or not",
162 pl.set(
"divide_prime_first",
false,
163 "When partitioning into-non power of two, whether to partition for nonpowers of two at the beginning, or at the end",
167 pl.set(
"ranks_per_node", 1,
168 "The number of MPI ranks per node",
170 pl.set(
"reduce_best_mapping",
true,
171 "If true, nodes will calculate different mappings with rotations, and best one will be reduced. If not, the result will be the one with longest dimension partitioning.",
182 void createMappingProblem(
partsoln_t *partition_, MachineRep *machine_);
184 Teuchos::RCP<mapsoln_t> soln;
186 Teuchos::RCP<partsoln_t> partition;
187 Teuchos::RCP<MachineRep> machine;
196 template <
typename Adapter,
typename MachineRep>
197 void MappingProblem<Adapter, MachineRep>::createMappingProblem(
198 partsoln_t *partition_,
199 MachineRep *machine_)
207 partition = Teuchos::rcp(partition_,
false);
213 partition = rcp(
new partsoln_t(this->env_, this->comm_,
214 this->inputAdapter_->getNumWeightsPerID()));
215 size_t nLocal = this->inputAdapter_->getLocalNumIDs();
217 const part_t *inputPartsView = NULL;
218 this->inputAdapter_->getPartsView(inputPartsView);
219 if (nLocal && inputPartsView == NULL) {
221 int me = this->comm_->getRank();
222 ArrayRCP<part_t> inputParts = arcp(
new part_t[nLocal], 0, nLocal,
true);
223 for (
size_t i = 0; i < nLocal; i++) inputParts[i] = me;
224 partition->setParts(inputParts);
228 ArrayRCP<part_t> inputParts = arcp(const_cast<part_t *>(inputPartsView),
230 partition->setParts(inputParts);
236 machine = Teuchos::rcp(machine_,
false);
239 Teuchos::ParameterList pl = this->env_->getParameters();
241 machine = Teuchos::rcp(
new MachineRep(*(this->comm_), pl));
248 template <
typename Adapter,
typename MachineRep>
255 std::string algName(
"block");
257 Teuchos::ParameterList pl = this->env_->getParametersNonConst();
258 const Teuchos::ParameterEntry *pe = pl.getEntryPtr(
"mapping_algorithm");
259 if (pe) algName = pe->getValue<std::string>(&algName);
262 if (algName ==
"default") {
264 #ifdef KDDKDD_NOT_READH
266 this->comm_, machine,
268 partition, this->envConst_));
269 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
270 this->algorithm_->map(this->soln);
273 else if (algName ==
"block") {
275 this->comm_, machine,
277 partition, this->envConst_));
278 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
279 this->algorithm_->map(this->soln);
281 else if (algName ==
"geometric") {
283 bool is_input_distributed =
true;
284 const Teuchos::ParameterEntry *pe_input_adapter = pl.getEntryPtr(
"distributed_input_adapter");
285 if (pe_input_adapter) is_input_distributed = pe_input_adapter->getValue<
bool>(&is_input_distributed);
288 int ranks_per_node = 1;
289 pe_input_adapter = pl.getEntryPtr(
"ranks_per_node");
290 if (pe_input_adapter) ranks_per_node = pe_input_adapter->getValue<
int>(&ranks_per_node);
292 bool divide_prime_first =
false;
293 pe_input_adapter = pl.getEntryPtr(
"divide_prime_first");
294 if (pe_input_adapter) divide_prime_first = pe_input_adapter->getValue<
bool>(÷_prime_first);
296 bool reduce_best_mapping =
true;
297 pe_input_adapter = pl.getEntryPtr(
"reduce_best_mapping");
298 if (pe_input_adapter) reduce_best_mapping = pe_input_adapter->getValue<
bool>(&reduce_best_mapping);
308 is_input_distributed, ranks_per_node, divide_prime_first, reduce_best_mapping));
309 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
310 this->algorithm_->map(this->soln);
315 throw std::logic_error(
"specified mapping_algorithm not supported");
330 MachineRepresentation=NULL
347 MachineRepresentation=NULL
361 MachineRepresentation=NULL
376 MachineRepresentation=NULL
390 In general, the applyPartitioningSolution method should take an
391 optional MappingSolution.
393 Should MappingSolution provide a re-numbered communicator reflecting the
new mapping?