10 #include <Teuchos_RCP.hpp>
11 #include <Teuchos_ArrayView.hpp>
35 #define GID_SET_LENGTH 3 // arbitrary for testing
41 #define LID_SET_LENGTH 4 // just to mix things up - make it different than gid
49 Teuchos::RCP<
const Teuchos::Comm<int> > comm,
bool only_rank0 =
true) {
50 for(
int proc = 0; proc < comm->getSize(); ++proc) {
52 if(proc == comm->getRank() && (!only_rank0 || proc == 0)) {
53 std::cout << message << std::endl;
62 #define NOT_FOUND_VALUE -1 // easier to tell it's the unset value as -1
91 template <
typename g
id_t,
typename l
id_t,
typename user_t>
111 IDs(
size_t totalIds_,
size_t idBase_,
size_t idStride_,
112 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
113 const std::string& test_name_,
bool print_detailed_output_,
114 bool performance_test_,
bool bUseLocalIDs_) :
127 if(
comm->getRank() == 0) {
129 std::cout <<
"Sub1: " << std::endl;
130 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
131 std::cout <<
" rank " << proc <<
": ";
132 for(
size_t n = 0; n <
totalIds; ++n) {
135 std::cout << std::endl;
139 std::cout <<
"Sub2: " << std::endl;
140 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
141 std::cout <<
" rank " << proc <<
": ";
142 for(
size_t n = 0; n <
totalIds; ++n) {
145 std::cout << std::endl;
149 std::cout <<
"update: " << std::endl;
150 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
151 std::cout <<
" rank " << proc <<
": ";
152 for(
size_t n = 0; n <
totalIds; ++n) {
155 std::cout << std::endl;
159 std::cout <<
"remove: " << std::endl;
160 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
161 std::cout <<
" rank " << proc <<
": ";
162 for(
size_t n = 0; n <
totalIds; ++n) {
165 std::cout << std::endl;
169 std::cout <<
"find: " << std::endl;
170 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
171 std::cout <<
" rank " << proc <<
": ";
172 for(
size_t n = 0; n <
totalIds; ++n) {
175 std::cout << std::endl;
184 std::string message = pass ?
185 " Passed: " + base_message :
186 " FAILED: " + base_message +
" on rank " +
187 std::to_string(
comm->getRank());
216 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
218 if(proc ==
comm->getRank()) {
220 std::cout << std::endl <<
222 <<
" ############" << std::endl;
224 std::cout <<
"Rank: " << proc << std::endl;
239 if(proc ==
comm->getSize()-1) {
240 std::cout << std::endl;
253 default:
throw std::logic_error(
"Bad mode.");
break;
259 return ((index %
comm->getSize()) == rank);
264 return ((index % (
comm->getSize()+1)) == rank);
269 return ((index % (
comm->getSize()+3)) == rank);
308 int test_duplicate_count = 2;
310 return (index < 100) ? test_duplicate_count : 1;
323 int test_duplicate_count = 2;
325 return (index < 100) ? test_duplicate_count : 1;
355 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
368 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
381 void print_gids(
const std::vector<gid_t> &printIds, std::string name)
const {
382 std::cout <<
" " << printIds.size() <<
" " << name <<
": ";
383 for (
size_t i = 0; i < printIds.size() && i <
maxPrintSize; i++) {
389 std::cout << std::endl;
394 void print_lids(
const std::vector<lid_t> &printIds, std::string name)
const {
395 std::cout <<
" " << printIds.size() <<
" " << name <<
": ";
396 for (
size_t i = 0; i < printIds.size() && i <
maxPrintSize; i++) {
402 std::cout << std::endl;
410 std::cout <<
"Find LIDs ";
411 for(
size_t n = 0; n < this->
find_gids.size(); ++n) {
415 std::cout << std::endl;
432 virtual bool check_lid_equal(
const lid_t & a,
const lid_t & b)
const = 0;
474 throw std::logic_error(
475 "setup already called - execute once in highest level class only.");
483 for(
size_t n = 0; n <
totalIds; ++n) {
485 bool bAtLeastOne =
false;
486 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
492 throw std::logic_error(
"The proc_update_gid method must generate an"
493 " algorithm which returns true for at least 1 proce for all IDs. If"
494 " this is changed then the findID algorithm should not return true"
495 " for any of those missing IDs. This is a sanity check.");
502 for(
size_t n = 0; n <
totalIds; ++n) {
508 for(
int i = 0; i < count_proc_update_gid; ++i) {
537 virtual void test() = 0;
539 template<
typename directory_t>
541 const int debug_level = 0;
547 directory_t zz2(zz1);
548 directory_t zz = zz2;
651 template <
typename g
id_t,
typename l
id_t,
typename user_t>
663 return "(" + std::to_string(gid) +
")";
667 return "(" + std::to_string(lid) +
")";
697 template <
typename g
id_t,
typename l
id_t,
typename user_t>
702 gid_length(gid_length_), lid_length(lid_length_) {
711 for(
size_t n = 0; n < lid_length; ++n) {
718 std::string output_string =
"(";
719 for(
size_t n = 0; n < gid_length; ++n) {
720 if(n!=0) output_string +=
" ";
721 output_string += std::to_string(gid.sub_gid[n]);
723 output_string +=
")";
724 return output_string;
728 std::string output_string =
"(";
729 for(
size_t n = 0; n < lid_length; ++n) {
730 if(n!=0) output_string +=
" ";
731 output_string += std::to_string(lid.sub_lid[n]);
733 output_string +=
")";
734 return output_string;
738 for(
size_t n = 0; n < lid_length; ++n) {
739 if(a.sub_lid[n] != b.sub_lid[n]) {
747 return gid.sub_gid[0];
754 return (gid.sub_gid[0]-this->idBase)/this->
idStride;
764 for(
size_t n = 0; n < gid_length; ++n) {
765 gid.sub_gid[n] = val + n;
772 for(
size_t n = 0; n < lid_length; ++n) {
773 result.sub_lid[n] = n + gid.sub_gid[0] + 1;
789 template <
typename g
id_t,
typename l
id_t,
typename user_t>
799 this->
template test_implement<directory_t>();
815 throw std::logic_error(
"Unexpected aggregate mode for non array.");
818 throw std::logic_error(
"Unexpected mode index.");
840 throw std::logic_error(
"Aggregate requested for non array setup.");
843 throw std::logic_error(
"Unexpected mode index.");
852 for(
int proc = 0; proc < this->
comm->getSize(); ++proc) {
853 bool passRank =
true;
854 this->
comm->barrier();
855 if(proc == this->
comm->getRank()) {
856 for(
size_t i = 0; i < this->
find_gids.size(); ++i) {
867 " but got value: " << this->
find_user[i] <<
868 " when we expected to read the unset value of " <<
870 "Remove FAILED." << std::endl;
875 if(this->
find_user[i] != expected_value) {
877 std::cout <<
"Failed read user data for global ID: " <<
879 expected_value <<
" Got data: " <<
884 const lid_t & find_lid = this->
find_lids[i];
888 std::cout <<
"Failed read lid for global ID: " <<
902 std::cout <<
"Checked rank: " << this->
comm->getRank() <<
903 " with nIds: " << this->
find_gids.size() <<
" which " <<
904 "FAILED" << std::endl;
912 this->
comm->barrier();
918 std::cout <<
"Write GID user data ";
919 for(
size_t n = 0; n < this->
update_gids.size(); ++n) {
923 std::cout << std::endl;
925 std::cout <<
"Find GID user data ";
926 for(
size_t n = 0; n < this->
find_gids.size(); ++n) {
930 std::cout << std::endl;
940 template <
typename g
id_t,
typename l
id_t,
typename user_t>
950 this->
template test_implement<directory_t>();
960 return user_t(test_create_array_length(gid, this->comm->getRank()),
961 this->sharedCount(gid));
964 return get_initial_user(gid, this->comm->getRank());
971 for(
int proc = 0; proc < this->comm->getSize(); ++proc) {
972 if(this->proc_update_gid(gid, proc)) {
973 user_t proc_input = get_initial_user(gid, proc);
974 for(
size_t i = 0; i < proc_input.size(); ++i) {
975 auto val = proc_input[i];
976 if(final_aggregated.size() == 0 ||
977 val > final_aggregated[final_aggregated.size()-1]) {
979 final_aggregated.push_back(val);
982 for(
auto itr = final_aggregated.begin();
983 itr != final_aggregated.end(); ++itr) {
987 else if((*itr) > val) {
988 final_aggregated.insert(itr, val);
996 return final_aggregated;
1000 throw std::logic_error(
"Unexpected mode index.");
1007 size_t modLength = test_create_array_length(gid, rank);
1009 for(
size_t n = 0; n < array.size(); ++n) {
1010 switch(this->mode) {
1012 array[n] = this->gid_seed_value(gid) + 3;
1023 array[n] = n + rank*2;
1026 throw std::logic_error(
"Unexpected mode index.");
1037 for(
int proc = 0; proc < this->comm->getSize(); ++proc) {
1038 bool passRank =
true;
1039 this->comm->barrier();
1040 if(proc == this->comm->getRank()) {
1041 for(
size_t i = 0; i < this->find_gids.size(); ++i) {
1042 gid_t gid = this->find_gids[i];
1048 if(this->removedIDGlobally(gid)) {
1050 if(this->find_user[i].size() != 1 ||
1053 std::cout <<
"Removed array for gid: " <<
1054 this->gid_to_string(gid) <<
1055 " but something set the user data which is incorrect. "
1056 "Remove FAILED." << std::endl;
1060 user_t expected_value = get_expected_user(gid);
1062 if(this->find_user[i].size() != expected_value.size()) {
1063 std::cout <<
" Rank: " << proc <<
" array size is incorrect for"
1064 " gid: " << this->gid_to_string(gid) <<
". Expected size: " <<
1065 expected_value.size() <<
" and got size: " <<
1066 this->find_user[i].size() << std::endl;
1073 if(this->bUseLocalIDs) {
1074 const lid_t & find_lid = this->find_lids[i];
1075 lid_t expected_lid = this->get_initial_lid(gid);
1076 if(!this->check_lid_equal(find_lid, expected_lid)) {
1078 std::cout <<
"Failed read lid for global ID: " <<
1079 this->gid_to_string(gid) <<
". Expected lid: " <<
1080 this->lid_to_string(expected_lid) <<
" Got lid: " <<
1081 this->lid_to_string(find_lid) << std::endl;
1086 for(
size_t arrayIndex = 0; arrayIndex < this->find_user[i].size()
1087 && passRank; ++arrayIndex) {
1088 if(this->find_user[i][arrayIndex] != expected_value[arrayIndex]) {
1090 std::cout <<
" Failed vector read for global ID: " <<
1091 this->gid_to_string(gid)
1092 <<
". Expected: " << expected_value[arrayIndex] <<
1093 " at array index " << arrayIndex <<
". Got: " <<
1094 this->find_user[i][arrayIndex] << std::endl;
1105 std::cout <<
" Checked rank: " << this->comm->getRank() <<
1106 " with num find gids: " << this->find_gids.size() <<
" which " <<
1107 "FAILED" << std::endl;
1115 this->comm->barrier();
1121 for(
size_t n = 0; n < this->update_gids.size(); ++n) {
1122 std::cout <<
" Write array for GID " <<
1123 this->gid_to_string(this->update_gids[n]) <<
": ";
1124 for(
size_t a = 0; a < this->update_user[n].size(); ++a) {
1125 std::cout << this->update_user[n][a] <<
" ";
1127 std::cout << std::endl;
1129 for(
size_t n = 0; n < this->find_gids.size(); ++n) {
1130 std::cout <<
" Read array for GID " <<
1131 this->gid_to_string(this->find_gids[n]) <<
": ";
1132 for(
size_t a = 0; a < this->find_user[n].size(); ++a) {
1133 std::cout << this->find_user[n][a] <<
" ";
1135 std::cout << std::endl;
1140 switch(this->mode) {
1150 return (this->gid_seed_value(gid)%7);
1155 return (this->gid_seed_value(gid)%7);
1160 return (this->gid_seed_value(gid)%7)+proc;
1163 throw std::logic_error(
"test_create_array_length bad mode.");
1172 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1178 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1179 const std::string& name_,
bool print_detailed_output_,
1180 bool performance_test_,
bool bUseLocalIDs_) :
1181 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1182 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1189 return "Single_User_Single_GID";
1197 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1203 size_t totalIds_,
size_t idBase_,
size_t idStride_,
1204 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1205 const std::string& name_,
bool print_detailed_output_,
1206 bool performance_test_,
bool bUseLocalIDs_) :
1207 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1208 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1215 return "Single_User_Multiple_GID";
1223 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1229 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1230 const std::string& name_,
bool print_detailed_output_,
1231 bool performance_test_,
bool bUseLocalIDs_) :
1232 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1233 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1240 return "Vector_User_Single_GID";
1248 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1254 size_t totalIds_,
size_t idBase_,
size_t idStride_,
1255 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1256 const std::string& name_,
bool print_detailed_output_,
1257 bool performance_test_,
bool bUseLocalIDs_) :
1258 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1259 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1266 return "Vector_User_Multiple_GID";
1285 TestManager(Teuchos::RCP<
const Teuchos::Comm<int> > comm_,
int totalIds_,
1286 bool print_detailed_output_,
bool performance_test_,
bool bUseLocalIDs_) :
1287 comm(comm_), totalIds(totalIds_), all_pass(true),
1288 print_detailed_output(print_detailed_output_),
1289 performance_test(performance_test_), bUseLocalIDs(bUseLocalIDs_) {
1293 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1295 int mode_,
size_t idBase_,
int idStride_) {
1297 idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1298 performance_test, bUseLocalIDs);
1303 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1305 const std::string& name_,
int mode_,
size_t idBase_,
int idStride_) {
1307 totalIds, idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1308 performance_test, bUseLocalIDs);
1313 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1315 int mode_,
size_t idBase_,
int idStride_) {
1317 idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1318 performance_test, bUseLocalIDs);
1323 template<
typename g
id_t,
typename l
id_t,
typename user_t >
1325 const std::string& name_,
int mode_,
size_t idBase_,
int idStride_) {
1327 totalIds, idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1328 performance_test, bUseLocalIDs);
1335 Teuchos::RCP<const Teuchos::Comm<int> > comm;
1338 bool print_detailed_output;
1339 bool performance_test;
1356 Tpetra::ScopeGuard tscope(&narg, &arg);
1357 Teuchos::RCP<const Teuchos::Comm<int> > comm =
1358 Teuchos::DefaultComm<int>::getComm();
1363 std::vector<size_t> run_with_totalIds = {0, 1, 2, 3, 5, 27, 63, 456, 1093};
1371 const bool print_output =
false;
1372 const bool performance_test =
false;
1374 for(
int run_with_local_ids = 0; run_with_local_ids <= 1; ++run_with_local_ids) {
1376 for(
size_t n = 0; n < run_with_totalIds.size(); ++n) {
1378 print_proc_safe(
"Testing totalIds: " + std::to_string(run_with_totalIds[n]),
1383 TestManager manager(comm, run_with_totalIds[n], print_output,
1384 performance_test, run_with_local_ids ?
true :
false);
1390 for(
int test_mode = 0; test_mode <
TestMode_Max; ++test_mode) {
1394 (
"contiguous int", test_mode, 0, 1);
1396 (
"non-contiguous int", test_mode, 20, 3);
1399 (
"long long", test_mode, 200, 4);
1429 Teuchos::reduceAll<int>(*comm,Teuchos::REDUCE_SUM, err,
1430 Teuchos::outArg(errGlobal));
virtual user_t get_initial_user(gid_t gid, int rank) const
virtual std::string lid_to_string(lid_t lid) const
int sharedCount(gid_t gid) const
Vector_User_Multiple_GID(size_t gid_length_, size_t lid_length_, size_t totalIds_, size_t idBase_, size_t idStride_, Teuchos::RCP< const Teuchos::Comm< int > > &comm_, int mode_, const std::string &name_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
virtual bool check_lid_equal(const lid_t &a, const lid_t &b) const =0
virtual lid_t get_not_found_lid() const
virtual size_t gid_seed_value(const gid_t &gid) const
void print() const
detailed notes on update IDs, find IDs, etc
bool did_test_pass() const
did_test_pass - did test pass
virtual std::string gid_to_string(gid_t gid) const
virtual lid_t get_initial_lid(gid_t gid) const =0
virtual void initialize_with_not_found_user()
bool removedIDGlobally(gid_t gid) const
virtual size_t test_create_array_length(gid_t gid, int proc) const
void print_proc_safe(const std::string &message, Teuchos::RCP< const Teuchos::Comm< int > > comm, bool only_rank0=true)
virtual lid_t get_initial_lid(gid_t gid) const
virtual bool check_lid_equal(const lid_t &a, const lid_t &b) const
virtual lid_t get_not_found_lid() const =0
virtual void initialize_with_not_found_lid()
virtual user_t get_initial_user(gid_t gid, int rank) const =0
virtual std::string gid_to_string(gid_t gid) const
bool trueForAtLeastOneProc(int index, int rank) const
std::vector< gid_t > update_gids
virtual bool check_lid_equal(const lid_t &a, const lid_t &b) const
virtual user_t get_expected_user(gid_t gid) const =0
virtual int convert_gid_to_index(const gid_t &gid) const
virtual std::string get_test_style() const
get_test_style the test is either vector user_t or single user_t the test is either multiple gids or ...
bool did_all_pass() const
bool print_detailed_output
int getMode() const
getMode - Replace, Add, or Aggregate
virtual std::string get_test_style() const =0
get_test_style the test is either vector user_t or single user_t the test is either multiple gids or ...
std::vector< lid_t > find_lids
virtual std::string get_test_style() const
get_test_style the test is either vector user_t or single user_t the test is either multiple gids or ...
virtual bool evaluateTests() const =0
evaluateTests - determine if test worked
int proc_update_gid(gid_t gid, int rank) const
virtual void print_lid_data() const
virtual user_t get_not_found_user() const
void run_vector_user_multiple_gid(size_t gid_length_, size_t lid_length_, const std::string &name_, int mode_, size_t idBase_, int idStride_)
Vector_User_Single_GID(size_t totalIds_, size_t idBase_, size_t idStride_, Teuchos::RCP< const Teuchos::Comm< int > > &comm_, int mode_, const std::string &name_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
virtual void print_user_data() const =0
virtual void print_user_data() const
virtual user_t get_expected_user(gid_t gid) const
Teuchos::RCP< const Teuchos::Comm< int > > comm
bool subset1(int index, int rank) const
virtual size_t gid_seed_value(const gid_t &gid) const
Multiple_GID(size_t gid_length_, size_t lid_length_)
virtual gid_t convert_index_to_gid(int index) const
void print_lids(const std::vector< lid_t > &printIds, std::string name) const
std::vector< gid_t > remove_gids
static const std::string pass
int proc_find_gid(gid_t gid, int rank) const
virtual void debug_print_subsets_and_decisions()
virtual bool evaluateTests() const
evaluateTests - determine if test worked
virtual std::string gid_to_string(gid_t gid) const =0
void run_vector_user_single_gid(const std::string &name_, int mode_, size_t idBase_, int idStride_)
int sub_lid[LID_SET_LENGTH]
virtual int convert_gid_to_index(const gid_t &gid) const
std::vector< gid_t > find_gids
virtual std::string get_test_style() const
get_test_style the test is either vector user_t or single user_t the test is either multiple gids or ...
Single_User_Single_GID(size_t totalIds_, size_t idBase_, size_t idStride_, Teuchos::RCP< const Teuchos::Comm< int > > &comm_, int mode_, const std::string &name_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
int runDirectoryTests(int narg, char **arg)
virtual user_t get_not_found_user() const =0
virtual std::string lid_to_string(lid_t lid) const
virtual gid_t convert_index_to_gid(int index) const
virtual size_t gid_seed_value(const gid_t &gid) const =0
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
virtual lid_t get_not_found_lid() const
virtual user_t get_not_found_user() const
int proc_remove_gid(gid_t gid, int rank) const
IDs(size_t totalIds_, size_t idBase_, size_t idStride_, Teuchos::RCP< const Teuchos::Comm< int > > &comm_, int mode_, const std::string &test_name_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
Construct IDs.
void run_single_user_single_gid(const std::string &name_, int mode_, size_t idBase_, int idStride_)
void printResultMessage(bool pass) const
virtual bool evaluateTests() const
evaluateTests - determine if test worked
virtual int convert_gid_to_index(const gid_t &gid) const =0
virtual std::string get_test_style() const
get_test_style the test is either vector user_t or single user_t the test is either multiple gids or ...
virtual gid_t convert_index_to_gid(int index) const =0
virtual lid_t get_initial_lid(gid_t gid) const
void print_gids(const std::vector< gid_t > &printIds, std::string name) const
TestManager(Teuchos::RCP< const Teuchos::Comm< int > > comm_, int totalIds_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
std::vector< lid_t > update_lids
int sub_gid[GID_SET_LENGTH]
std::vector< user_t > find_user
std::vector< user_t > update_user
std::string get_mode_name() const
virtual void print_user_data() const
virtual user_t get_expected_user(gid_t gid) const
void run_single_user_multiple_gid(size_t gid_length_, size_t lid_length_, const std::string &name_, int mode_, size_t idBase_, int idStride_)
virtual std::string lid_to_string(lid_t lid) const =0
const std::string & get_test_name() const
virtual user_t get_initial_user(gid_t gid, int rank) const
Single_User_Multiple_GID(size_t gid_length_, size_t lid_length_, size_t totalIds_, size_t idBase_, size_t idStride_, Teuchos::RCP< const Teuchos::Comm< int > > &comm_, int mode_, const std::string &name_, bool print_detailed_output_, bool performance_test_, bool bUseLocalIDs_)
bool subset2(int index, int rank) const
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t