50#ifndef _ZOLTAN2_MAPPINGPROBLEM_HPP_
51#define _ZOLTAN2_MAPPINGPROBLEM_HPP_
81template<
typename Adapter,
83 MachineRepresentation<
typename Adapter::scalar_t,
84 typename Adapter::part_t> >
90 typedef typename Adapter::gno_t
gno_t;
91 typedef typename Adapter::lno_t
lno_t;
92 typedef typename Adapter::user_t
user_t;
93 typedef typename Adapter::part_t
part_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> >(
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;
205template <
typename Adapter,
typename MachineRep>
206void 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));
257template <
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
274 this->algorithm_ = rcp(
new AlgDefaultMapping<Adapter,MachineRep>(
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") {
283 this->algorithm_ = rcp(
new AlgBlockMapping<Adapter,MachineRep>(
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);
315 rcp(
new CoordinateTaskMapper<Adapter,part_t>(this->comm_,
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
Define a simple mapping of parts to processors assuming parts.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
#define __func__zoltan2__
Defines the MappingSolution class.
Defines the PartitioningSolution class.
Defines the Problem base class.
Gathering definitions used in software development.
static RCP< Teuchos::BoolParameterEntryValidator > getBoolValidator()
Exists to make setting up validators less cluttered.
static RCP< Teuchos::AnyNumberParameterEntryValidator > getAnyIntValidator()
Exists to make setting up validators less cluttered.
MachineRepresentation Class Base class for representing machine coordinates, networks,...
MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
Adapter::scalar_t scalar_t
MappingSolution< Adapter > mapsoln_t
Adapter::base_adapter_t base_adapter_t
static void getValidParameters(ParameterList &pl)
Set up validators specific to this Problem.
mapsoln_t * getSolution()
Get the solution to the problem.
virtual ~MappingProblem()
Destructor.
PartitioningSolution< Adapter > partsoln_t
Teuchos::RCP< MachineRep > getMachine()
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.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
Exception thrown when a called base-class method is not implemented.
A PartitioningSolution is a solution to a partitioning problem.
Problem base class from which other classes (PartitioningProblem, ColoringProblem,...
Created by mbenlioglu on Aug 31, 2020.
SparseMatrixAdapter_t::part_t part_t