55 #include <unordered_set> 59 #include <Teuchos_Comm.hpp> 60 #include <Teuchos_DefaultComm.hpp> 66 static const char*
name() {
67 std::cout <<
"You are missing a DECL_TYPE_NAME" << std::endl;
72 #define DECL_TYPE_NAME(x) \ 73 template<> struct type_name<x> { static const char* name() {return #x;} } 80 static const std::string
fail =
"FAIL ";
81 static const std::string
pass =
" ";
84 void checkNUnique(std::string &name,
size_t nUniqueGids,
size_t nExpected)
86 if (nUniqueGids != nExpected)
87 std::cout <<
fail << name
88 <<
"nUniqueGids " << nUniqueGids <<
" != " << nExpected
93 template <
typename gno_t>
96 std::vector<gno_t> &gids,
98 const Teuchos::Comm<int> &comm
101 gno_t maxGid = 0, gmaxGid = 0;
102 size_t len = gids.size();
103 for (
size_t i = 0; i < len; i++)
104 if (gids[i] > maxGid) maxGid = gids[i];
106 Teuchos::reduceAll<int, gno_t>(comm, Teuchos::REDUCE_MAX, 1,
108 if (gmaxGid != maxExpected)
109 std::cout <<
fail << name
110 <<
"max Gid " << gmaxGid <<
" != " << maxExpected
115 template <
typename gno_t>
118 std::vector<gno_t> &gids,
120 const Teuchos::Comm<int> &comm
123 gno_t minGid = std::numeric_limits<gno_t>::max(), gminGid;
124 size_t len = gids.size();
125 for (
size_t i = 0; i < len; i++)
126 if (gids[i] < minGid) minGid = gids[i];
128 Teuchos::reduceAll<int, gno_t>(comm, Teuchos::REDUCE_MIN, 1,
130 if (gminGid != minExpected)
131 std::cout <<
fail << name
132 <<
"min Gid " << gminGid <<
" != " << minExpected
137 template <
typename gno_t>
140 std::vector<gno_t> &gids,
143 size_t gidsLen = gids.size();
144 std::unordered_set<gno_t> gidsSet(gidsLen);
147 for (
size_t i = 0; i < gidsLen; i++) {
148 if (gidsSet.find(gids[i]) != gidsSet.end()) {
153 gidsSet.insert(gids[i]);
155 size_t nUnique = gidsLen - nDups;
156 if (nUnique != nExpected)
157 std::cout <<
fail << name
158 <<
"num locally unique Gids " << nUnique <<
" != " << nExpected
164 template <
typename gno_t>
165 void test1(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
171 int me = comm->getRank();
172 int np = comm->getSize();
174 std::string name = std::string(
" test1: ")
176 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
178 typedef std::array<gno_t, 1> zkey_t;
179 typedef std::vector<zkey_t> keyvec_t;
180 typedef std::vector<gno_t> gidvec_t;
182 const size_t nKeys = me+1;
183 keyvec_t keys(nKeys);
184 gidvec_t gids(nKeys);
186 for (
size_t i = 0; i < nKeys; i++) {
192 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t, gno_t>(keys,gids,*comm);
196 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
209 template <
typename gno_t>
210 void test2(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
218 int me = comm->getRank();
219 int np = comm->getSize();
221 std::string name = std::string(
" test2: ")
223 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
225 typedef std::array<gno_t, 2> zkey_t;
226 typedef std::vector<zkey_t> keyvec_t;
227 typedef std::vector<gno_t> gidvec_t;
229 const size_t nKeys = 6;
230 const size_t nKeysHalf = 3;
231 keyvec_t keys(nKeys);
232 gidvec_t gids(nKeys);
234 for (
size_t i = 0; i < nKeysHalf; i++) {
240 for (
size_t i = 0; i < nKeysHalf; i++) {
242 k[0] = gno_t((me+i+1)%np);
244 keys[i+nKeysHalf] = k;
247 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
251 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
255 checkMaxGid(name, gids, gno_t(nKeysHalf*np-1), *comm);
262 template <
typename gno_t>
263 void test3(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
272 int me = comm->getRank();
273 int np = comm->getSize();
275 std::string name = std::string(
" test3: ")
277 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
279 typedef std::array<gno_t, 3> zkey_t;
280 typedef std::vector<zkey_t> keyvec_t;
281 typedef std::vector<gno_t> gidvec_t;
283 const size_t nKeys = 2*np;
284 const size_t nKeysHalf = np;
285 keyvec_t keys(nKeys);
286 gidvec_t gids(nKeys);
288 for (
size_t i = 0; i < nKeysHalf; i++) {
293 keys[i+nKeysHalf] = k;
295 for (
size_t i = 0; i < nKeysHalf; i++) {
303 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
313 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
326 template <
typename gno_t>
327 void test4(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
333 int me = comm->getRank();
335 std::string name = std::string(
" test4: ")
337 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
339 typedef std::array<gno_t, 4> zkey_t;
340 typedef std::vector<zkey_t> keyvec_t;
341 typedef std::vector<gno_t> gidvec_t;
343 const size_t nKeys = (me+1)%2;
344 keyvec_t keys(nKeys);
345 gidvec_t gids(nKeys);
347 for (
size_t i = 0; i < nKeys; i++) {
356 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
360 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
373 template <
typename gno_t>
374 void test5(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
383 int me = comm->getRank();
384 int np = comm->getSize();
386 std::string name = std::string(
" test5: ")
388 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
392 const size_t nVecs = 3;
393 const size_t nKeys = 2*np;
394 const size_t nKeysHalf = np;
397 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
399 typedef Tpetra::Map<lno_t, gno_t> map_t;
400 Teuchos::RCP<const map_t> map = rcp(
new map_t(gNEntries, nKeys, 0, comm),
403 Tpetra::MultiVector<gno_t, lno_t, gno_t> keys(map, nVecs);
404 Tpetra::Vector<gno_t, lno_t, gno_t> gids(map);
406 for (
size_t i = 0; i < nKeysHalf; i++) {
407 keys.replaceLocalValue(i+nKeysHalf, 0, gno_t(me));
408 keys.replaceLocalValue(i+nKeysHalf, 1, gno_t(me));
409 keys.replaceLocalValue(i+nKeysHalf, 2, gno_t(i));
411 for (
size_t i = 0; i < nKeysHalf; i++) {
412 keys.replaceLocalValue(i, 0, gno_t(i));
413 keys.replaceLocalValue(i, 1, gno_t(i));
414 keys.replaceLocalValue(i, 2, gno_t(i));
417 size_t nUniqueGids = Zoltan2::findUniqueGids<lno_t,gno_t>(keys,gids);
421 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
425 Teuchos::ArrayRCP<const gno_t> gidsData = gids.getData();
426 std::vector<gno_t> gidsVec(nKeys);
427 for (
size_t i = 0; i < nKeys; i++) gidsVec[i] = gidsData[i];
438 template <
typename gno_t>
439 void test6(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
445 int me = comm->getRank();
447 std::string name = std::string(
" test6: ")
449 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
453 const size_t nVecs = 4;
454 const size_t nKeys = (me+1)%2;
457 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
459 typedef Tpetra::Map<lno_t, gno_t> map_t;
460 Teuchos::RCP<const map_t> map = rcp(
new map_t(gNEntries, nKeys, 0, comm),
463 Tpetra::MultiVector<gno_t, lno_t, gno_t> keys(map, nVecs);
464 Tpetra::Vector<gno_t, lno_t, gno_t> gids(map);
466 for (
size_t i = 0; i < nKeys; i++) {
467 keys.replaceLocalValue(i, 0, gno_t(0));
468 keys.replaceLocalValue(i, 1, gno_t(1));
469 keys.replaceLocalValue(i, 2, gno_t(2));
470 keys.replaceLocalValue(i, 3, gno_t(3));
473 size_t nUniqueGids = Zoltan2::findUniqueGids<lno_t,gno_t>(keys,gids);
477 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
481 Teuchos::ArrayRCP<const gno_t> gidsData = gids.getData();
482 std::vector<gno_t> gidsVec(nKeys);
483 for (
size_t i = 0; i < nKeys; i++) gidsVec[i] = gidsData[i];
494 int main(
int argc,
char *argv[])
496 Teuchos::GlobalMPISession session(&argc, &argv);
497 Teuchos::RCP<const Teuchos::Comm<int> > comm =
498 Teuchos::DefaultComm<int>::getComm();
500 #ifdef HAVE_TPETRA_INT_INT 508 if (comm->getRank() == 0)
509 std::cout <<
"Skipping int tests because Tpetra is not build with " 510 <<
"GO == int" << std::endl;
513 #ifdef HAVE_TPETRA_INT_LONG_LONG 514 test1<long long>(comm);
515 test2<long long>(comm);
516 test3<long long>(comm);
517 test4<long long>(comm);
518 test5<long long>(comm);
519 test6<long long>(comm);
521 if (comm->getRank() == 0)
522 std::cout <<
"Skipping long long tests because Tpetra is not build with " 523 <<
"GO == long long" << std::endl;
void checkNUnique(std::string &name, size_t nUniqueGids, size_t nExpected)
int main(int argc, char *argv[])
void test3(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void test6(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
#define DECL_TYPE_NAME(x)
void test2(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void test5(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
static const char * name()
static const std::string fail
void test1(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void checkNLocallyUnique(std::string &name, std::vector< gno_t > &gids, size_t nExpected)
static const std::string pass
void checkMaxGid(std::string &name, std::vector< gno_t > &gids, gno_t maxExpected, const Teuchos::Comm< int > &comm)
Convert keys stored in std::vector to unique Gids stored in std::vector.
void checkMinGid(std::string &name, std::vector< gno_t > &gids, gno_t minExpected, const Teuchos::Comm< int > &comm)
void test4(Teuchos::RCP< const Teuchos::Comm< int > > &comm)