46 #include <Teuchos_RCP.hpp>
47 #include <Teuchos_ArrayView.hpp>
71 #define GID_SET_LENGTH 3 // arbitrary for testing
77 #define LID_SET_LENGTH 4 // just to mix things up - make it different than gid
85 Teuchos::RCP<
const Teuchos::Comm<int> > comm,
bool only_rank0 =
true) {
86 for(
int proc = 0; proc < comm->getSize(); ++proc) {
88 if(proc == comm->getRank() && (!only_rank0 || proc == 0)) {
89 std::cout << message << std::endl;
98 #define NOT_FOUND_VALUE -1 // easier to tell it's the unset value as -1
127 template <
typename g
id_t,
typename l
id_t,
typename user_t>
147 IDs(
size_t totalIds_,
size_t idBase_,
size_t idStride_,
148 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
149 const std::string& test_name_,
bool print_detailed_output_,
150 bool performance_test_,
bool bUseLocalIDs_) :
163 if(
comm->getRank() == 0) {
165 std::cout <<
"Sub1: " << std::endl;
166 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
167 std::cout <<
" rank " << proc <<
": ";
168 for(
size_t n = 0; n <
totalIds; ++n) {
171 std::cout << std::endl;
175 std::cout <<
"Sub2: " << std::endl;
176 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
177 std::cout <<
" rank " << proc <<
": ";
178 for(
size_t n = 0; n <
totalIds; ++n) {
181 std::cout << std::endl;
185 std::cout <<
"update: " << std::endl;
186 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
187 std::cout <<
" rank " << proc <<
": ";
188 for(
size_t n = 0; n <
totalIds; ++n) {
191 std::cout << std::endl;
195 std::cout <<
"remove: " << std::endl;
196 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
197 std::cout <<
" rank " << proc <<
": ";
198 for(
size_t n = 0; n <
totalIds; ++n) {
201 std::cout << std::endl;
205 std::cout <<
"find: " << std::endl;
206 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
207 std::cout <<
" rank " << proc <<
": ";
208 for(
size_t n = 0; n <
totalIds; ++n) {
211 std::cout << std::endl;
220 std::string message = pass ?
221 " Passed: " + base_message :
222 " FAILED: " + base_message +
" on rank " +
223 std::to_string(
comm->getRank());
252 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
254 if(proc ==
comm->getRank()) {
256 std::cout << std::endl <<
258 <<
" ############" << std::endl;
260 std::cout <<
"Rank: " << proc << std::endl;
275 if(proc ==
comm->getSize()-1) {
276 std::cout << std::endl;
289 default:
throw std::logic_error(
"Bad mode.");
break;
295 return ((index %
comm->getSize()) == rank);
300 return ((index % (
comm->getSize()+1)) == rank);
305 return ((index % (
comm->getSize()+3)) == rank);
344 int test_duplicate_count = 2;
346 return (index < 100) ? test_duplicate_count : 1;
359 int test_duplicate_count = 2;
361 return (index < 100) ? test_duplicate_count : 1;
391 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
404 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
417 void print_gids(
const std::vector<gid_t> &printIds, std::string name)
const {
418 std::cout <<
" " << printIds.size() <<
" " << name <<
": ";
419 for (
size_t i = 0; i < printIds.size() && i <
maxPrintSize; i++) {
425 std::cout << std::endl;
430 void print_lids(
const std::vector<lid_t> &printIds, std::string name)
const {
431 std::cout <<
" " << printIds.size() <<
" " << name <<
": ";
432 for (
size_t i = 0; i < printIds.size() && i <
maxPrintSize; i++) {
438 std::cout << std::endl;
446 std::cout <<
"Find LIDs ";
447 for(
size_t n = 0; n < this->
find_gids.size(); ++n) {
451 std::cout << std::endl;
468 virtual bool check_lid_equal(
const lid_t & a,
const lid_t & b)
const = 0;
510 throw std::logic_error(
511 "setup already called - execute once in highest level class only.");
519 for(
size_t n = 0; n <
totalIds; ++n) {
521 bool bAtLeastOne =
false;
522 for(
int proc = 0; proc <
comm->getSize(); ++proc) {
528 throw std::logic_error(
"The proc_update_gid method must generate an"
529 " algorithm which returns true for at least 1 proce for all IDs. If"
530 " this is changed then the findID algorithm should not return true"
531 " for any of those missing IDs. This is a sanity check.");
538 for(
size_t n = 0; n <
totalIds; ++n) {
544 for(
int i = 0; i < count_proc_update_gid; ++i) {
573 virtual void test() = 0;
575 template<
typename directory_t>
577 const int debug_level = 0;
583 directory_t zz2(zz1);
584 directory_t zz = zz2;
687 template <
typename g
id_t,
typename l
id_t,
typename user_t>
699 return "(" + std::to_string(gid) +
")";
703 return "(" + std::to_string(lid) +
")";
733 template <
typename g
id_t,
typename l
id_t,
typename user_t>
738 gid_length(gid_length_), lid_length(lid_length_) {
747 for(
size_t n = 0; n < lid_length; ++n) {
754 std::string output_string =
"(";
755 for(
size_t n = 0; n < gid_length; ++n) {
756 if(n!=0) output_string +=
" ";
757 output_string += std::to_string(gid.sub_gid[n]);
759 output_string +=
")";
760 return output_string;
764 std::string output_string =
"(";
765 for(
size_t n = 0; n < lid_length; ++n) {
766 if(n!=0) output_string +=
" ";
767 output_string += std::to_string(lid.sub_lid[n]);
769 output_string +=
")";
770 return output_string;
774 for(
size_t n = 0; n < lid_length; ++n) {
775 if(a.sub_lid[n] != b.sub_lid[n]) {
783 return gid.sub_gid[0];
790 return (gid.sub_gid[0]-this->idBase)/this->
idStride;
800 for(
size_t n = 0; n < gid_length; ++n) {
801 gid.sub_gid[n] = val + n;
808 for(
size_t n = 0; n < lid_length; ++n) {
809 result.sub_lid[n] = n + gid.sub_gid[0] + 1;
825 template <
typename g
id_t,
typename l
id_t,
typename user_t>
835 this->
template test_implement<directory_t>();
851 throw std::logic_error(
"Unexpected aggregate mode for non array.");
854 throw std::logic_error(
"Unexpected mode index.");
876 throw std::logic_error(
"Aggregate requested for non array setup.");
879 throw std::logic_error(
"Unexpected mode index.");
888 for(
int proc = 0; proc < this->
comm->getSize(); ++proc) {
889 bool passRank =
true;
890 this->
comm->barrier();
891 if(proc == this->
comm->getRank()) {
892 for(
size_t i = 0; i < this->
find_gids.size(); ++i) {
903 " but got value: " << this->
find_user[i] <<
904 " when we expected to read the unset value of " <<
906 "Remove FAILED." << std::endl;
911 if(this->
find_user[i] != expected_value) {
913 std::cout <<
"Failed read user data for global ID: " <<
915 expected_value <<
" Got data: " <<
920 const lid_t & find_lid = this->
find_lids[i];
924 std::cout <<
"Failed read lid for global ID: " <<
938 std::cout <<
"Checked rank: " << this->
comm->getRank() <<
939 " with nIds: " << this->
find_gids.size() <<
" which " <<
940 "FAILED" << std::endl;
948 this->
comm->barrier();
954 std::cout <<
"Write GID user data ";
955 for(
size_t n = 0; n < this->
update_gids.size(); ++n) {
959 std::cout << std::endl;
961 std::cout <<
"Find GID user data ";
962 for(
size_t n = 0; n < this->
find_gids.size(); ++n) {
966 std::cout << std::endl;
976 template <
typename g
id_t,
typename l
id_t,
typename user_t>
986 this->
template test_implement<directory_t>();
996 return user_t(test_create_array_length(gid, this->comm->getRank()),
997 this->sharedCount(gid));
1000 return get_initial_user(gid, this->comm->getRank());
1007 for(
int proc = 0; proc < this->comm->getSize(); ++proc) {
1008 if(this->proc_update_gid(gid, proc)) {
1009 user_t proc_input = get_initial_user(gid, proc);
1010 for(
size_t i = 0; i < proc_input.size(); ++i) {
1011 auto val = proc_input[i];
1012 if(final_aggregated.size() == 0 ||
1013 val > final_aggregated[final_aggregated.size()-1]) {
1015 final_aggregated.push_back(val);
1018 for(
auto itr = final_aggregated.begin();
1019 itr != final_aggregated.end(); ++itr) {
1023 else if((*itr) > val) {
1024 final_aggregated.insert(itr, val);
1032 return final_aggregated;
1036 throw std::logic_error(
"Unexpected mode index.");
1043 size_t modLength = test_create_array_length(gid, rank);
1045 for(
size_t n = 0; n < array.size(); ++n) {
1046 switch(this->mode) {
1048 array[n] = this->gid_seed_value(gid) + 3;
1059 array[n] = n + rank*2;
1062 throw std::logic_error(
"Unexpected mode index.");
1073 for(
int proc = 0; proc < this->comm->getSize(); ++proc) {
1074 bool passRank =
true;
1075 this->comm->barrier();
1076 if(proc == this->comm->getRank()) {
1077 for(
size_t i = 0; i < this->find_gids.size(); ++i) {
1078 gid_t gid = this->find_gids[i];
1084 if(this->removedIDGlobally(gid)) {
1086 if(this->find_user[i].size() != 1 ||
1089 std::cout <<
"Removed array for gid: " <<
1090 this->gid_to_string(gid) <<
1091 " but something set the user data which is incorrect. "
1092 "Remove FAILED." << std::endl;
1096 user_t expected_value = get_expected_user(gid);
1098 if(this->find_user[i].size() != expected_value.size()) {
1099 std::cout <<
" Rank: " << proc <<
" array size is incorrect for"
1100 " gid: " << this->gid_to_string(gid) <<
". Expected size: " <<
1101 expected_value.size() <<
" and got size: " <<
1102 this->find_user[i].size() << std::endl;
1109 if(this->bUseLocalIDs) {
1110 const lid_t & find_lid = this->find_lids[i];
1111 lid_t expected_lid = this->get_initial_lid(gid);
1112 if(!this->check_lid_equal(find_lid, expected_lid)) {
1114 std::cout <<
"Failed read lid for global ID: " <<
1115 this->gid_to_string(gid) <<
". Expected lid: " <<
1116 this->lid_to_string(expected_lid) <<
" Got lid: " <<
1117 this->lid_to_string(find_lid) << std::endl;
1122 for(
size_t arrayIndex = 0; arrayIndex < this->find_user[i].size()
1123 && passRank; ++arrayIndex) {
1124 if(this->find_user[i][arrayIndex] != expected_value[arrayIndex]) {
1126 std::cout <<
" Failed vector read for global ID: " <<
1127 this->gid_to_string(gid)
1128 <<
". Expected: " << expected_value[arrayIndex] <<
1129 " at array index " << arrayIndex <<
". Got: " <<
1130 this->find_user[i][arrayIndex] << std::endl;
1141 std::cout <<
" Checked rank: " << this->comm->getRank() <<
1142 " with num find gids: " << this->find_gids.size() <<
" which " <<
1143 "FAILED" << std::endl;
1151 this->comm->barrier();
1157 for(
size_t n = 0; n < this->update_gids.size(); ++n) {
1158 std::cout <<
" Write array for GID " <<
1159 this->gid_to_string(this->update_gids[n]) <<
": ";
1160 for(
size_t a = 0; a < this->update_user[n].size(); ++a) {
1161 std::cout << this->update_user[n][a] <<
" ";
1163 std::cout << std::endl;
1165 for(
size_t n = 0; n < this->find_gids.size(); ++n) {
1166 std::cout <<
" Read array for GID " <<
1167 this->gid_to_string(this->find_gids[n]) <<
": ";
1168 for(
size_t a = 0; a < this->find_user[n].size(); ++a) {
1169 std::cout << this->find_user[n][a] <<
" ";
1171 std::cout << std::endl;
1176 switch(this->mode) {
1186 return (this->gid_seed_value(gid)%7);
1191 return (this->gid_seed_value(gid)%7);
1196 return (this->gid_seed_value(gid)%7)+proc;
1199 throw std::logic_error(
"test_create_array_length bad mode.");
1208 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1214 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1215 const std::string& name_,
bool print_detailed_output_,
1216 bool performance_test_,
bool bUseLocalIDs_) :
1217 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1218 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1225 return "Single_User_Single_GID";
1233 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1239 size_t totalIds_,
size_t idBase_,
size_t idStride_,
1240 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1241 const std::string& name_,
bool print_detailed_output_,
1242 bool performance_test_,
bool bUseLocalIDs_) :
1243 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1244 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1251 return "Single_User_Multiple_GID";
1259 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1265 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1266 const std::string& name_,
bool print_detailed_output_,
1267 bool performance_test_,
bool bUseLocalIDs_) :
1268 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1269 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1276 return "Vector_User_Single_GID";
1284 template <
typename g
id_t,
typename l
id_t,
typename user_t>
1290 size_t totalIds_,
size_t idBase_,
size_t idStride_,
1291 Teuchos::RCP<
const Teuchos::Comm<int> > &comm_,
int mode_,
1292 const std::string& name_,
bool print_detailed_output_,
1293 bool performance_test_,
bool bUseLocalIDs_) :
1294 IDs<gid_t, lid_t,
user_t>(totalIds_, idBase_, idStride_, comm_, mode_,
1295 name_, print_detailed_output_, performance_test_, bUseLocalIDs_),
1302 return "Vector_User_Multiple_GID";
1321 TestManager(Teuchos::RCP<
const Teuchos::Comm<int> > comm_,
int totalIds_,
1322 bool print_detailed_output_,
bool performance_test_,
bool bUseLocalIDs_) :
1323 comm(comm_), totalIds(totalIds_), all_pass(true),
1324 print_detailed_output(print_detailed_output_),
1325 performance_test(performance_test_), bUseLocalIDs(bUseLocalIDs_) {
1329 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1331 int mode_,
size_t idBase_,
int idStride_) {
1333 idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1334 performance_test, bUseLocalIDs);
1339 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1341 const std::string& name_,
int mode_,
size_t idBase_,
int idStride_) {
1343 totalIds, idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1344 performance_test, bUseLocalIDs);
1349 template<
typename g
id_t,
typename l
id_t,
typename user_t>
1351 int mode_,
size_t idBase_,
int idStride_) {
1353 idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1354 performance_test, bUseLocalIDs);
1359 template<
typename g
id_t,
typename l
id_t,
typename user_t >
1361 const std::string& name_,
int mode_,
size_t idBase_,
int idStride_) {
1363 totalIds, idBase_, idStride_, comm, mode_, name_, print_detailed_output,
1364 performance_test, bUseLocalIDs);
1371 Teuchos::RCP<const Teuchos::Comm<int> > comm;
1374 bool print_detailed_output;
1375 bool performance_test;
1392 Tpetra::ScopeGuard tscope(&narg, &arg);
1393 Teuchos::RCP<const Teuchos::Comm<int> > comm =
1394 Teuchos::DefaultComm<int>::getComm();
1399 std::vector<size_t> run_with_totalIds = {0, 1, 2, 3, 5, 27, 63, 456, 1093};
1407 const bool print_output =
false;
1408 const bool performance_test =
false;
1410 for(
int run_with_local_ids = 0; run_with_local_ids <= 1; ++run_with_local_ids) {
1412 for(
size_t n = 0; n < run_with_totalIds.size(); ++n) {
1414 print_proc_safe(
"Testing totalIds: " + std::to_string(run_with_totalIds[n]),
1419 TestManager manager(comm, run_with_totalIds[n], print_output,
1420 performance_test, run_with_local_ids ?
true :
false);
1426 for(
int test_mode = 0; test_mode <
TestMode_Max; ++test_mode) {
1430 (
"contiguous int", test_mode, 0, 1);
1432 (
"non-contiguous int", test_mode, 20, 3);
1435 (
"long long", test_mode, 200, 4);
1465 Teuchos::reduceAll<int>(*comm,Teuchos::REDUCE_SUM, err,
1466 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