50 #ifndef _ZOLTAN2_MAPPINGPROBLEM_HPP_
51 #define _ZOLTAN2_MAPPINGPROBLEM_HPP_
81 template<
typename Adapter,
83 MachineRepresentation<
typename Adapter::scalar_t,
90 typedef typename Adapter::gno_t
gno_t;
91 typedef typename Adapter::lno_t
lno_t;
106 const Teuchos::RCP<
const Teuchos::Comm<int> > &ucomm_,
108 MachineRep *machine_ = NULL) :
109 Problem<Adapter>(A_, p_, ucomm_)
112 createMappingProblem(partition_, machine_);
115 #ifdef HAVE_ZOLTAN2_MPI
121 MachineRep *machine_ = NULL) :
123 rcp<const Comm<int> >(
124 new Teuchos::MpiComm<int>(
125 Teuchos::opaqueWrapper(mpicomm_))),
126 partition_, machine_)
147 void solve(
bool updateInputData=
true);
155 RCP<Teuchos::StringValidator> mapping_algorithm_Validator =
156 Teuchos::rcp(
new Teuchos::StringValidator(
157 Teuchos::tuple<std::string>(
"geometric",
"default",
"block" )));
158 pl.set(
"mapping_algorithm",
"default",
"mapping algorithm",
159 mapping_algorithm_Validator);
163 pl.set(
"distributed_input_adapter",
true,
164 "Whether the input adapter for mapping is distributed over processes or not",
168 pl.set(
"divide_prime_first",
false,
169 "When partitioning into-non power of two, whether to partition for "
170 "nonpowers of two at the beginning, or at the end",
174 pl.set(
"ranks_per_node", 1,
175 "The number of MPI ranks per node",
177 pl.set(
"reduce_best_mapping",
true,
178 "If true, nodes will calculate different mappings with rotations, and best "
179 "one will be reduced. If not, the result will be the one with longest "
180 "dimension partitioning.",
191 void createMappingProblem(
partsoln_t *partition_, MachineRep *machine_);
193 Teuchos::RCP<mapsoln_t> soln;
195 Teuchos::RCP<partsoln_t> partition;
196 Teuchos::RCP<MachineRep> machine;
205 template <
typename Adapter,
typename MachineRep>
206 void MappingProblem<Adapter, MachineRep>::createMappingProblem(
207 partsoln_t *partition_,
208 MachineRep *machine_)
216 partition = Teuchos::rcp(partition_,
false);
222 partition = rcp(
new partsoln_t(this->env_, this->comm_,
223 this->inputAdapter_->getNumWeightsPerID()));
224 size_t nLocal = this->inputAdapter_->getLocalNumIDs();
226 const part_t *inputPartsView = NULL;
227 this->inputAdapter_->getPartsView(inputPartsView);
228 if (nLocal && inputPartsView == NULL) {
230 int me = this->comm_->getRank();
231 ArrayRCP<part_t> inputParts = arcp(
new part_t[nLocal], 0, nLocal,
true);
232 for (
size_t i = 0; i < nLocal; i++) inputParts[i] = me;
233 partition->setParts(inputParts);
237 ArrayRCP<part_t> inputParts = arcp(const_cast<part_t *>(inputPartsView),
239 partition->setParts(inputParts);
245 machine = Teuchos::rcp(machine_,
false);
248 Teuchos::ParameterList pl = this->env_->getParameters();
250 machine = Teuchos::rcp(
new MachineRep(*(this->comm_), pl));
257 template <
typename Adapter,
typename MachineRep>
264 std::string algName(
"block");
266 Teuchos::ParameterList pl = this->env_->getParametersNonConst();
267 const Teuchos::ParameterEntry *pe = pl.getEntryPtr(
"mapping_algorithm");
268 if (pe) algName = pe->getValue<std::string>(&algName);
271 if (algName ==
"default") {
273 #ifdef KDDKDD_NOT_READH
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);
282 else if (algName ==
"block") {
284 this->comm_, machine,
286 partition, this->envConst_));
287 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
288 this->algorithm_->map(this->soln);
290 else if (algName ==
"geometric") {
292 bool is_input_distributed =
true;
293 const Teuchos::ParameterEntry *pe_input_adapter =
294 pl.getEntryPtr(
"distributed_input_adapter");
295 if (pe_input_adapter)
296 is_input_distributed = pe_input_adapter->getValue<
bool>(&is_input_distributed);
299 int ranks_per_node = 1;
300 pe_input_adapter = pl.getEntryPtr(
"ranks_per_node");
301 if (pe_input_adapter)
302 ranks_per_node = pe_input_adapter->getValue<
int>(&ranks_per_node);
304 bool divide_prime_first =
false;
305 pe_input_adapter = pl.getEntryPtr(
"divide_prime_first");
306 if (pe_input_adapter)
307 divide_prime_first = pe_input_adapter->getValue<
bool>(÷_prime_first);
309 bool reduce_best_mapping =
true;
310 pe_input_adapter = pl.getEntryPtr(
"reduce_best_mapping");
311 if (pe_input_adapter)
312 reduce_best_mapping = pe_input_adapter->getValue<
bool>(&reduce_best_mapping);
320 is_input_distributed,
323 reduce_best_mapping));
325 this->soln = rcp(
new mapsoln_t(this->env_, this->comm_, this->algorithm_));
327 this->algorithm_->map(this->soln);
331 throw std::logic_error(
"specified mapping_algorithm not supported");
346 MachineRepresentation=NULL
363 MachineRepresentation=NULL
377 MachineRepresentation=NULL
392 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
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.
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