49 #include <Teuchos_ParameterList.hpp>
50 #include <Teuchos_CommHelpers.hpp>
61 template <
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;
180 template <
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;
220 template <
typename Adapter>
225 const Teuchos::Comm<int> &comm
239 template <
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;
340 template <
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;
437 int main(
int narg,
char *arg[])
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;