24 #include "Teuchos_XMLParameterListHelpers.hpp"
26 #include <Teuchos_LAPACK.hpp>
34 #ifdef hopper_separate_test
37 #define CATCH_EXCEPTIONS_AND_RETURN(pp) \
38 catch (std::runtime_error &e) { \
39 std::cout << "Runtime exception returned from " << pp << ": " \
40 << e.what() << " FAIL" << std::endl; \
43 catch (std::logic_error &e) { \
44 std::cout << "Logic exception returned from " << pp << ": " \
45 << e.what() << " FAIL" << std::endl; \
48 catch (std::bad_alloc &e) { \
49 std::cout << "Bad_alloc exception returned from " << pp << ": " \
50 << e.what() << " FAIL" << std::endl; \
53 catch (std::exception &e) { \
54 std::cout << "Unknown exception returned from " << pp << ": " \
55 << e.what() << " FAIL" << std::endl; \
59 #define CATCH_EXCEPTIONS_WITH_COUNT(ierr, pp) \
60 catch (std::runtime_error &e) { \
61 std::cout << "Runtime exception returned from " << pp << ": " \
62 << e.what() << " FAIL" << std::endl; \
65 catch (std::logic_error &e) { \
66 std::cout << "Logic exception returned from " << pp << ": " \
67 << e.what() << " FAIL" << std::endl; \
70 catch (std::bad_alloc &e) { \
71 std::cout << "Bad_alloc exception returned from " << pp << ": " \
72 << e.what() << " FAIL" << std::endl; \
75 catch (std::exception &e) { \
76 std::cout << "Unknown exception returned from " << pp << ": " \
77 << e.what() << " FAIL" << std::endl; \
90 const string& delimiters =
" \f\n\r\t\v" )
92 return s.substr( 0, s.find_last_not_of( delimiters ) + 1 );
97 const string& delimiters =
" \f\n\r\t\v" )
99 return s.substr( s.find_first_not_of( delimiters ) );
104 const string& delimiters =
" \f\n\r\t\v" )
109 template <
typename Adapter>
113 typename Adapter::scalar_t *lower,
114 typename Adapter::scalar_t *upper,
119 std::cout <<
"boxAssign test " << str <<
": Box (";
120 for (
int j = 0; j < dim; j++) std::cout << lower[j] <<
" ";
121 std::cout <<
") x (";
122 for (
int j = 0; j < dim; j++) std::cout << upper[j] <<
" ";
125 std::cout <<
") does not overlap any parts" << std::endl;
127 std::cout <<
") overlaps parts ";
128 for (
size_t k = 0; k < nparts; k++) std::cout << parts[k] <<
" ";
129 std::cout << std::endl;
133 template <
typename Adapter>
136 RCP<tMVector_t> &coords,
142 int coordDim = coords->getNumVectors();
147 sprintf(mechar,
"%d", problem->
getComm()->getRank());
155 size_t numPoints = coords->getLocalLength();
156 for (
size_t localID = 0; localID < numPoints; localID++) {
160 for (
int i = 0; i < coordDim; i++)
161 pointDrop[i] = coords->getData(i)[localID];
164 part = problem->
getSolution().pointAssign(coordDim, pointDrop);
169 std::cout << me <<
" Point " << localID
170 <<
" gid " << coords->getMap()->getGlobalElement(localID)
171 <<
" (" << pointDrop[0];
172 if (coordDim > 1) std::cout <<
" " << pointDrop[1];
173 if (coordDim > 2) std::cout <<
" " << pointDrop[2];
174 std::cout <<
") in boxPart " << part
175 <<
" in solnPart " << solnPart
194 const std::vector<Zoltan2::coordinateModelPartBox>
195 pBoxes = problem->
getSolution().getPartBoxesView();
197 for (
size_t i = 0; i < pBoxes.size(); i++) {
200 std::cout << me <<
" pBox " << i <<
" pid " << pBoxes[i].getpId()
201 <<
" (" << lmin[0] <<
"," << lmin[1] <<
","
202 << (coordDim > 2 ? lmin[2] : 0) <<
") x "
203 <<
" (" << lmax[0] <<
"," << lmax[1] <<
","
204 << (coordDim > 2 ? lmax[2] : 0) <<
")" << std::endl;
211 for (
int i = 0; i < coordDim; i++) pointDrop[i] = 0.;
213 part = problem->
getSolution().pointAssign(coordDim, pointDrop);
217 std::cout << me <<
" OriginPoint (" << pointDrop[0];
218 if (coordDim > 1) std::cout <<
" " << pointDrop[1];
219 if (coordDim > 2) std::cout <<
" " << pointDrop[2];
220 std::cout <<
") part " << part << std::endl;
225 for (
int i = 0; i < coordDim; i++) pointDrop[i] = -100.+i;
227 part = problem->
getSolution().pointAssign(coordDim, pointDrop);
230 std::cout << me <<
" NegativePoint (" << pointDrop[0];
231 if (coordDim > 1) std::cout <<
" " << pointDrop[1];
232 if (coordDim > 2) std::cout <<
" " << pointDrop[2];
233 std::cout <<
") part " << part << std::endl;
238 for (
int i = 0; i < coordDim; i++) pointDrop[i] = i*5;
240 part = problem->
getSolution().pointAssign(coordDim, pointDrop);
243 std::cout << me <<
" i*5-Point (" << pointDrop[0];
244 if (coordDim > 1) std::cout <<
" " << pointDrop[1];
245 if (coordDim > 2) std::cout <<
" " << pointDrop[2];
246 std::cout <<
") part " << part << std::endl;
251 for (
int i = 0; i < coordDim; i++) pointDrop[i] = 10+i*5;
253 part = problem->
getSolution().pointAssign(coordDim, pointDrop);
256 std::cout << me <<
" WoopWoop-Point (" << pointDrop[0];
257 if (coordDim > 1) std::cout <<
" " << pointDrop[1];
258 if (coordDim > 2) std::cout <<
" " << pointDrop[2];
259 std::cout <<
") part " << part << std::endl;
266 template <
typename Adapter>
269 RCP<tMVector_t> &coords)
274 int coordDim = coords->getNumVectors();
279 sprintf(mechar,
"%d", problem->
getComm()->getRank());
282 const std::vector<Zoltan2::coordinateModelPartBox>
283 pBoxes = problem->
getSolution().getPartBoxesView();
284 size_t nBoxes = pBoxes.size();
290 size_t pickabox = nBoxes / 2;
291 for (
int i = 0; i < coordDim; i++) {
292 zscalar_t dd = 0.2 * (pBoxes[pickabox].getlmaxs()[i] -
293 pBoxes[pickabox].getlmins()[i]);
294 lower[i] = pBoxes[pickabox].getlmins()[i] + dd;
295 upper[i] = pBoxes[pickabox].getlmaxs()[i] - dd;
298 problem->
getSolution().boxAssign(coordDim, lower, upper,
303 std::cout << me <<
" FAIL boxAssign error: smaller test, nparts > 1"
307 print_boxAssign_result<Adapter>(
"smallerbox", coordDim,
308 lower, upper, nparts, parts);
316 size_t pickabox = nBoxes / 2;
317 for (
int i = 0; i < coordDim; i++) {
318 zscalar_t dd = 0.2 * (pBoxes[pickabox].getlmaxs()[i] -
319 pBoxes[pickabox].getlmins()[i]);
320 lower[i] = pBoxes[pickabox].getlmins()[i] - dd;
321 upper[i] = pBoxes[pickabox].getlmaxs()[i] + dd;
324 problem->
getSolution().boxAssign(coordDim, lower, upper,
330 if ((nBoxes > 1) && (nparts < 2)) {
331 std::cout << me <<
" FAIL boxAssign error: "
332 <<
"larger test, nparts < 2"
338 bool found_pickabox = 0;
339 for (
size_t i = 0; i < nparts; i++)
340 if (parts[i] == pBoxes[pickabox].getpId()) {
344 if (!found_pickabox) {
345 std::cout << me <<
" FAIL boxAssign error: "
346 <<
"larger test, pickabox not found"
351 print_boxAssign_result<Adapter>(
"largerbox", coordDim,
352 lower, upper, nparts, parts);
360 for (
int i = 0; i < coordDim; i++) {
361 lower[i] = std::numeric_limits<zscalar_t>::max();
362 upper[i] = std::numeric_limits<zscalar_t>::min();
364 for (
size_t j = 0; j < nBoxes; j++) {
365 for (
int i = 0; i < coordDim; i++) {
366 if (pBoxes[j].getlmins()[i] <= lower[i])
367 lower[i] = pBoxes[j].getlmins()[i];
368 if (pBoxes[j].getlmaxs()[i] >= upper[i])
369 upper[i] = pBoxes[j].getlmaxs()[i];
373 problem->
getSolution().boxAssign(coordDim, lower, upper,
379 if (nparts != nBoxes) {
380 std::cout << me <<
" FAIL boxAssign error: "
381 <<
"global test, nparts found " << nparts
382 <<
" != num global parts " << nBoxes
386 print_boxAssign_result<Adapter>(
"globalbox", coordDim,
387 lower, upper, nparts, parts);
397 for (
int i = 0; i < coordDim; i++) {
403 problem->
getSolution().boxAssign(coordDim, lower, upper,
409 if (nparts != nBoxes) {
410 std::cout << me <<
" FAIL boxAssign error: "
411 <<
"bigdomain test, nparts found " << nparts
412 <<
" != num global parts " << nBoxes
416 print_boxAssign_result<Adapter>(
"bigdomainbox", coordDim,
417 lower, upper, nparts, parts);
427 for (
int i = 0; i < coordDim; i++) {
428 lower[i] = upper[i] + 10;
433 problem->
getSolution().boxAssign(coordDim, lower, upper,
441 std::cout << me <<
" FAIL boxAssign error: "
442 <<
"outthere test, nparts found " << nparts
447 print_boxAssign_result<Adapter>(
"outthere box", coordDim,
448 lower, upper, nparts, parts);
457 void readGeoGenParams(
string paramFileName, Teuchos::ParameterList &geoparams,
const RCP<
const Teuchos::Comm<int> > & comm){
458 std::string input =
"";
460 for(
int i = 0; i < 25000; ++i){
465 if(comm->getRank() == 0){
467 std::fstream inParam(paramFileName.c_str());
474 std::string tmp =
"";
475 getline (inParam,tmp);
476 while (!inParam.eof()){
483 getline (inParam,tmp);
486 for (
size_t i = 0; i < input.size(); ++i){
494 int size = input.size();
498 comm->broadcast(0,
sizeof(
int), (
char*) &size);
500 throw std::runtime_error(
"File " + paramFileName +
" cannot be opened.");
502 comm->broadcast(0, size, inp);
503 std::istringstream inParam(inp);
505 getline (inParam,str);
506 while (!inParam.eof()){
508 size_t pos = str.find(
'=');
509 if(pos == string::npos){
510 throw std::runtime_error(
"Invalid Line:" + str +
" in parameter file");
512 string paramname =
trim_copy(str.substr(0,pos));
513 string paramvalue =
trim_copy(str.substr(pos + 1));
514 geoparams.set(paramname, paramvalue);
516 getline (inParam,str);
520 template<
class bv_use_node_t>
522 Teuchos::RCP<Teuchos::ParameterList> params,
524 RCP<tMVector_t> coords,
530 const int bvme = comm->getRank();
533 const size_t bvnvecs = coords->getNumVectors();
534 const size_t bvsize = coords->getNumVectors() * coords->getLocalLength();
536 ArrayRCP<inputAdapter_t::scalar_t> *bvtpetravectors =
537 new ArrayRCP<inputAdapter_t::scalar_t>[bvnvecs];
538 for (
size_t i = 0; i < bvnvecs; i++)
539 bvtpetravectors[i] = coords->getDataNonConst(i);
543 inputAdapter_t::scalar_t *bvcoordarr =
new inputAdapter_t::scalar_t[bvsize];
545 bvgids[j] = coords->getMap()->getGlobalElement(j);
546 for (
size_t i = 0; i < bvnvecs; i++) {
547 bvcoordarr[idx++] = bvtpetravectors[i][j];
555 bv_use_node_t> bvtypes_t;
557 std::vector<const inputAdapter_t::scalar_t *> bvcoords(bvnvecs);
558 std::vector<int> bvstrides(bvnvecs);
559 for (
size_t i = 0; i < bvnvecs; i++) {
560 bvcoords[i] = &bvcoordarr[i];
561 bvstrides[i] = bvnvecs;
563 std::vector<const inputAdapter_t::scalar_t *> bvwgts;
564 std::vector<int> bvwgtstrides;
566 if(numWeightsPerCoord > 0) {
567 bvwgts = std::vector<const inputAdapter_t::scalar_t *>(numWeightsPerCoord);
568 bvwgtstrides = std::vector<int>(coords->getLocalLength());
569 for (
size_t i = 0; i < coords->getLocalLength(); i++) {
570 bvwgtstrides[i] = numWeightsPerCoord;
572 for (
int i = 0; i < numWeightsPerCoord; i++) {
577 bvadapter_t bvia(bvlen, bvgids, bvcoords, bvstrides,
578 bvwgts, bvwgtstrides);
596 for (inputAdapter_t::lno_t i = 0; i < bvlen; i++) {
597 if (problem->getSolution().getPartListView()[i] !=
599 std::cout << bvme <<
" " << i <<
" "
600 << coords->getMap()->getGlobalElement(i) <<
" " << bvgids[i]
601 <<
": XMV " << problem->getSolution().getPartListView()[i]
602 <<
"; BMV " << bvproblem->
getSolution().getPartListView()[i]
603 <<
" : FAIL" << std::endl;
618 delete [] bvcoordarr;
619 delete [] bvtpetravectors;
622 if (coords->getGlobalLength() < 40) {
623 int len = coords->getLocalLength();
625 problem->getSolution().getPartListView();
626 for (
int i = 0; i < len; i++)
627 std::cout << comm->getRank()
629 <<
" gid " << coords->getMap()->getGlobalElement(i)
630 <<
" part " << zparts[i] << std::endl;
636 template<
class bv_use_node_t>
638 int numTeams,
int numParts,
float imbalance,
639 std::string paramFile, std::string pqParts,
642 int migration_check_option,
643 int migration_all_to_all_type,
645 int migration_processor_assignment_type,
646 int migration_doMigration_type,
651 int mj_premigration_option,
652 int mj_premigration_coordinate_cutoff
656 Teuchos::ParameterList geoparams(
"geo params");
668 for(
int i = 0; i < coord_dim; ++i){
669 coords[i] =
new zscalar_t[numLocalPoints];
673 if (numWeightsPerCoord) {
674 weight=
new zscalar_t * [numWeightsPerCoord];
675 for(
int i = 0; i < numWeightsPerCoord; ++i){
676 weight[i] =
new zscalar_t[numLocalPoints];
684 RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp = rcp(
685 new Tpetra::Map<zlno_t, zgno_t, znode_t>(numGlobalPoints,
686 numLocalPoints, 0, comm));
687 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(coord_dim);
688 for (
int i=0; i < coord_dim; i++){
689 if(numLocalPoints > 0){
690 Teuchos::ArrayView<const zscalar_t> a(coords[i], numLocalPoints);
694 Teuchos::ArrayView<const zscalar_t> a;
698 RCP<tMVector_t> tmVector = RCP<tMVector_t>(
new
701 std::vector<const zscalar_t *>
weights;
702 if(numWeightsPerCoord){
703 for (
int i = 0; i < numWeightsPerCoord;++i){
704 weights.push_back(weight[i]);
707 std::vector<int> stride;
711 inputAdapter_t *ia =
new inputAdapter_t(tmVector, weights, stride);
713 Teuchos::RCP<Teuchos::ParameterList> params;
717 params = Teuchos::getParametersFromXmlFile(pfname);
720 params =RCP<Teuchos::ParameterList>(
new Teuchos::ParameterList,
true);
727 params->set(
"timer_output_stream" ,
"std::cout");
729 params->set(
"algorithm",
"multijagged");
731 params->set(
"mj_keep_part_boxes",
true);
733 params->set(
"rectilinear",
true );
736 params->set(
"imbalance_tolerance",
double(imbalance));
737 params->set(
"mj_premigration_option", mj_premigration_option);
738 if (mj_premigration_coordinate_cutoff > 0){
739 params->set(
"mj_premigration_coordinate_count",
740 mj_premigration_coordinate_cutoff);
744 params->set(
"mj_parts", pqParts);
746 params->set(
"mj_num_teams", numTeams);
749 params->set(
"num_global_parts", numParts);
751 params->set(
"mj_concurrent_part_count", k);
752 if(migration_check_option >= 0)
753 params->set(
"mj_migration_option", migration_check_option);
754 if(migration_imbalance_cut_off >= 0)
755 params->set(
"mj_minimum_migration_imbalance",
756 double(migration_imbalance_cut_off));
771 ierr += compareWithBasicVectorAdapterTest<bv_use_node_t>(
772 comm, params, problem, tmVector,
773 weight, numWeightsPerCoord);
778 RCP<quality_t> metricObject =
781 if (comm->getRank() == 0){
782 metricObject->printMetrics(std::cout);
789 ierr += run_pointAssign_tests<inputAdapter_t>(problem, tmVector,
791 ierr += run_boxAssign_tests<inputAdapter_t>(problem, tmVector);
794 if(numWeightsPerCoord){
795 for(
int i = 0; i < numWeightsPerCoord; ++i) {
801 for(
int i = 0; i < coord_dim; ++i) {
812 template<
class bv_use_node_t>
814 RCP<
const Teuchos::Comm<int> > &comm,
822 int migration_check_option,
823 int migration_all_to_all_type,
825 int migration_processor_assignment_type,
826 int migration_doMigration_type,
831 int mj_premigration_option,
832 int mj_premigration_coordinate_cutoff
845 inputAdapter_t *ia =
new inputAdapter_t(coords);
847 Teuchos::RCP <Teuchos::ParameterList> params ;
851 params = Teuchos::getParametersFromXmlFile(pfname);
854 params =RCP <Teuchos::ParameterList> (
new Teuchos::ParameterList,
true);
859 params->set(
"mj_keep_part_boxes",
true);
861 params->set(
"rectilinear",
true);
862 params->set(
"algorithm",
"multijagged");
864 params->set(
"imbalance_tolerance",
double(imbalance));
868 params->set(
"mj_parts", pqParts);
870 params->set(
"mj_premigration_option", mj_premigration_option);
873 params->set(
"num_global_parts", numParts);
876 params->set(
"mj_concurrent_part_count", k);
878 if(migration_check_option >= 0){
879 params->set(
"mj_migration_option", migration_check_option);
881 if(migration_imbalance_cut_off >= 0){
882 params->set(
"mj_minimum_migration_imbalance",
883 double (migration_imbalance_cut_off));
885 if (mj_premigration_coordinate_cutoff > 0){
886 params->set(
"mj_premigration_coordinate_count",
887 mj_premigration_coordinate_cutoff);
902 ierr += compareWithBasicVectorAdapterTest<bv_use_node_t>(
903 comm, params, problem, coords);
908 RCP<quality_t> metricObject =
911 if (comm->getRank() == 0){
912 metricObject->printMetrics(std::cout);
913 std::cout <<
"testFromDataFile is done " << std::endl;
920 ierr += run_pointAssign_tests<inputAdapter_t>(problem, coords,
922 ierr += run_boxAssign_tests<inputAdapter_t>(problem, coords);
930 #ifdef hopper_separate_test
932 template <
typename zscalar_t,
typename zlno_t>
934 FILE *f = fopen(fileName.c_str(),
"r");
936 std::cout << fileName <<
" cannot be opened" << std::endl;
939 fscanf(f,
"%d", &numLocal);
940 fscanf(f,
"%d", &dim);
942 for (
int i = 0; i < dim; ++i){
945 for (
int i = 0; i < dim; ++i){
946 for (
zlno_t j = 0; j < numLocal; ++j){
947 fscanf(f,
"%lf", &(coords[i][j]));
951 std::cout <<
"done reading:" << fileName << std::endl;
954 int testFromSeparateDataFiles(
955 RCP<
const Teuchos::Comm<int> > &comm,
963 int migration_check_option,
964 int migration_all_to_all_type,
966 int migration_processor_assignment_type,
967 int migration_doMigration_type,
971 int mj_premigration_option
978 int mR = comm->getRank();
979 if (mR == 0) std::cout <<
"size of zscalar_t:" <<
sizeof(
zscalar_t) << std::endl;
980 string tFile = fname +
"_" + std::to_string(mR) +
".mtx";
984 getCoords<zscalar_t, zlno_t>(double_coords, numLocal, dim, tFile);
986 Teuchos::Array<Teuchos::ArrayView<const zscalar_t> > coordView(dim);
987 for (
int i=0; i < dim; i++){
989 Teuchos::ArrayView<const zscalar_t> a(double_coords[i], numLocal);
992 Teuchos::ArrayView<const zscalar_t> a;
999 Teuchos::Comm<int> *tcomm = (Teuchos::Comm<int> *)comm.getRawPtr();
1001 reduceAll<int, zgno_t>(
1003 Teuchos::REDUCE_SUM,
1010 RCP<Tpetra::Map<zlno_t, zgno_t, znode_t> > mp = rcp(
1011 new Tpetra::Map<zlno_t, zgno_t, znode_t> (numGlobal, numLocal, 0, comm));
1012 RCP< Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> >coords = RCP< Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t> >(
1013 new Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>( mp, coordView.view(0, dim), dim));
1016 RCP<const tMVector_t> coordsConst = rcp_const_cast<
const tMVector_t>(coords);
1021 inputAdapter_t *ia =
new inputAdapter_t(coordsConst);
1025 Teuchos::RCP <Teuchos::ParameterList> params ;
1029 params = Teuchos::getParametersFromXmlFile(pfname);
1032 params =RCP <Teuchos::ParameterList> (
new Teuchos::ParameterList,
true);
1036 params->set(
"algorithm",
"multijagged");
1038 params->set(
"imbalance_tolerance",
double(imbalance));
1041 params->set(
"mj_premigration_option", mj_premigration_option);
1043 params->set(
"mj_parts", pqParts);
1046 params->set(
"mj_num_teams", numTeams);
1049 params->set(
"num_global_parts", numParts);
1052 params->set(
"parallel_part_calculation_count", k);
1054 if(migration_processor_assignment_type >= 0){
1055 params->set(
"migration_processor_assignment_type", migration_processor_assignment_type);
1057 if(migration_check_option >= 0){
1058 params->set(
"migration_check_option", migration_check_option);
1060 if(migration_all_to_all_type >= 0){
1061 params->set(
"migration_all_to_all_type", migration_all_to_all_type);
1063 if(migration_imbalance_cut_off >= 0){
1064 params->set(
"migration_imbalance_cut_off",
1065 double (migration_imbalance_cut_off));
1067 if (migration_doMigration_type >= 0){
1068 params->set(
"migration_doMigration_type",
int (migration_doMigration_type));
1071 params->set(
"mj_keep_part_boxes",
true);
1073 params->set(
"rectilinear",
true);
1089 ierr += compareWithBasicVectorAdapterTest<bv_use_node_t>(
1090 comm, params, problem, coords);
1093 if (coordsConst->getGlobalLength() < 40) {
1094 int len = coordsConst->getLocalLength();
1097 for (
int i = 0; i < len; i++)
1098 std::cout << comm->getRank()
1099 <<
" gid " << coords->getMap()->getGlobalElement(i)
1100 <<
" part " << zparts[i] << std::endl;
1105 RCP<quality_t> metricObject =
1108 if (comm->getRank() == 0){
1109 metricObject->printMetrics(std::cout);
1110 std::cout <<
"testFromDataFile is done " << std::endl;
1117 ierr += run_pointAssign_tests<inputAdapter_t>(problem, coords,
1119 ierr += run_boxAssign_tests<inputAdapter_t>(problem, coords);
1132 for(
int i = 0; args[i] != 0; i++)
1137 std::stringstream stream(std::stringstream::in | std::stringstream::out);
1138 stream << argumentline;
1139 getline(stream, argumentid,
'=');
1143 stream >> argumentValue;
1156 std::string &pfname,
1158 int &migration_check_option,
1159 int &migration_all_to_all_type,
1161 int &migration_processor_assignment_type,
1162 int &migration_doMigration_type,
1164 bool &print_details,
1167 int &mj_premigration_option,
1168 int &mj_coordinate_cutoff
1171 bool isCset =
false;
1172 bool isPset =
false;
1173 bool isFset =
false;
1174 bool isPFset =
false;
1176 for(
int i = 0; i < narg; ++i){
1178 string identifier =
"";
1179 long long int value = -1;
double fval = -1;
1181 value = (
long long int) (fval);
1183 if(identifier ==
"W"){
1184 if(value == 0 || value == 1){
1185 print_details = (value == 0 ?
false :
true);
1187 throw std::runtime_error(
"Invalid argument at " + tmp);
1190 else if(identifier ==
"UVM"){
1191 if(value == 0 || value == 1){
1192 uvm = (value == 0 ?
false :
true);
1194 throw std::runtime_error(
"Invalid argument at " + tmp);
1197 else if(identifier ==
"T"){
1201 throw std::runtime_error(
"Invalid argument at " + tmp);
1203 }
else if(identifier ==
"C"){
1208 throw std::runtime_error(
"Invalid argument at " + tmp);
1210 }
else if(identifier ==
"P"){
1211 std::stringstream stream(std::stringstream::in | std::stringstream::out);
1214 getline(stream, ttmp,
'=');
1217 }
else if(identifier ==
"I"){
1221 throw std::runtime_error(
"Invalid argument at " + tmp);
1223 }
else if(identifier ==
"MI"){
1225 migration_imbalance_cut_off=fval;
1227 throw std::runtime_error(
"Invalid argument at " + tmp);
1229 }
else if(identifier ==
"MO"){
1231 migration_check_option = value;
1233 throw std::runtime_error(
"Invalid argument at " + tmp);
1235 }
else if(identifier ==
"AT"){
1237 migration_processor_assignment_type = value;
1239 throw std::runtime_error(
"Invalid argument at " + tmp);
1243 else if(identifier ==
"MT"){
1245 migration_all_to_all_type = value;
1247 throw std::runtime_error(
"Invalid argument at " + tmp);
1250 else if(identifier ==
"PCC"){
1252 mj_coordinate_cutoff = value;
1254 throw std::runtime_error(
"Invalid argument at " + tmp);
1258 else if(identifier ==
"PM"){
1260 mj_premigration_option = value;
1262 throw std::runtime_error(
"Invalid argument at " + tmp);
1266 else if(identifier ==
"DM"){
1268 migration_doMigration_type = value;
1270 throw std::runtime_error(
"Invalid argument at " + tmp);
1273 else if(identifier ==
"F"){
1274 std::stringstream stream(std::stringstream::in | std::stringstream::out);
1276 getline(stream, fname,
'=');
1281 else if(identifier ==
"PF"){
1282 std::stringstream stream(std::stringstream::in | std::stringstream::out);
1284 getline(stream, pfname,
'=');
1290 else if(identifier ==
"O"){
1291 if(value >= 0 && value <= 3){
1294 throw std::runtime_error(
"Invalid argument at " + tmp);
1297 else if(identifier ==
"K"){
1301 throw std::runtime_error(
"Invalid argument at " + tmp);
1304 else if(identifier ==
"TB"){
1306 test_boxes = (value == 0 ?
false :
true);
1308 throw std::runtime_error(
"Invalid argument at " + tmp);
1311 else if(identifier ==
"R"){
1313 rectilinear = (value == 0 ?
false :
true);
1315 throw std::runtime_error(
"Invalid argument at " + tmp);
1319 throw std::runtime_error(
"Invalid argument at " + tmp);
1323 if(!( (isCset || isPset || isPFset) && isFset)){
1324 throw std::runtime_error(
"(C || P || PF) && F are mandatory arguments.");
1330 std::cout <<
"\nUsage:" << std::endl;
1331 std::cout << executable <<
" arglist" << std::endl;
1332 std::cout <<
"arglist:" << std::endl;
1333 std::cout <<
"\tT=numTeams: numTeams > 0" << std::endl;
1334 std::cout <<
"\tC=numParts: numParts > 0" << std::endl;
1335 std::cout <<
"\tP=MultiJaggedPart: Example: P=512,512" << std::endl;
1336 std::cout <<
"\tI=imbalance: Example I=1.03 (ignored for now.)" << std::endl;
1337 std::cout <<
"\tF=filePath: When O=0 the path of the coordinate input file, for O>1 the path to the geometric generator parameter file." << std::endl;
1338 std::cout <<
"\tO=input option: O=0 for reading coordinate from file, O>0 for generating coordinate from coordinate generator file. Default will run geometric generator." << std::endl;
1339 std::cout <<
"\tK=concurrent part calculation input: K>0." << std::endl;
1340 std::cout <<
"\tMI=migration_imbalance_cut_off: MI=1.35. " << std::endl;
1341 std::cout <<
"\tMT=migration_all_to_all_type: 0 for alltoallv, 1 for Zoltan_Comm, 2 for Zoltan2 Distributor object(Default 1)." << std::endl;
1342 std::cout <<
"\tMO=migration_check_option: 0 for decision on imbalance, 1 for forcing migration, >1 for avoiding migration. (Default-0)" << std::endl;
1343 std::cout <<
"\tAT=migration_processor_assignment_type. 0-for assigning procs with respect to proc ownment, otherwise, assignment with respect to proc closeness." << std::endl;
1344 std::cout <<
"Example:\n" << executable <<
" P=2,2,2 C=8 F=simple O=0" << std::endl;
1349 Tpetra::ScopeGuard tscope(&narg, &arg);
1350 Teuchos::RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
1352 int rank = tcomm->getRank();
1357 float imbalance = -1.03;
1360 string pqParts =
"";
1362 std::string fname =
"";
1363 std::string paramFile =
"";
1366 int migration_check_option = -2;
1367 int migration_all_to_all_type = -1;
1368 zscalar_t migration_imbalance_cut_off = -1.15;
1369 int migration_processor_assignment_type = -1;
1370 int migration_doMigration_type = -1;
1371 int mj_premigration_option = 0;
1372 int mj_premigration_coordinate_cutoff = 0;
1375 bool print_details =
true;
1376 bool test_boxes =
false;
1377 bool rectilinear =
false;
1386 #if defined(KOKKOS_ENABLE_CUDA)
1387 using uvm_off_node_t = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
1388 Kokkos::Cuda, Kokkos::CudaSpace>;
1389 #elif defined(KOKKOS_ENABLE_HIP)
1390 using uvm_off_node_t = Tpetra::KokkosCompat::KokkosDeviceWrapperNode<
1391 Kokkos::HIP, Kokkos::HIPSpace>;
1407 migration_check_option,
1408 migration_all_to_all_type,
1409 migration_imbalance_cut_off,
1410 migration_processor_assignment_type,
1411 migration_doMigration_type,
1416 mj_premigration_option, mj_premigration_coordinate_cutoff);
1418 catch(std::exception &s){
1419 if(tcomm->getRank() == 0){
1431 ierr = testFromDataFile<znode_t>(tcomm, numTeams, numParts,
1432 imbalance,
fname, pqParts, paramFile, k,
1433 migration_check_option,
1434 migration_all_to_all_type,
1435 migration_imbalance_cut_off,
1436 migration_processor_assignment_type,
1437 migration_doMigration_type, uvm, print_details, test_boxes,
1439 mj_premigration_option, mj_premigration_coordinate_cutoff);
1442 #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)
1443 ierr = testFromDataFile<uvm_off_node_t>(tcomm, numTeams, numParts,
1444 imbalance,
fname, pqParts, paramFile, k,
1445 migration_check_option,
1446 migration_all_to_all_type,
1447 migration_imbalance_cut_off,
1448 migration_processor_assignment_type,
1449 migration_doMigration_type, uvm, print_details, test_boxes,
1451 mj_premigration_option, mj_premigration_coordinate_cutoff);
1453 throw std::logic_error(
"uvm set off but this is not a cuda/hip test.");
1458 #ifdef hopper_separate_test
1462 ierr = testFromSeparateDataFiles(tcomm, numTeams, numParts,
1463 imbalance, fname, pqParts, paramFile, k,
1464 migration_check_option,
1465 migration_all_to_all_type,
1466 migration_imbalance_cut_off,
1467 migration_processor_assignment_type,
1468 migration_doMigration_type,uvm, print_details, test_boxes,
1470 mj_premigration_option, mj_premigration_coordinate_cutoff);
1475 ierr = GeometricGenInterface<znode_t>(tcomm, numTeams, numParts,
1476 imbalance,
fname, pqParts, paramFile, k,
1477 migration_check_option,
1478 migration_all_to_all_type,
1479 migration_imbalance_cut_off,
1480 migration_processor_assignment_type,
1481 migration_doMigration_type, uvm, print_details, test_boxes,
1483 mj_premigration_option, mj_premigration_coordinate_cutoff);
1486 #if defined(KOKKOS_ENABLE_CUDA) || defined(KOKKOS_ENABLE_HIP)
1487 ierr = GeometricGenInterface<uvm_off_node_t>(tcomm, numTeams,
1488 numParts, imbalance,
fname, pqParts, paramFile, k,
1489 migration_check_option,
1490 migration_all_to_all_type,
1491 migration_imbalance_cut_off,
1492 migration_processor_assignment_type,
1493 migration_doMigration_type, uvm, print_details, test_boxes,
1495 mj_premigration_option, mj_premigration_coordinate_cutoff);
1497 throw std::logic_error(
"uvm set off but this is not a cuda test.");
1504 if (ierr == 0) std::cout <<
"PASS" << std::endl;
1505 else std::cout <<
"FAIL" << std::endl;
1510 catch(std::string &s){
1512 std::cerr << s << std::endl;
1517 std::cerr << s << std::endl;
void getCoords(void *data, int numGid, int numLid, int numObj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int dim, double *coords_, int *ierr)
int compareWithBasicVectorAdapterTest(RCP< const Teuchos::Comm< int > > &comm, Teuchos::RCP< Teuchos::ParameterList > params, Zoltan2::PartitioningProblem< Zoltan2::XpetraMultiVectorAdapter< tMVector_t >> *problem, RCP< tMVector_t > coords, Zoltan2::XpetraMultiVectorAdapter< tMVector_t >::scalar_t **weights=NULL, int numWeightsPerCoord=0)
#define CATCH_EXCEPTIONS_WITH_COUNT(ierr, pp)
void getLocalCoordinatesCopy(scalar_t **c)
typename InputTraits< User >::scalar_t scalar_t
string trim_right_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
void print_usage(char *executable)
int GeometricGenInterface(RCP< const Teuchos::Comm< int > > &comm, int numTeams, int numParts, float imbalance, std::string paramFile, std::string pqParts, std::string pfname, int k, int migration_check_option, int migration_all_to_all_type, zscalar_t migration_imbalance_cut_off, int migration_processor_assignment_type, int migration_doMigration_type, bool uvm, bool print_details, bool test_boxes, bool rectilinear, int mj_premigration_option, int mj_premigration_coordinate_cutoff)
void readGeoGenParams(string paramFileName, Teuchos::ParameterList &geoparams, const RCP< const Teuchos::Comm< int > > &comm)
map_t::global_ordinal_type gno_t
A simple class that can be the User template argument for an InputAdapter.
int getCoordinateDimension()
Zoltan2::EvaluatePartition< matrixAdapter_t > quality_t
int main(int narg, char **arg)
Defines the PartitioningSolution class.
common code used by tests
void print_boxAssign_result(const char *str, int dim, typename Adapter::scalar_t *lower, typename Adapter::scalar_t *upper, size_t nparts, typename Adapter::part_t *parts)
Defines the XpetraMultiVectorAdapter.
string trim_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
SparseMatrixAdapter_t::part_t part_t
int testFromDataFile(RCP< const Teuchos::Comm< int > > &comm, int numTeams, int numParts, float imbalance, std::string fname, std::string pqParts, std::string pfname, int k, int migration_check_option, int migration_all_to_all_type, zscalar_t migration_imbalance_cut_off, int migration_processor_assignment_type, int migration_doMigration_type, bool uvm, bool print_details, bool test_boxes, bool rectilinear, int mj_premigration_option, int mj_premigration_coordinate_cutoff)
Defines the EvaluatePartition class.
int run_boxAssign_tests(Zoltan2::PartitioningProblem< Adapter > *problem, RCP< tMVector_t > &coords)
RCP< const Comm< int > > getComm()
Return the communicator used by the problem.
BasicVectorAdapter represents a vector (plus optional weights) supplied by the user as pointers to st...
map_t::local_ordinal_type lno_t
void printTimers() const
Return the communicator passed to the problem.
An adapter for Xpetra::MultiVector.
#define CATCH_EXCEPTIONS_AND_RETURN(pp)
void getArgVals(int narg, char **arg, int &numTeams, int &numParts, float &imbalance, string &pqParts, int &opt, std::string &fname, std::string &pfname, int &k, int &migration_check_option, int &migration_all_to_all_type, zscalar_t &migration_imbalance_cut_off, int &migration_processor_assignment_type, int &migration_doMigration_type, bool &uvm, bool &print_details, bool &test_boxes, bool &rectilinear, int &mj_premigration_option, int &mj_coordinate_cutoff)
Tpetra::Map::local_ordinal_type zlno_t
int run_pointAssign_tests(Zoltan2::PartitioningProblem< Adapter > *problem, RCP< tMVector_t > &coords, bool print_details)
static const std::string fail
string convert_to_string(char *args)
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
string trim_left_copy(const string &s, const string &delimiters=" \f\n\r\t\v")
int getNumWeights()
##END Predistribution functions######################//
bool getArgumentValue(string &argumentid, double &argumentValue, string argumentline)
lno_t getNumLocalCoords()
Defines the PartitioningProblem class.
A class that computes and returns quality metrics.
gno_t getNumGlobalCoords()
Defines the BasicVectorAdapter class.
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t
Tpetra::Map::global_ordinal_type zgno_t
void solve(bool updateInputData=true)
Direct the problem to create a solution.
void getLocalWeightsCopy(scalar_t **w)
std::string testDataFilePath(".")