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
189 typedef typename Adapter::part_t part_t;
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
228 typedef typename Adapter::part_t part_t;
239 template <
typename Adapter>
243 const typename Adapter::part_t *useTheseParts,
248 const Teuchos::Comm<int> &comm
251 typedef typename Adapter::part_t part_t;
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,
347 typedef typename Adapter::part_t part_t;
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;
375 machine_t defMachine(*comm);
379 std::cout <<
"Testing Mapping using explicit machine" << std::endl;
387 if (!sameMappingSolution(*msoln1, *msoln2, *comm)) {
390 std::cout << hi <<
" FAILED: solution with explicit machine " 391 "differs from default" << std::endl;
397 std::cout <<
"Testing Mapping using a partitioning solution" << std::endl;
402 ArrayRCP<part_t> partList(ia.getLocalNumIDs());
403 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
404 partList[i] = (me + 1) % np;
417 std::cout << hi <<
" FAILED: invalid mapping solution " 418 "from partitioning solution" << std::endl;
425 int main(
int argc,
char *argv[])
427 Teuchos::GlobalMPISession session(&argc, &argv);
428 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
429 int me = comm->getRank();
433 typedef vecAdapter_t::part_t part_t;
434 typedef vecAdapter_t::scalar_t scalar_t;
438 int nPartsPerRow = 1;
440 bool useInputParts =
true;
442 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
445 allgood =
runTest(ia, comm,
"test1");
452 int nPartsPerRow = 1;
454 bool useInputParts =
false;
455 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
462 int nPartsPerRow = 2;
464 bool useInputParts =
true;
465 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
472 int nPartsPerRow = 3;
474 bool useInputParts =
true;
475 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
480 if (allgood && (me == 0))
481 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
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,...
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.