49#include <Teuchos_ParameterList.hpp>
50#include <Teuchos_CommHelpers.hpp>
61template <
typename User>
80 const Teuchos::Comm<int> &comm_,
83 bool useInputParts_=
false)
87 nPartsPerRow(nPartsPerRow_),
88 lowestPartNum(lowestPartNum_),
89 useInputParts(useInputParts_)
94 for (
int i = 0, j = 0; i < nPartsPerRow; i++)
96 inputparts[j] = lowestPartNum + i + me*nPartsPerRow;
110 std::cout << hi <<
" methods Rank " << me <<
" ids: ";
111 for (
size_t j = 0; j <
getLocalNumIDs(); j++) std::cout << mids[j] <<
" ";
112 std::cout << std::endl;
120 std::cout << hi <<
" methods Rank " << me <<
" coords: ";
124 std::cout << mcoords[k][j*stride[k]] <<
",";
127 std::cout << std::endl;
132 const part_t *minputparts;
134 std::cout << hi <<
" methods Rank " << me <<
" parts: ";
135 if (minputparts != NULL)
137 std::cout << minputparts[j] <<
" ";
139 std::cout <<
"not provided";
140 std::cout << std::endl;
155 Coords = coords[Idx];
161 InputPart = inputparts;
180template <
typename Adapter>
184 const Teuchos::Comm<int> &comm
195 if (ia.adapterUsesInputParts()) {
198 ia.getPartsView(inputParts);
204 int me = comm.getRank();
207 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
208 defaultParts[i] = me;
212 delete [] defaultParts;
220template <
typename Adapter>
225 const Teuchos::Comm<int> &comm
239template <
typename Adapter>
248 const Teuchos::Comm<int> &comm
253 int np = comm.getSize();
258 part_t globalmin, localmin = std::numeric_limits<part_t>::max();
259 part_t globalmax, localmax = 0;
261 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++) {
265 if (r < 0 || r >= np) {
267 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
268 <<
"Invalid rank " << r <<
" of " << np <<
" returned"
273 part_t p = useTheseParts[i];
274 if (p > localmax) localmax = p;
275 if (p < localmin) localmin = p;
279 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_MAX, 1,
280 &localmax, &globalmax);
281 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_MIN, 1,
282 &localmin, &globalmin);
293 if ((p < globalmin) || (p > globalmax)) {
295 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
296 <<
"Invalid part " << p <<
" of " << np <<
" returned"
305 bool errorThrownCorrectly =
false;
306 part_t sillyPart = globalmax+10;
310 catch (std::exception &e) {
311 errorThrownCorrectly =
true;
313 if (errorThrownCorrectly ==
false) {
315 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
316 <<
"Mapping Solution accepted a too-high part number "
317 << sillyPart <<
" returned " << ret << std::endl;
320 errorThrownCorrectly =
false;
321 sillyPart = globalmin - 1;
325 catch (std::exception &e) {
326 errorThrownCorrectly =
true;
328 if (errorThrownCorrectly ==
false) {
330 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
331 <<
"Mapping Solution accepted a too-low part number "
332 << sillyPart <<
" returned " << ret << std::endl;
340template <
typename Adapter>
343 const RCP<
const Teuchos::Comm<int> > &comm,
348 typedef typename Adapter::scalar_t scalar_t;
350 int me = comm->getRank();
351 int np = comm->getSize();
355 Teuchos::ParameterList params;
356 params.set(
"mapping_algorithm",
"block");
360 std::cout <<
"Testing Mapping using default machine" << std::endl;
367 if (!validMappingSolution<Adapter>(*msoln1, ia, *comm)) {
370 std::cout << hi <<
" FAILED: invalid mapping solution" << std::endl;
376 machine_t defMachine(*comm);
380 std::cout <<
"Testing Mapping using explicit machine" << std::endl;
388 if (!sameMappingSolution(*msoln1, *msoln2, *comm)) {
391 std::cout << hi <<
" FAILED: solution with explicit machine "
392 "differs from default" << std::endl;
398 std::cout <<
"Testing Mapping using a partitioning solution" << std::endl;
403 ArrayRCP<part_t> partList(ia.getLocalNumIDs());
404 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
405 partList[i] = (me + 1) % np;
409#ifdef HAVE_ZOLTAN2_MPI
414 MPI_Comm mpicomm = Teuchos::getRawMpiComm(*comm);
429 std::cout << hi <<
" FAILED: invalid mapping solution "
430 "from partitioning solution" << std::endl;
439 Tpetra::ScopeGuard tscope(&narg, &arg);
440 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
442 int me = comm->getRank();
451 int nPartsPerRow = 1;
453 bool useInputParts =
true;
455 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
458 allgood =
runTest(ia, comm,
"test1");
465 int nPartsPerRow = 1;
467 bool useInputParts =
false;
468 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
475 int nPartsPerRow = 2;
477 bool useInputParts =
true;
478 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
485 int nPartsPerRow = 3;
487 bool useInputParts =
true;
488 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
493 if (allgood && (me == 0))
494 std::cout <<
"PASS" << std::endl;
int main(int narg, char *arg[])
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > zzuser_t
bool validMappingSolution(Zoltan2::MappingSolution< Adapter > &msoln, Adapter &ia, const Teuchos::Comm< int > &comm)
bool runTest(Adapter &ia, const RCP< const Teuchos::Comm< int > > &comm, std::string hi)
Defines the MappingProblem class.
Defines the MappingSolution class.
common code used by tests
Defines the VectorAdapter interface.
void print(std::string hi)
int adapterNPartsPerRow()
static const int nCoordDim
void getIDsView(const gno_t *&Ids) const
static const int nCoordPerRank
void getEntriesView(const scalar_t *&Coords, int &Stride, int Idx) const
Zoltan2::VectorAdapter< User >::gno_t gno_t
void getPartsView(const part_t *&InputPart) const
Zoltan2::VectorAdapter< User >::lno_t lno_t
Zoltan2::VectorAdapter< User >::part_t part_t
VerySimpleVectorAdapter(const Teuchos::Comm< int > &comm_, int nPartsPerRow_, int lowestPartNum_, bool useInputParts_=false)
Zoltan2::VectorAdapter< User >::scalar_t scalar_t
bool adapterUsesInputParts()
int adapterLowestPartNum()
size_t getLocalNumIDs() const
Returns the number of objects on this process.
int getNumEntriesPerID() const
Return the number of vectors.
InputTraits< User >::part_t part_t
InputTraits< User >::scalar_t scalar_t
InputTraits< User >::lno_t lno_t
InputTraits< User >::gno_t gno_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods.
MachineRepresentation Class Base class for representing machine coordinates, networks,...
MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
mapsoln_t * getSolution()
Get the solution to the problem.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
PartitionMapping maps a solution or an input distribution to ranks.
int getRankForPart(part_t part)
Get the rank containing a part. Simplifying assumption: a part is wholy assigned to a rank; it is not...
void getMyPartsView(part_t &numParts, part_t *&parts)
Get the parts belonging to this rank.
A PartitioningSolution is a solution to a partitioning problem.
void setParts(ArrayRCP< part_t > &partList)
The algorithm uses setParts to set the solution.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
VectorAdapter defines the interface for vector input.
map_t::global_ordinal_type gno_t
SparseMatrixAdapter_t::part_t part_t