19 #include <unordered_set>
29 template <
typename key_t,
typename gno_t>
31 const std::vector<key_t> &keys,
32 std::vector<gno_t> &gids,
33 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
37 const bool bUseLocalIDs =
false;
44 directory_t directory(comm, bUseLocalIDs, debug_level);
46 directory.update(keys.size(), &keys[0], NULL, &gids[0], NULL,
49 directory.remap_user_data_as_unique_gids();
52 directory.find(keys.size(), &keys[0], NULL, &gids[0], NULL, NULL,
false);
58 typedef long long mpi_t;
59 mpi_t nDDEntries =
static_cast<mpi_t
>(directory.node_map_size());
64 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM,
65 Teuchos::getRawMpiComm(*comm));
67 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
70 return size_t(nUnique);
76 static const char*
name() {
77 std::cout <<
"You are missing a DECL_TYPE_NAME" << std::endl;
82 #define DECL_TYPE_NAME(x) \
83 template<> struct type_name<x> { static const char* name() {return #x;} }
90 static const std::string
fail =
"FAIL ";
91 static const std::string
pass =
" ";
94 void checkNUnique(std::string &name,
size_t nUniqueGids,
size_t nExpected)
96 if (nUniqueGids != nExpected)
97 std::cout <<
fail << name
98 <<
"nUniqueGids " << nUniqueGids <<
" != " << nExpected
103 template <
typename gno_t>
106 std::vector<gno_t> &gids,
108 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
111 gno_t maxGid = 0, gmaxGid = 0;
112 size_t len = gids.size();
113 for (
size_t i = 0; i < len; i++)
114 if (gids[i] > maxGid) maxGid = gids[i];
116 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MAX, 1,
118 if (gmaxGid != maxExpected)
119 std::cout <<
fail << name
120 <<
"max Gid " << gmaxGid <<
" != " << maxExpected
125 template <
typename gno_t>
128 std::vector<gno_t> &gids,
130 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
133 gno_t minGid = std::numeric_limits<gno_t>::max(), gminGid;
134 size_t len = gids.size();
135 for (
size_t i = 0; i < len; i++)
136 if (gids[i] < minGid) minGid = gids[i];
138 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MIN, 1,
140 if (gminGid != minExpected)
141 std::cout <<
fail << name
142 <<
"min Gid " << gminGid <<
" != " << minExpected
147 template <
typename gno_t>
150 std::vector<gno_t> &gids,
153 size_t gidsLen = gids.size();
154 std::unordered_set<gno_t> gidsSet(gidsLen);
157 for (
size_t i = 0; i < gidsLen; i++) {
158 if (gidsSet.find(gids[i]) != gidsSet.end()) {
163 gidsSet.insert(gids[i]);
165 size_t nUnique = gidsLen - nDups;
166 if (nUnique != nExpected)
167 std::cout <<
fail << name
168 <<
"num locally unique Gids " << nUnique <<
" != " << nExpected
174 template <
typename gno_t>
175 void test1(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
181 int me = comm->getRank();
182 int np = comm->getSize();
184 std::string name = std::string(
" test1: ")
186 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
188 typedef std::array<gno_t, 1> zkey_t;
189 typedef std::vector<zkey_t> keyvec_t;
190 typedef std::vector<gno_t> gidvec_t;
192 const size_t nKeys = me+1;
193 keyvec_t keys(nKeys);
194 gidvec_t gids(nKeys);
196 for (
size_t i = 0; i < nKeys; i++) {
202 size_t nUniqueGids = findUniqueGids<zkey_t, gno_t>(keys,gids,comm);
206 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
219 template <
typename gno_t>
220 void test2(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
228 int me = comm->getRank();
229 int np = comm->getSize();
231 std::string name = std::string(
" test2: ")
233 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
235 typedef std::array<gno_t, 2> zkey_t;
236 typedef std::vector<zkey_t> keyvec_t;
237 typedef std::vector<gno_t> gidvec_t;
239 const size_t nKeys = 6;
240 const size_t nKeysHalf = 3;
241 keyvec_t keys(nKeys);
242 gidvec_t gids(nKeys);
244 for (
size_t i = 0; i < nKeysHalf; i++) {
250 for (
size_t i = 0; i < nKeysHalf; i++) {
252 k[0] =
gno_t((me+i+1)%np);
254 keys[i+nKeysHalf] = k;
257 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
261 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
271 template <
typename gno_t>
272 void test3(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
281 int me = comm->getRank();
282 int np = comm->getSize();
284 std::string name = std::string(
" test3: ")
286 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
288 typedef std::array<gno_t, 3> zkey_t;
289 typedef std::vector<zkey_t> keyvec_t;
290 typedef std::vector<gno_t> gidvec_t;
292 const size_t nKeys = 2*np;
293 const size_t nKeysHalf = np;
294 keyvec_t keys(nKeys);
295 gidvec_t gids(nKeys);
297 for (
size_t i = 0; i < nKeysHalf; i++) {
302 keys[i+nKeysHalf] = k;
304 for (
size_t i = 0; i < nKeysHalf; i++) {
312 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
322 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
335 template <
typename gno_t>
336 void test4(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
342 int me = comm->getRank();
344 std::string name = std::string(
" test4: ")
346 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
348 typedef std::array<gno_t, 4> zkey_t;
349 typedef std::vector<zkey_t> keyvec_t;
350 typedef std::vector<gno_t> gidvec_t;
352 const size_t nKeys = (me+1)%2;
353 keyvec_t keys(nKeys);
354 gidvec_t gids(nKeys);
356 for (
size_t i = 0; i < nKeys; i++) {
365 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
369 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
382 int main(
int argc,
char *argv[])
384 Tpetra::ScopeGuard tscope(&argc, &argv);
385 Teuchos::RCP<const Teuchos::Comm<int> > comm =
386 Teuchos::DefaultComm<int>::getComm();
388 Zoltan2::test1<int>(comm);
389 Zoltan2::test2<int>(comm);
390 Zoltan2::test3<int>(comm);
391 Zoltan2::test4<int>(comm);
393 Zoltan2::test1<long long>(comm);
394 Zoltan2::test2<long long>(comm);
395 Zoltan2::test3<long long>(comm);
396 Zoltan2::test4<long long>(comm);
void test1(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
map_t::global_ordinal_type gno_t
int main(int narg, char **arg)
void test4(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
static const std::string pass
void checkNUnique(std::string &name, size_t nUniqueGids, size_t nExpected)
map_t::local_ordinal_type lno_t
size_t findUniqueGids(Tpetra::MultiVector< gno_t, lno_t, gno_t > &keys, Tpetra::Vector< gno_t, lno_t, gno_t > &gids)
void test2(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
static const std::string fail
void checkNLocallyUnique(std::string &name, std::vector< gno_t > &gids, size_t nExpected)
Gathering definitions used in software development.
static const char * name()
void test3(Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void checkMinGid(std::string &name, std::vector< gno_t > &gids, gno_t minExpected, Teuchos::RCP< const Teuchos::Comm< int > > &comm)
void checkMaxGid(std::string &name, std::vector< gno_t > &gids, gno_t maxExpected, Teuchos::RCP< const Teuchos::Comm< int > > &comm)