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;} }
81 static const std::string
fail =
"FAIL ";
82 static const std::string
pass =
" ";
85 void checkNUnique(std::string &name,
size_t nUniqueGids,
size_t nExpected)
87 if (nUniqueGids != nExpected)
88 std::cout <<
fail << name
89 <<
"nUniqueGids " << nUniqueGids <<
" != " << nExpected
94 template <
typename gno_t>
97 std::vector<gno_t> &gids,
99 const Teuchos::Comm<int> &comm
102 gno_t maxGid = 0, gmaxGid = 0;
103 size_t len = gids.size();
104 for (
size_t i = 0; i < len; i++)
105 if (gids[i] > maxGid) maxGid = gids[i];
107 Teuchos::reduceAll<int, gno_t>(comm, Teuchos::REDUCE_MAX, 1,
109 if (gmaxGid != maxExpected)
110 std::cout <<
fail << name
111 <<
"max Gid " << gmaxGid <<
" != " << maxExpected
116 template <
typename gno_t>
119 std::vector<gno_t> &gids,
121 const Teuchos::Comm<int> &comm
124 gno_t minGid = std::numeric_limits<gno_t>::max(), gminGid;
125 size_t len = gids.size();
126 for (
size_t i = 0; i < len; i++)
127 if (gids[i] < minGid) minGid = gids[i];
129 Teuchos::reduceAll<int, gno_t>(comm, Teuchos::REDUCE_MIN, 1,
131 if (gminGid != minExpected)
132 std::cout <<
fail << name
133 <<
"min Gid " << gminGid <<
" != " << minExpected
138 template <
typename gno_t>
141 std::vector<gno_t> &gids,
144 size_t gidsLen = gids.size();
145 std::unordered_set<gno_t> gidsSet(gidsLen);
148 for (
size_t i = 0; i < gidsLen; i++) {
149 if (gidsSet.find(gids[i]) != gidsSet.end()) {
154 gidsSet.insert(gids[i]);
156 size_t nUnique = gidsLen - nDups;
157 if (nUnique != nExpected)
158 std::cout <<
fail << name
159 <<
"num locally unique Gids " << nUnique <<
" != " << nExpected
165 template <
typename gno_t>
166 void test1(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
172 int me = comm->getRank();
173 int np = comm->getSize();
175 std::string name = std::string(
" test1: ")
177 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
179 typedef std::array<gno_t, 1> zkey_t;
180 typedef std::vector<zkey_t> keyvec_t;
181 typedef std::vector<gno_t> gidvec_t;
183 const size_t nKeys = me+1;
184 keyvec_t keys(nKeys);
185 gidvec_t gids(nKeys);
187 for (
size_t i = 0; i < nKeys; i++) {
193 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t, gno_t>(keys,gids,*comm);
197 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
210 template <
typename gno_t>
211 void test2(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
219 int me = comm->getRank();
220 int np = comm->getSize();
222 std::string name = std::string(
" test2: ")
224 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
226 typedef std::array<gno_t, 2> zkey_t;
227 typedef std::vector<zkey_t> keyvec_t;
228 typedef std::vector<gno_t> gidvec_t;
230 const size_t nKeys = 6;
231 const size_t nKeysHalf = 3;
232 keyvec_t keys(nKeys);
233 gidvec_t gids(nKeys);
235 for (
size_t i = 0; i < nKeysHalf; i++) {
241 for (
size_t i = 0; i < nKeysHalf; i++) {
243 k[0] = gno_t((me+i+1)%np);
245 keys[i+nKeysHalf] = k;
248 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
252 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
256 checkMaxGid(name, gids, gno_t(nKeysHalf*np-1), *comm);
263 template <
typename gno_t>
264 void test3(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
273 int me = comm->getRank();
274 int np = comm->getSize();
276 std::string name = std::string(
" test3: ")
278 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
280 typedef std::array<gno_t, 3> zkey_t;
281 typedef std::vector<zkey_t> keyvec_t;
282 typedef std::vector<gno_t> gidvec_t;
284 const size_t nKeys = 2*np;
285 const size_t nKeysHalf = np;
286 keyvec_t keys(nKeys);
287 gidvec_t gids(nKeys);
289 for (
size_t i = 0; i < nKeysHalf; i++) {
294 keys[i+nKeysHalf] = k;
296 for (
size_t i = 0; i < nKeysHalf; i++) {
304 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
314 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
327 template <
typename gno_t>
328 void test4(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
334 int me = comm->getRank();
336 std::string name = std::string(
" test4: ")
338 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
340 typedef std::array<gno_t, 4> zkey_t;
341 typedef std::vector<zkey_t> keyvec_t;
342 typedef std::vector<gno_t> gidvec_t;
344 const size_t nKeys = (me+1)%2;
345 keyvec_t keys(nKeys);
346 gidvec_t gids(nKeys);
348 for (
size_t i = 0; i < nKeys; i++) {
357 size_t nUniqueGids = Zoltan2::findUniqueGids<zkey_t,gno_t>(keys,gids,*comm);
361 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
374 template <
typename gno_t>
375 void test5(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
384 int me = comm->getRank();
385 int np = comm->getSize();
387 std::string name = std::string(
" test5: ")
389 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
393 const size_t nVecs = 3;
394 const size_t nKeys = 2*np;
395 const size_t nKeysHalf = np;
398 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
400 typedef Tpetra::Map<lno_t, gno_t> map_t;
401 Teuchos::RCP<const map_t> map = rcp(
new map_t(gNEntries, nKeys, 0, comm),
404 Tpetra::MultiVector<gno_t, lno_t, gno_t> keys(map, nVecs);
405 Tpetra::Vector<gno_t, lno_t, gno_t> gids(map);
407 for (
size_t i = 0; i < nKeysHalf; i++) {
408 keys.replaceLocalValue(i+nKeysHalf, 0, gno_t(me));
409 keys.replaceLocalValue(i+nKeysHalf, 1, gno_t(me));
410 keys.replaceLocalValue(i+nKeysHalf, 2, gno_t(i));
412 for (
size_t i = 0; i < nKeysHalf; i++) {
413 keys.replaceLocalValue(i, 0, gno_t(i));
414 keys.replaceLocalValue(i, 1, gno_t(i));
415 keys.replaceLocalValue(i, 2, gno_t(i));
418 size_t nUniqueGids = Zoltan2::findUniqueGids<lno_t,gno_t>(keys,gids);
422 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
426 Teuchos::ArrayRCP<const gno_t> gidsData = gids.getData();
427 std::vector<gno_t> gidsVec(nKeys);
428 for (
size_t i = 0; i < nKeys; i++) gidsVec[i] = gidsData[i];
439 template <
typename gno_t>
440 void test6(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
446 int me = comm->getRank();
448 std::string name = std::string(
" test6: ")
450 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
454 const size_t nVecs = 4;
455 const size_t nKeys = (me+1)%2;
458 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid();
460 typedef Tpetra::Map<lno_t, gno_t> map_t;
461 Teuchos::RCP<const map_t> map = rcp(
new map_t(gNEntries, nKeys, 0, comm),
464 Tpetra::MultiVector<gno_t, lno_t, gno_t> keys(map, nVecs);
465 Tpetra::Vector<gno_t, lno_t, gno_t> gids(map);
467 for (
size_t i = 0; i < nKeys; i++) {
468 keys.replaceLocalValue(i, 0, gno_t(0));
469 keys.replaceLocalValue(i, 1, gno_t(1));
470 keys.replaceLocalValue(i, 2, gno_t(2));
471 keys.replaceLocalValue(i, 3, gno_t(3));
474 size_t nUniqueGids = Zoltan2::findUniqueGids<lno_t,gno_t>(keys,gids);
478 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
482 Teuchos::ArrayRCP<const gno_t> gidsData = gids.getData();
483 std::vector<gno_t> gidsVec(nKeys);
484 for (
size_t i = 0; i < nKeys; i++) gidsVec[i] = gidsData[i];
495 int main(
int narg,
char *arg[])
497 Tpetra::ScopeGuard tscope(&narg, &arg);
498 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
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
521 if (comm->getRank() == 0)
522 std::cout <<
"Skipping long tests because Tpetra is not build with "
523 <<
"GO == long " << std::endl;
526 #ifdef HAVE_TPETRA_INT_LONG_LONG
527 test1<long long>(comm);
528 test2<long long>(comm);
529 test3<long long>(comm);
530 test4<long long>(comm);
531 test5<long long>(comm);
532 test6<long long>(comm);
534 if (comm->getRank() == 0)
535 std::cout <<
"Skipping long long tests because Tpetra is not build with "
536 <<
"GO == long long" << std::endl;
void checkNUnique(std::string &name, size_t nUniqueGids, size_t nExpected)
void test3(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void test6(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
#define DECL_TYPE_NAME(x)
int main(int narg, char *arg[])
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
Tpetra::global_size_t global_size_t
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)