55 #include <unordered_set>
65 template <
typename key_t,
typename gno_t>
67 const std::vector<key_t> &keys,
68 std::vector<gno_t> &gids,
69 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
73 const bool bUseLocalIDs =
false;
80 directory_t directory(comm, bUseLocalIDs, debug_level);
82 directory.update(keys.size(), &keys[0], NULL, &gids[0], NULL,
85 directory.remap_user_data_as_unique_gids();
88 directory.find(keys.size(), &keys[0], NULL, &gids[0], NULL, NULL,
false);
94 typedef long long mpi_t;
95 mpi_t nDDEntries =
static_cast<mpi_t
>(directory.node_map_size());
100 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM,
101 Teuchos::getRawMpiComm(*comm));
103 MPI_Allreduce(&nDDEntries, &nUnique, 1, MPI_LONG_LONG, MPI_SUM, MPI_COMM_WORLD);
106 return size_t(nUnique);
113 std::cout <<
"You are missing a DECL_TYPE_NAME" << std::endl;
118 #define DECL_TYPE_NAME(x) \
119 template<> struct type_name<x> { static const char* name() {return #x;} }
126 static const std::string
fail =
"FAIL ";
127 static const std::string
pass =
" ";
130 void checkNUnique(std::string &name,
size_t nUniqueGids,
size_t nExpected)
132 if (nUniqueGids != nExpected)
133 std::cout <<
fail << name
134 <<
"nUniqueGids " << nUniqueGids <<
" != " << nExpected
139 template <
typename gno_t>
142 std::vector<gno_t> &gids,
144 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
147 gno_t maxGid = 0, gmaxGid = 0;
148 size_t len = gids.size();
149 for (
size_t i = 0; i < len; i++)
150 if (gids[i] > maxGid) maxGid = gids[i];
152 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MAX, 1,
154 if (gmaxGid != maxExpected)
155 std::cout <<
fail << name
156 <<
"max Gid " << gmaxGid <<
" != " << maxExpected
161 template <
typename gno_t>
164 std::vector<gno_t> &gids,
166 Teuchos::RCP<
const Teuchos::Comm<int> > &comm
169 gno_t minGid = std::numeric_limits<gno_t>::max(), gminGid;
170 size_t len = gids.size();
171 for (
size_t i = 0; i < len; i++)
172 if (gids[i] < minGid) minGid = gids[i];
174 Teuchos::reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_MIN, 1,
176 if (gminGid != minExpected)
177 std::cout <<
fail << name
178 <<
"min Gid " << gminGid <<
" != " << minExpected
183 template <
typename gno_t>
186 std::vector<gno_t> &gids,
189 size_t gidsLen = gids.size();
190 std::unordered_set<gno_t> gidsSet(gidsLen);
193 for (
size_t i = 0; i < gidsLen; i++) {
194 if (gidsSet.find(gids[i]) != gidsSet.end()) {
199 gidsSet.insert(gids[i]);
201 size_t nUnique = gidsLen - nDups;
202 if (nUnique != nExpected)
203 std::cout <<
fail << name
204 <<
"num locally unique Gids " << nUnique <<
" != " << nExpected
210 template <
typename gno_t>
211 void test1(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
217 int me = comm->getRank();
218 int np = comm->getSize();
220 std::string name = std::string(
" test1: ")
222 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
224 typedef std::array<gno_t, 1> zkey_t;
225 typedef std::vector<zkey_t> keyvec_t;
226 typedef std::vector<gno_t> gidvec_t;
228 const size_t nKeys = me+1;
229 keyvec_t keys(nKeys);
230 gidvec_t gids(nKeys);
232 for (
size_t i = 0; i < nKeys; i++) {
238 size_t nUniqueGids = findUniqueGids<zkey_t, gno_t>(keys,gids,comm);
242 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
255 template <
typename gno_t>
256 void test2(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
264 int me = comm->getRank();
265 int np = comm->getSize();
267 std::string name = std::string(
" test2: ")
269 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
271 typedef std::array<gno_t, 2> zkey_t;
272 typedef std::vector<zkey_t> keyvec_t;
273 typedef std::vector<gno_t> gidvec_t;
275 const size_t nKeys = 6;
276 const size_t nKeysHalf = 3;
277 keyvec_t keys(nKeys);
278 gidvec_t gids(nKeys);
280 for (
size_t i = 0; i < nKeysHalf; i++) {
286 for (
size_t i = 0; i < nKeysHalf; i++) {
288 k[0] =
gno_t((me+i+1)%np);
290 keys[i+nKeysHalf] = k;
293 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
297 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
307 template <
typename gno_t>
308 void test3(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
317 int me = comm->getRank();
318 int np = comm->getSize();
320 std::string name = std::string(
" test3: ")
322 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
324 typedef std::array<gno_t, 3> zkey_t;
325 typedef std::vector<zkey_t> keyvec_t;
326 typedef std::vector<gno_t> gidvec_t;
328 const size_t nKeys = 2*np;
329 const size_t nKeysHalf = np;
330 keyvec_t keys(nKeys);
331 gidvec_t gids(nKeys);
333 for (
size_t i = 0; i < nKeysHalf; i++) {
338 keys[i+nKeysHalf] = k;
340 for (
size_t i = 0; i < nKeysHalf; i++) {
348 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
358 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
371 template <
typename gno_t>
372 void test4(Teuchos::RCP<
const Teuchos::Comm<int> > &comm)
378 int me = comm->getRank();
380 std::string name = std::string(
" test4: ")
382 if (me == 0) std::cout <<
"--------\n Starting " << name << std::endl;
384 typedef std::array<gno_t, 4> zkey_t;
385 typedef std::vector<zkey_t> keyvec_t;
386 typedef std::vector<gno_t> gidvec_t;
388 const size_t nKeys = (me+1)%2;
389 keyvec_t keys(nKeys);
390 gidvec_t gids(nKeys);
392 for (
size_t i = 0; i < nKeys; i++) {
401 size_t nUniqueGids = findUniqueGids<zkey_t,gno_t>(keys,gids,comm);
405 std::cout <<
" " << name <<
" nUniqueGids " << nUniqueGids << std::endl;
418 int main(
int argc,
char *argv[])
420 Tpetra::ScopeGuard tscope(&argc, &argv);
421 Teuchos::RCP<const Teuchos::Comm<int> > comm =
422 Teuchos::DefaultComm<int>::getComm();
424 Zoltan2::test1<int>(comm);
425 Zoltan2::test2<int>(comm);
426 Zoltan2::test3<int>(comm);
427 Zoltan2::test4<int>(comm);
429 Zoltan2::test1<long long>(comm);
430 Zoltan2::test2<long long>(comm);
431 Zoltan2::test3<long long>(comm);
432 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)