14#include <Teuchos_ParameterList.hpp>
15#include <Teuchos_CommHelpers.hpp>
26template <
typename User>
45 const Teuchos::Comm<int> &comm_,
48 bool useInputParts_=
false)
52 nPartsPerRow(nPartsPerRow_),
53 lowestPartNum(lowestPartNum_),
54 useInputParts(useInputParts_)
59 for (
int i = 0, j = 0; i < nPartsPerRow; i++)
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;
145template <
typename Adapter>
149 const Teuchos::Comm<int> &comm
154 typedef typename Adapter::part_t
part_t;
160 if (ia.adapterUsesInputParts()) {
163 ia.getPartsView(inputParts);
169 int me = comm.getRank();
172 for (
size_t i = 0; i < ia.getLocalNumIDs(); i++)
173 defaultParts[i] = me;
177 delete [] defaultParts;
185template <
typename Adapter>
190 const Teuchos::Comm<int> &comm
193 typedef typename Adapter::part_t
part_t;
204template <
typename Adapter>
208 const typename Adapter::part_t *useTheseParts,
213 const Teuchos::Comm<int> &comm
216 typedef typename Adapter::part_t
part_t;
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);
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;
305template <
typename Adapter>
308 const RCP<
const Teuchos::Comm<int> > &comm,
312 typedef typename Adapter::part_t
part_t;
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;
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;
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.
typename InputTraits< User >::lno_t lno_t
typename InputTraits< User >::scalar_t scalar_t
typename InputTraits< User >::gno_t gno_t
typename InputTraits< User >::part_t part_t
A simple class that can be the User template argument for an InputAdapter.
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