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_)
92 ids[j] = me * nCoordPerRank + j;
94 for (
int i = 0, j = 0; i < nPartsPerRow; i++)
95 for (
int k = 0; k < nCoordPerRank / nPartsPerRow; k++, j++)
96 inputparts[j] = lowestPartNum + i + me*nPartsPerRow;
101 if (nCoordDim > 2) coords[2][j] =
scalar_t(np);
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()) {
197 const part_t *inputParts;
198 ia.getPartsView(inputParts);
204 int me = comm.getRank();
206 part_t *defaultParts =
new part_t[ia.getLocalNumIDs()];
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);
288 for (part_t i = 0; i <
nParts; i++) {
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 argc,
char *argv[])
439 Teuchos::GlobalMPISession session(&argc, &argv);
440 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
441 int me = comm->getRank();
450 int nPartsPerRow = 1;
452 bool useInputParts =
true;
454 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
457 allgood =
runTest(ia, comm,
"test1");
464 int nPartsPerRow = 1;
466 bool useInputParts =
false;
467 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
474 int nPartsPerRow = 2;
476 bool useInputParts =
true;
477 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
484 int nPartsPerRow = 3;
486 bool useInputParts =
true;
487 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
492 if (allgood && (me == 0))
493 std::cout <<
"PASS" << std::endl;
InputTraits< User >::scalar_t scalar_t
int main(int argc, char *argv[])
bool validMappingSolution(Zoltan2::MappingSolution< Adapter > &msoln, Adapter &ia, const Teuchos::Comm< int > &comm)
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > zzuser_t
InputTraits< User >::gno_t gno_t
PartitionMapping maps a solution or an input distribution to ranks.
VerySimpleVectorAdapter(const Teuchos::Comm< int > &comm_, int nPartsPerRow_, int lowestPartNum_, bool useInputParts_=false)
int getNumEntriesPerID() const
Return the number of vectors (typically one).
void getPartsView(const part_t *&InputPart) const
void solve(bool updateInputData=true)
Direct the problem to create a solution.
bool runTest(Adapter &ia, const RCP< const Teuchos::Comm< int > > &comm, std::string hi)
A simple class that can be the User template argument for an InputAdapter.
InputTraits< User >::lno_t lno_t
Defines the VectorAdapter interface.
common code used by tests
void print(std::string hi)
void getEntriesView(const scalar_t *&Coords, int &Stride, int Idx) const
int adapterNPartsPerRow()
mapsoln_t * getSolution()
Get the solution to the problem.
Zoltan2::VectorAdapter< User >::scalar_t scalar_t
SparseMatrixAdapter_t::part_t part_t
A PartitioningSolution is a solution to a partitioning problem.
Zoltan2::VectorAdapter< User >::gno_t gno_t
Zoltan2::VectorAdapter< User >::lno_t lno_t
VectorAdapter defines the interface for vector input.
InputTraits< User >::part_t part_t
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
static const int nCoordPerRank
void setParts(ArrayRCP< part_t > &partList)
The algorithm uses setParts to set the solution.
int getRankForPart(part_t part)
Get the rank containing a part. Simplifying assumption: a part is wholy assigned to a rank; it is not...
int adapterLowestPartNum()
Defines the MappingSolution class.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
void getMyPartsView(part_t &numParts, part_t *&parts)
Get the parts belonging to this rank.
void getIDsView(const gno_t *&Ids) const
static const int nCoordDim
MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
bool adapterUsesInputParts()
Zoltan2::VectorAdapter< User >::part_t part_t
Defines the MappingProblem class.
size_t getLocalNumIDs() const
Returns the number of objects on this process.