14 #include <Teuchos_ParameterList.hpp>
15 #include <Teuchos_CommHelpers.hpp>
26 template <
typename User>
45 const Teuchos::Comm<int> &comm_,
48 bool useInputParts_=
false)
52 nPartsPerRow(nPartsPerRow_),
53 lowestPartNum(lowestPartNum_),
54 useInputParts(useInputParts_)
57 ids[j] = me * nCoordPerRank + j;
59 for (
int i = 0, j = 0; i < nPartsPerRow; i++)
60 for (
int k = 0; k < nCoordPerRank / nPartsPerRow; k++, j++)
61 inputparts[j] = lowestPartNum + i + me*nPartsPerRow;
75 std::cout << hi <<
" methods Rank " << me <<
" ids: ";
76 for (
size_t j = 0; j <
getLocalNumIDs(); j++) std::cout << mids[j] <<
" ";
77 std::cout << std::endl;
85 std::cout << hi <<
" methods Rank " << me <<
" coords: ";
89 std::cout << mcoords[k][j*stride[k]] <<
",";
92 std::cout << std::endl;
99 std::cout << hi <<
" methods Rank " << me <<
" parts: ";
100 if (minputparts != NULL)
102 std::cout << minputparts[j] <<
" ";
104 std::cout <<
"not provided";
105 std::cout << std::endl;
120 Coords = coords[Idx];
126 InputPart = inputparts;
145 template <
typename Adapter>
149 const Teuchos::Comm<int> &comm
160 if (ia.adapterUsesInputParts()) {
162 const part_t *inputParts;
163 ia.getPartsView(inputParts);
169 int me = comm.getRank();
171 part_t *defaultParts =
new part_t[ia.getLocalNumIDs()];
172 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
173 defaultParts[i] = me;
177 delete [] defaultParts;
185 template <
typename Adapter>
190 const Teuchos::Comm<int> &comm
204 template <
typename Adapter>
213 const Teuchos::Comm<int> &comm
218 int np = comm.getSize();
223 part_t globalmin, localmin = std::numeric_limits<part_t>::max();
224 part_t globalmax, localmax = 0;
226 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++) {
230 if (r < 0 || r >= np) {
232 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
233 <<
"Invalid rank " << r <<
" of " << np <<
" returned"
238 part_t p = useTheseParts[i];
239 if (p > localmax) localmax = p;
240 if (p < localmin) localmin = p;
244 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_MAX, 1,
245 &localmax, &globalmax);
246 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_MIN, 1,
247 &localmin, &globalmin);
253 for (part_t i = 0; i <
nParts; i++) {
258 if ((p < globalmin) || (p > globalmax)) {
260 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
261 <<
"Invalid part " << p <<
" of " << np <<
" returned"
270 bool errorThrownCorrectly =
false;
271 part_t sillyPart = globalmax+10;
275 catch (std::exception &e) {
276 errorThrownCorrectly =
true;
278 if (errorThrownCorrectly ==
false) {
280 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
281 <<
"Mapping Solution accepted a too-high part number "
282 << sillyPart <<
" returned " << ret << std::endl;
285 errorThrownCorrectly =
false;
286 sillyPart = globalmin - 1;
290 catch (std::exception &e) {
291 errorThrownCorrectly =
true;
293 if (errorThrownCorrectly ==
false) {
295 std::cout << __FILE__ <<
":" << __LINE__ <<
" "
296 <<
"Mapping Solution accepted a too-low part number "
297 << sillyPart <<
" returned " << ret << std::endl;
305 template <
typename Adapter>
308 const RCP<
const Teuchos::Comm<int> > &comm,
313 typedef typename Adapter::scalar_t scalar_t;
315 int me = comm->getRank();
316 int np = comm->getSize();
320 Teuchos::ParameterList params;
321 params.set(
"mapping_algorithm",
"block");
325 std::cout <<
"Testing Mapping using default machine" << std::endl;
332 if (!validMappingSolution<Adapter>(*msoln1, ia, *comm)) {
335 std::cout << hi <<
" FAILED: invalid mapping solution" << std::endl;
341 machine_t defMachine(*comm);
345 std::cout <<
"Testing Mapping using explicit machine" << std::endl;
353 if (!sameMappingSolution(*msoln1, *msoln2, *comm)) {
356 std::cout << hi <<
" FAILED: solution with explicit machine "
357 "differs from default" << std::endl;
363 std::cout <<
"Testing Mapping using a partitioning solution" << std::endl;
368 ArrayRCP<part_t> partList(ia.getLocalNumIDs());
369 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
370 partList[i] = (me + 1) % np;
374 #ifdef HAVE_ZOLTAN2_MPI
379 MPI_Comm mpicomm = Teuchos::getRawMpiComm(*comm);
394 std::cout << hi <<
" FAILED: invalid mapping solution "
395 "from partitioning solution" << std::endl;
402 int main(
int narg,
char *arg[])
404 Tpetra::ScopeGuard tscope(&narg, &arg);
405 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
407 int me = comm->getRank();
416 int nPartsPerRow = 1;
418 bool useInputParts =
true;
420 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
423 allgood =
runTest(ia, comm,
"test1");
430 int nPartsPerRow = 1;
432 bool useInputParts =
false;
433 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
440 int nPartsPerRow = 2;
442 bool useInputParts =
true;
443 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
450 int nPartsPerRow = 3;
452 bool useInputParts =
true;
453 vecAdapter_t ia(*comm, nPartsPerRow, firstPart, useInputParts);
458 if (allgood && (me == 0))
459 std::cout <<
"PASS" << std::endl;
bool validMappingSolution(Zoltan2::MappingSolution< Adapter > &msoln, Adapter &ia, const Teuchos::Comm< int > &comm)
typename InputTraits< User >::scalar_t scalar_t
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > zzuser_t
PartitionMapping maps a solution or an input distribution to ranks.
VerySimpleVectorAdapter(const Teuchos::Comm< int > &comm_, int nPartsPerRow_, int lowestPartNum_, bool useInputParts_=false)
map_t::global_ordinal_type gno_t
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)
Defines the VectorAdapter interface.
void getEntriesView(const scalar_t *&Coords, int &Stride, int Idx) const
Provide a pointer to the elements of the specified vector.
int main(int narg, char **arg)
common code used by tests
typename InputTraits< User >::part_t part_t
void print(std::string hi)
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.
size_t getLocalNumIDs() const
Returns the number of objects on this process.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
typename InputTraits< User >::gno_t gno_t
Zoltan2::VectorAdapter< User >::gno_t gno_t
Zoltan2::VectorAdapter< User >::lno_t lno_t
VectorAdapter defines the interface for vector input.
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.
void getMyPartsView(part_t &numParts, part_t *&parts)
Get the parts belonging to this rank.
void getIDsView(const gno_t *&Ids) const
Provide a pointer to this process' identifiers.
int getNumEntriesPerID() const
Return the number of vectors.
void getPartsView(const part_t *&InputPart) const
Provide pointer to an array containing the input part assignment for each ID. The input part informat...
static const int nCoordDim
MappingProblem enables mapping of a partition (either computed or input) to MPI ranks.
bool adapterUsesInputParts()
typename InputTraits< User >::lno_t lno_t
Zoltan2::VectorAdapter< User >::part_t part_t
Defines the MappingProblem class.