11 #include "Tpetra_Core.hpp"
49 typedef int test_lid_t;
50 typedef int test_gid_t;
57 directory_t directory(comm,
false, 0);
62 std::vector<test_gid_t> writeGIDs;
64 if(comm->getRank() == 0) {
65 writeGIDs = { 1, 5, 7, 10 };
73 std::vector<user_t> writeUser;
74 if(comm->getRank() == 0) {
75 writeUser = { 10, 50, 70, 100 };
82 directory.update(writeGIDs.size(), &writeGIDs[0], NULL, &writeUser[0], NULL,
86 std::vector<test_gid_t> findIds = { 3, 5 };
92 std::vector<user_t> findUser(findIds.size());
103 directory.find(findIds.size(), &findIds[0], NULL, &findUser[0], NULL, NULL);
107 if(findUser[0] != 30) {
108 std::cout <<
"We should have gotten 30 for this value." << std::endl;
113 if(findUser[1] != 50) {
114 std::cout <<
"We should have gotten 50 for this value." << std::endl;
118 catch(std::logic_error &e) {
119 if(comm->getSize() != 1) {
123 std::cout <<
"Successfully detected throw since find failed." << std::endl;
132 std::vector<test_gid_t> writeGIDs2;
134 if(comm->getRank() == 0) {
135 writeGIDs2 = { 5, 700, 1000 };
138 writeGIDs2 = { 3, 200 };
141 std::vector<user_t> writeUser2;
142 if(comm->getRank() == 0) {
143 writeUser2 = { 50, 7000, 10000 };
146 writeUser2 = { 30, 2000 };
150 directory.update(writeGIDs2.size(), &writeGIDs2[0], NULL, &writeUser2[0], NULL,
154 std::vector<test_gid_t> findIds2 = { 1, 5, 1000 };
157 std::vector<user_t> findUser2(findIds2.size());
158 directory.find(findIds2.size(), &findIds2[0], NULL, &findUser2[0], NULL, NULL);
164 if(findUser2[0] != 10) {
165 std::cout <<
"We should have gotten 10 for this value. " << std::endl;
168 if(findUser2[1] != 50) {
169 std::cout <<
"We should have gotten 50 for this value." << std::endl;
174 if(findUser2[2] != 10000) {
175 std::cout <<
"We should have gotten 10000 for this value." << std::endl;
188 typedef int test_lid_t;
189 typedef long test_gid_t;
190 typedef std::vector<long long>
user_t;
200 directory_t directory(comm,
false, 0);
203 std::vector<test_gid_t> writeGIDs;
204 switch(comm->getRank()) {
206 writeGIDs = { 3, 5 };
209 writeGIDs = { 3, 7 };
218 std::vector<user_t> writeUser;
219 switch(comm->getRank()) {
221 writeUser = { {1,2}, {4,8,10} };
224 writeUser = { {2,10}, {6,8} };
227 writeUser = { {1,2,10} };
232 directory.update(writeGIDs.size(), &writeGIDs[0], NULL, &writeUser[0], NULL,
236 std::vector<test_gid_t> findIds = { 3, 5 };
244 std::vector<user_t> findUser(findIds.size());
247 directory.find(findIds.size(), &findIds[0], NULL, &findUser[0], NULL, NULL);
257 user_t expectedValue0 =
258 (comm->getSize() == 1) ?
user_t({1,2}) :
user_t({1,2,10});
259 if(findUser[0] != expectedValue0) {
260 std::cout <<
"findUser[0] did not match expected." << std::endl;
272 user_t expectedValue1 =
273 (comm->getSize() <= 2) ?
user_t({4,8,10}) :
user_t({1,2,4,8,10});
274 if(findUser[1] != expectedValue1) {
275 std::cout <<
"findUser[1] did not match expected." << std::endl;
288 typedef int test_lid_t;
297 directory_t directory(comm,
false, 0);
301 std::vector<test_gid_t> writeGIDs;
302 test_gid_t gid1(1, 8, 7, 3);
303 test_gid_t gid2(1, 8, 7, 4);
306 if(comm->getRank() == 0) {
307 writeGIDs = { gid1, gid2 };
310 writeGIDs = { gid2 };
318 std::vector<user_t> writeUser;
319 if(comm->getRank() == 0) {
320 writeUser = { 1, 1 };
327 directory.update(writeGIDs.size(), &writeGIDs[0], NULL, &writeUser[0], NULL,
331 std::vector<test_gid_t> findIds = { gid1, gid2 };
337 std::vector<user_t> findUser(findIds.size());
340 directory.find(findIds.size(), &findIds[0], NULL, &findUser[0], NULL, NULL);
343 if(findUser[0] != 1) {
344 std::cout <<
"We should have gotten 1 for gid1. Only rank 0 wrote to gid1"
345 " so the sum should have been 1." << std::endl;
351 if(findUser[1] != comm->getSize()) {
352 std::cout <<
"We should have gotten the proc count " << comm->getSize()
353 <<
" since every rank wrote to gid2." << std::endl;
377 directory_t directory(comm,
true, 0);
381 std::vector<test_gid_t> writeGIDs;
382 test_gid_t gid1(1, 8, 7, 3);
383 test_gid_t gid2(1, 8, 7, 4);
387 std::vector<test_lid_t> writeLIDs;
388 test_lid_t lid1(500, 2009);
389 test_lid_t lid2(500, 8000);
392 if(comm->getRank() == 0) {
393 writeGIDs = { gid1, gid2 };
394 writeLIDs = { lid1, lid2 };
397 writeGIDs = { gid2 };
398 writeLIDs = { lid2 };
401 std::vector<user_t> writeUser;
402 if(comm->getRank() == 0) {
403 writeUser = { 1, 1 };
410 directory.update(writeGIDs.size(), &writeGIDs[0], &writeLIDs[0], &writeUser[0],
414 std::vector<test_gid_t> findGIDs = { gid1, gid2 };
417 std::vector<test_lid_t> findLIDs(findGIDs.size());
420 directory.find(findGIDs.size(), &findGIDs[0], &findLIDs[0], NULL, NULL, NULL);
423 if(findLIDs[0].val[0] != lid1.val[0] || findLIDs[0].val[1] != lid1.val[1]) {
424 std::cout <<
"We should have gotten [500,2009] for lid1." << std::endl;
429 if(findLIDs[1].val[0] != lid2.val[0] || findLIDs[1].val[1] != lid2.val[1]) {
430 std::cout <<
"We should have gotten [500,8000] for lid1." << std::endl;
435 std::vector<user_t> findUser(findGIDs.size());
438 directory.find(findGIDs.size(), &findGIDs[0], &findLIDs[0], &findUser[0],
442 if(findUser[0] != 1) {
443 std::cout <<
"We should have gotten 1 for gid1. Only rank 0 wrote to gid1"
444 " so the sum should have been 1." << std::endl;
450 if(findUser[1] != 1) {
451 std::cout <<
"We should have gotten the proc count " << comm->getSize()
452 <<
" since every rank wrote to gid2." << std::endl;
459 int main(
int narg,
char **arg) {
460 Tpetra::ScopeGuard tscope(&narg, &arg);
461 Teuchos::RCP<const Teuchos::Comm<int> > comm =
462 Teuchos::DefaultComm<int>::getComm();
475 Teuchos::reduceAll<int>(*comm,Teuchos::REDUCE_SUM, err,
476 Teuchos::outArg(errGlobal));
480 if(comm->getRank() == 0) {
482 std::cout <<
"Passed" << std::endl;
485 std::cout <<
"FAILED!" << std::endl;
int test_multiple_lid(Teuchos::RCP< const Teuchos::Comm< int > > comm)
int main(int narg, char **arg)
lid_struct(unsigned long v0, unsigned long v1)
int test_multiple_gid(Teuchos::RCP< const Teuchos::Comm< int > > comm)
gid_struct(int v0, int v1, int v2, int v3)
int test_simple_replace(Teuchos::RCP< const Teuchos::Comm< int > > comm)
int test_aggregate(Teuchos::RCP< const Teuchos::Comm< int > > comm)
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t