45 #include <Teuchos_Comm.hpp> 46 #include <Teuchos_ParameterList.hpp> 47 #include <Teuchos_FilteredIterator.hpp> 48 #include <Teuchos_ParameterEntry.hpp> 57 #include <Tpetra_MultiVector_decl.hpp> 60 #include <Teuchos_ArrayViewDecl.hpp> 63 const std::string
shapes[] = {
"SQUARE",
"RECTANGLE",
"CIRCLE",
"CUBE",
"RECTANGULAR_PRISM",
"SPHERE"};
68 #define DISTRIBUTION_COUNT 2 70 #define HOLE_ALLOC_STEP 10 71 #define MAX_WEIGHT_DIM 10 72 #define INVALID(STR) "Invalid argument at " + STR 73 #define INVALIDSHAPE(STR, DIM) "Invalid shape name " + STR + " for " + DIM + ".\nValid shapes are \"SQUARE\", \"RECTANGLE\", \"CIRCLE\" for 2D, and \"CUBE\", \"RECTANGULAR_PRISM\", \"SPHERE\" for 3D" 75 #define INVALID_SHAPE_ARG(SHAPE, REQUIRED) "Invalid argument count for shape " + SHAPE + ". Requires " + REQUIRED + " argument(s)." 76 #define MAX_ITER_ALLOWED 500 113 template <
typename T>
119 this->center.
x = center_.
x;
120 this->center.
y = center_.
y;
121 this->center.
z = center_.
z;
122 this->edge1 = edge1_;
123 this->edge2 = edge2_;
124 this->edge3 = edge3_;
130 template <
typename T>
136 return fabs(dot.
x - this->center.x) < this->edge1 / 2 && fabs(dot.
y - this->center.y) < this->edge1 / 2;
140 template <
typename T>
145 return fabs(dot.
x - this->center.x) < this->edge1 / 2 && fabs(dot.
y - this->center.y) < this->edge2 / 2;
150 template <
typename T>
156 return (dot.
x - this->center.x)*(dot.
x - this->center.x) + (dot.
y - this->center.y) * (dot.
y - this->center.y) < this->edge1 * this->edge1;
160 template <
typename T>
166 return fabs(dot.
x - this->center.x) < this->edge1 / 2 && fabs(dot.
y - this->center.y) < this->edge1 / 2 && fabs(dot.
z - this->center.z) < this->edge1 / 2;
170 template <
typename T>
176 return fabs(dot.
x - this->center.x) < this->edge1 / 2 && fabs(dot.
y - this->center.y) < this->edge2 / 2 && fabs(dot.
z - this->center.z) < this->edge3 / 2;
180 template <
typename T>
186 return fabs((dot.
x - this->center.x) * (dot.
x - this->center.x) * (dot.
x - this->center.x)) +
187 fabs((dot.
y - this->center.y) * (dot.
y - this->center.y) * (dot.
y - this->center.y)) +
188 fabs((dot.
z - this->center.z) * (dot.
z - this->center.z) * (dot.
z - this->center.z))
190 this->edge1 * this->edge1 * this->edge1;
194 template <
typename T,
typename weighttype>
198 virtual weighttype get1DWeight(T
x)=0;
199 virtual weighttype get2DWeight(T x, T
y)=0;
200 virtual weighttype get3DWeight(T x, T y, T
z)=0;
223 template <
typename T,
typename weighttype>
234 SteppedEquation(T a1_, T a2_, T a3_, T b1_, T b2_, T b3_, T c_, T x1_, T y1_, T z1_, T *steps_, T *values_,
int stepCount_):
WeightDistribution<T,weighttype>(){
247 this->stepCount = stepCount_;
248 if(this->stepCount > 0){
249 this->steps =
new T[this->stepCount];
250 this->values =
new T[this->stepCount + 1];
252 for (
int i = 0; i < this->stepCount; ++i){
253 this->steps[i] = steps_[i];
254 this->values[i] = values_[i];
256 this->values[this->stepCount] = values_[this->stepCount];
262 if(this->stepCount > 0){
263 delete [] this->steps;
264 delete [] this->values;
270 T expressionRes = this->a1 * pow( (x - this->x1), b1) + c;
271 if(this->stepCount > 0){
272 for (
int i = 0; i < this->stepCount; ++i){
273 if (expressionRes < this->steps[i])
return this->values[i];
275 return this->values[this->stepCount];
278 return weighttype(expressionRes);
283 T expressionRes = this->a1 * pow( (x - this->x1), b1) + this->a2 * pow( (y - this->y1), b2) + c;
284 if(this->stepCount > 0){
285 for (
int i = 0; i < this->stepCount; ++i){
286 if (expressionRes < this->steps[i])
return this->values[i];
288 return this->values[this->stepCount];
291 return weighttype(expressionRes);
296 cout << this->a1 <<
"*" <<
"math.pow( (" << x <<
"- " << this->x1 <<
" ), " << b1 <<
")" <<
"+" << this->a2<<
"*"<<
"math.pow( (" << y <<
"-" << this->y1 <<
"), " <<
297 b2 <<
" ) + " << this->a3 <<
" * math.pow( (" << z <<
"-" << this->z1 <<
"), " << b3 <<
")+ " << c <<
" == " <<
298 this->a1 * pow( (x - this->x1), b1) + this->a2 * pow( (y - this->y1), b2) + this->a3 * pow( (z - this->z1), b3) + c << endl;
303 T expressionRes = this->a1 * pow( (x - this->x1), b1) + this->a2 * pow( (y - this->y1), b2) + this->a3 * pow( (z - this->z1), b3) + this->c;
306 if(this->stepCount > 0){
307 for (
int i = 0; i < this->stepCount; ++i){
308 if (expressionRes < this->steps[i]) {
310 return this->values[i];
315 return this->values[this->stepCount];
318 return weighttype(expressionRes);
323 T expressionRes = this->a1 * pow( (p.
x - this->x1), b1) + this->a2 * pow( (p.
y - this->y1), b2) + this->a3 * pow( (p.
z - this->z1), b3);
324 if(this->stepCount > 0){
325 for (
int i = 0; i < this->stepCount; ++i){
326 if (expressionRes < this->steps[i])
return this->values[i];
328 return this->values[this->stepCount];
331 return weighttype(expressionRes);
336 template <
typename T,
typename lno_t,
typename gno_t>
347 numPoints(np_), dimension(dim), requested(0), assignedPrevious(0),
351 virtual T getXCenter() = 0;
352 virtual T getXRadius() =0;
356 float *sharedRatios_,
int myRank){
358 for (
int i = 0; i < myRank; ++i){
360 this->assignedPrevious +=
lno_t(sharedRatios_[i] * this->numPoints);
361 if (i < this->numPoints % this->worldSize){
362 this->assignedPrevious += 1;
366 this->requested = requestedPointcount;
368 unsigned int slice = UINT_MAX/(this->worldSize);
369 unsigned int stateBegin = myRank * slice;
374 #ifdef HAVE_ZOLTAN2_OMP 380 #ifdef HAVE_ZOLTAN2_OMP 381 me = omp_get_thread_num();
382 tsize = omp_get_num_threads();
384 unsigned int state = stateBegin + me * slice/(tsize);
386 #ifdef HAVE_ZOLTAN2_OMP 389 for(
lno_t cnt = 0; cnt < requestedPointcount; ++cnt){
393 throw "Max number of Iteration is reached for point creation. Check the area criteria or hole coordinates.";
397 bool isInHole =
false;
398 for(
lno_t i = 0; i < holeCount; ++i){
399 if(holes[i][0].isInArea(p)){
404 if(isInHole)
continue;
445 float *sharedRatios_,
int myRank){
447 for (
int i = 0; i < myRank; ++i){
449 this->assignedPrevious +=
lno_t(sharedRatios_[i] * this->numPoints);
450 if (i < this->numPoints % this->worldSize){
451 this->assignedPrevious += 1;
455 this->requested = requestedPointcount;
457 unsigned int slice = UINT_MAX/(this->worldSize);
458 unsigned int stateBegin = myRank * slice;
459 #ifdef HAVE_ZOLTAN2_OMP 465 #ifdef HAVE_ZOLTAN2_OMP 466 me = omp_get_thread_num();
467 tsize = omp_get_num_threads();
469 unsigned int state = stateBegin + me * (slice/(tsize));
477 #ifdef HAVE_ZOLTAN2_OMP 480 for(
lno_t cnt = 0; cnt < requestedPointcount; ++cnt){
484 throw "Max number of Iteration is reached for point creation. Check the area criteria or hole coordinates.";
488 bool isInHole =
false;
489 for(
lno_t i = 0; i < holeCount; ++i){
490 if(holes[i][0].isInArea(p)){
495 if(isInHole)
continue;
496 coords[0][cnt + tindex] = p.
x;
497 if(this->dimension > 1){
498 coords[1][cnt + tindex] = p.
y;
499 if(this->dimension > 2){
500 coords[2][cnt + tindex] = p.
z;
510 template <
typename T,
typename lno_t,
typename gno_t>
527 T sd_x, T sd_y, T sd_z,
int wSize) :
529 standartDevx(sd_x), standartDevy(sd_y), standartDevz(sd_z)
531 this->center.
x = center_.
x;
532 this->center.
y = center_.
y;
533 this->center.
z = center_.
z;
541 for(
int i = 0; i < this->dimension; ++i){
544 p.
x = normalDist(this->center.
x, this->standartDevx, state);
547 p.
y = normalDist(this->center.
y, this->standartDevy, state);
550 p.
z = normalDist(this->center.
z, this->standartDevz, state);
553 throw "unsupported dimension";
561 T normalDist(T center_, T sd,
unsigned int &state) {
562 static bool derived=
false;
563 static T storedDerivation;
564 T polarsqrt, normalsquared, normal1, normal2;
567 normal1=2.0*( T(rand_r(&state))/T(RAND_MAX) ) - 1.0;
568 normal2=2.0*( T(rand_r(&state))/T(RAND_MAX) ) - 1.0;
569 normalsquared=normal1*normal1+normal2*normal2;
570 }
while ( normalsquared>=1.0 || normalsquared == 0.0);
572 polarsqrt=sqrt(-2.0*log(normalsquared)/normalsquared);
573 storedDerivation=normal1*polarsqrt;
575 return normal2*polarsqrt*sd + center_;
579 return storedDerivation*sd + center_;
584 template <
typename T,
typename lno_t,
typename gno_t>
596 return (rightMostx - leftMostx)/2 + leftMostx;
599 return (rightMostx - leftMostx)/2;
604 T l_z, T r_z,
int wSize ) :
606 leftMostx(l_x), rightMostx(r_x), leftMosty(l_y), rightMosty(r_y),
607 leftMostz(l_z), rightMostz(r_z){}
615 for(
int i = 0; i < this->dimension; ++i){
618 p.
x = uniformDist(this->leftMostx, this->rightMostx, state);
621 p.
y = uniformDist(this->leftMosty, this->rightMosty, state);
624 p.
z = uniformDist(this->leftMostz, this->rightMostz, state);
627 throw "unsupported dimension";
635 T uniformDist(T a, T b,
unsigned int &state)
637 return (b-a)*(rand_r(&state) / double(RAND_MAX)) + a;
641 template <
typename T,
typename lno_t,
typename gno_t>
658 return (rightMostx - leftMostx)/2 + leftMostx;
661 return (rightMostx - leftMostx)/2;
666 T l_x, T r_x, T l_y, T r_y, T l_z, T r_z ,
667 int myRank_,
int wSize) :
669 leftMostx(l_x), rightMostx(r_x), leftMosty(l_y), rightMosty(r_y), leftMostz(l_z), rightMostz(r_z), myRank(myRank_){
671 this->processCnt = 0;
672 this->along_X = alongX; this->along_Y = alongY; this->along_Z = alongZ;
674 if(this->along_X > 1)
675 this->xstep = (rightMostx - leftMostx) / (alongX - 1);
678 if(this->along_Y > 1)
679 this->ystep = (rightMosty - leftMosty) / (alongY - 1);
682 if(this->along_Z > 1)
683 this->zstep = (rightMostz - leftMostz) / (alongZ - 1);
686 xshift = 0; yshift = 0; zshift = 0;
701 this->zshift = pindex / (along_X * along_Y);
702 this->yshift = (pindex % (along_X * along_Y)) / along_X;
703 this->xshift = (pindex % (along_X * along_Y)) % along_X;
710 p.
x = xshift * this->xstep + leftMostx;
711 p.
y = yshift * this->ystep + leftMosty;
712 p.
z = zshift * this->zstep + leftMostz;
767 template <
typename T,
typename lno_t,
typename gno_t,
typename node_t>
772 int coordinate_dimension;
773 gno_t numGlobalCoords;
774 lno_t numLocalCoords;
775 float *loadDistributions;
777 bool distinctCoordSet;
779 int distributionCount;
784 int weight_dimension;
800 template <
typename tt>
801 tt getParamVal(
const Teuchos::ParameterEntry& pe,
const std::string ¶mname){
804 returnVal = Teuchos::getValue<tt>(pe);
812 int countChar (std::string inStr,
char cntChar){
814 for (
unsigned int i = 0; i < inStr.size(); ++i){
815 if (inStr[i] == cntChar) {
822 template <
typename tt>
824 std::stringstream ss (std::stringstream::in |std::stringstream::out);
826 std::string tmp =
"";
831 template <
typename tt>
832 tt fromString(std::string obj){
833 std::stringstream ss (std::stringstream::in | std::stringstream::out);
838 throw "Cannot convert string " + obj;
844 void splitString(std::string inStr,
char splitChar, std::string *outSplittedStr){
845 std::stringstream ss (std::stringstream::in | std::stringstream::out);
849 std::string tmp =
"";
850 std::getline(ss, tmp ,splitChar);
851 outSplittedStr[cnt++] = tmp;
888 void getCoordinateDistributions(std::string coordinate_distributions){
889 if(coordinate_distributions ==
""){
890 throw "At least one distribution function must be provided to coordinate generator.";
893 int argCnt = this->countChar(coordinate_distributions,
',') + 1;
894 std::string *splittedStr =
new std::string[argCnt];
895 splitString(coordinate_distributions,
',', splittedStr);
897 for(
int i = 0; i < argCnt; ){
900 std::string distName = splittedStr[i++];
902 if(distName ==
"NORMAL"){
904 if (this->coordinate_dimension == 3){
907 if(i + reqArg > argCnt) {
908 std::string tmp = toString<int>(reqArg);
911 np_ = fromString<gno_t>(splittedStr[i++]);
914 pp.
x = fromString<T>(splittedStr[i++]);
915 pp.y = fromString<T>(splittedStr[i++]);
917 if(this->coordinate_dimension == 3){
918 pp.z = fromString<T>(splittedStr[i++]);
921 T sd_x = fromString<T>(splittedStr[i++]);
922 T sd_y = fromString<T>(splittedStr[i++]);
924 if(this->coordinate_dimension == 3){
925 sd_z = fromString<T>(splittedStr[i++]);
929 }
else if(distName ==
"UNIFORM" ){
931 if (this->coordinate_dimension == 3){
934 if(i + reqArg > argCnt) {
935 std::string tmp = toString<int>(reqArg);
938 np_ = fromString<gno_t>(splittedStr[i++]);
939 T l_x = fromString<T>(splittedStr[i++]);
940 T r_x = fromString<T>(splittedStr[i++]);
941 T l_y = fromString<T>(splittedStr[i++]);
942 T r_y = fromString<T>(splittedStr[i++]);
946 if(this->coordinate_dimension == 3){
947 l_z = fromString<T>(splittedStr[i++]);
948 r_z = fromString<T>(splittedStr[i++]);
951 this->coordinateDistributions[this->distributionCount++] =
new CoordinateUniformDistribution<T, lno_t,gno_t>( np_, this->coordinate_dimension, l_x, r_x, l_y, r_y, l_z, r_z, this->worldSize );
952 }
else if (distName ==
"GRID"){
954 if(this->coordinate_dimension == 3){
957 if(i + reqArg > argCnt) {
958 std::string tmp = toString<int>(reqArg);
962 gno_t np_x = fromString<gno_t>(splittedStr[i++]);
963 gno_t np_y = fromString<gno_t>(splittedStr[i++]);
967 if(this->coordinate_dimension == 3){
968 np_z = fromString<gno_t>(splittedStr[i++]);
971 np_ = np_x * np_y * np_z;
972 T l_x = fromString<T>(splittedStr[i++]);
973 T r_x = fromString<T>(splittedStr[i++]);
974 T l_y = fromString<T>(splittedStr[i++]);
975 T r_y = fromString<T>(splittedStr[i++]);
979 if(this->coordinate_dimension == 3){
980 l_z = fromString<T>(splittedStr[i++]);
981 r_z = fromString<T>(splittedStr[i++]);
984 if(np_x < 1 || np_z < 1 || np_y < 1 ){
985 throw "Provide at least 1 point along each dimension for grid test.";
989 (np_x, np_y,np_z, this->coordinate_dimension, l_x, r_x,l_y, r_y, l_z, r_z , this->myRank, this->worldSize);
993 std::string tmp = toString<int>(this->coordinate_dimension);
996 this->numGlobalCoords += (
gno_t) np_;
998 delete []splittedStr;
1001 void getProcLoadDistributions(std::string proc_load_distributions){
1003 this->loadDistributions =
new float[this->worldSize];
1004 if(proc_load_distributions ==
""){
1005 float r = 1.0 / this->worldSize;
1006 for(
int i = 0; i < this->worldSize; ++i){
1007 this->loadDistributions[i] = r;
1012 int argCnt = this->countChar(proc_load_distributions,
',') + 1;
1013 if(argCnt != this->worldSize) {
1014 throw "Invalid parameter count load distributions. Given " + toString<int>(argCnt) +
" processor size is " + toString<int>(this->worldSize);
1016 std::string *splittedStr =
new std::string[argCnt];
1017 splitString(proc_load_distributions,
',', splittedStr);
1018 for(
int i = 0; i < argCnt; ++i){
1019 this->loadDistributions[i] = fromString<float>(splittedStr[i]);
1021 delete []splittedStr;
1025 for(
int i = 0; i < this->worldSize; ++i){
1026 sum += this->loadDistributions[i];
1028 if (fabs(sum - 1.0) > 10*std::numeric_limits<float>::epsilon()){
1029 throw "Processor load ratios do not sum to 1.0.";
1035 void getHoles(std::string holeDescription){
1036 if(holeDescription ==
""){
1040 int argCnt = this->countChar(holeDescription,
',') + 1;
1041 std::string *splittedStr =
new std::string[argCnt];
1042 splitString(holeDescription,
',', splittedStr);
1044 for(
int i = 0; i < argCnt; ){
1045 holes = (
Hole<T> **)realloc((
void *)holes, (this->holeCount + 1)*
sizeof(
Hole<T> *));
1047 std::string shapeName = splittedStr[i++];
1048 if(shapeName ==
"SQUARE" && this->coordinate_dimension == 2){
1049 if(i + 3 > argCnt) {
1053 pp.
x = fromString<T>(splittedStr[i++]);
1054 pp.
y = fromString<T>(splittedStr[i++]);
1055 T edge = fromString<T>(splittedStr[i++]);
1056 this->holes[this->holeCount++] =
new SquareHole<T>(pp, edge);
1057 }
else if(shapeName ==
"RECTANGLE" && this->coordinate_dimension == 2){
1058 if(i + 4 > argCnt) {
1062 pp.
x = fromString<T>(splittedStr[i++]);
1063 pp.
y = fromString<T>(splittedStr[i++]);
1064 T edgex = fromString<T>(splittedStr[i++]);
1065 T edgey = fromString<T>(splittedStr[i++]);
1068 }
else if(shapeName ==
"CIRCLE" && this->coordinate_dimension == 2){
1069 if(i + 3 > argCnt) {
1073 pp.
x = fromString<T>(splittedStr[i++]);
1074 pp.
y = fromString<T>(splittedStr[i++]);
1075 T r = fromString<T>(splittedStr[i++]);
1077 }
else if(shapeName ==
"CUBE" && this->coordinate_dimension == 3){
1078 if(i + 4 > argCnt) {
1082 pp.
x = fromString<T>(splittedStr[i++]);
1083 pp.
y = fromString<T>(splittedStr[i++]);
1084 pp.
z = fromString<T>(splittedStr[i++]);
1085 T edge = fromString<T>(splittedStr[i++]);
1086 this->holes[this->holeCount++] =
new CubeHole<T>(pp, edge);
1087 }
else if(shapeName ==
"RECTANGULAR_PRISM" && this->coordinate_dimension == 3){
1088 if(i + 6 > argCnt) {
1092 pp.
x = fromString<T>(splittedStr[i++]);
1093 pp.
y = fromString<T>(splittedStr[i++]);
1094 pp.
z = fromString<T>(splittedStr[i++]);
1095 T edgex = fromString<T>(splittedStr[i++]);
1096 T edgey = fromString<T>(splittedStr[i++]);
1097 T edgez = fromString<T>(splittedStr[i++]);
1100 }
else if(shapeName ==
"SPHERE" && this->coordinate_dimension == 3){
1101 if(i + 4 > argCnt) {
1105 pp.
x = fromString<T>(splittedStr[i++]);
1106 pp.
y = fromString<T>(splittedStr[i++]);
1107 pp.
z = fromString<T>(splittedStr[i++]);
1108 T r = fromString<T>(splittedStr[i++]);
1111 std::string tmp = toString<int>(this->coordinate_dimension);
1115 delete [] splittedStr;
1118 void getWeightDistribution(std::string *weight_distribution_arr,
int wdimension){
1123 std::string weight_distribution = weight_distribution_arr[ii];
1124 if(weight_distribution ==
"")
continue;
1125 if(wcount == wdimension) {
1126 throw "Weight Dimension is provided as " + toString<int>(wdimension) +
". More weight distribution is provided.";
1129 int count = this->countChar(weight_distribution,
' ');
1130 std::string *splittedStr =
new string[count + 1];
1131 this->splitString(weight_distribution,
' ', splittedStr);
1142 for (
int i = 1; i < count + 1; ++i){
1143 int assignmentCount = this->countChar(splittedStr[i],
'=');
1144 if (assignmentCount != 1){
1145 throw "Error at the argument " + splittedStr[i];
1147 std::string parameter_vs_val[2];
1148 this->splitString(splittedStr[i],
'=', parameter_vs_val);
1149 std::string parameter = parameter_vs_val[0];
1150 std::string value = parameter_vs_val[1];
1153 if (parameter ==
"a1"){
1154 a1 = this->fromString<T>(value);
1156 else if (parameter ==
"a2"){
1157 if(this->coordinate_dimension > 1){
1158 a2 = this->fromString<T>(value);
1161 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1165 else if (parameter ==
"a3"){
1166 if(this->coordinate_dimension > 2){
1167 a3 = this->fromString<T>(value);
1170 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1173 else if (parameter ==
"b1"){
1174 b1 = this->fromString<T>(value);
1176 else if (parameter ==
"b2"){
1177 if(this->coordinate_dimension > 1){
1178 b2 = this->fromString<T>(value);
1181 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1184 else if (parameter ==
"b3"){
1186 if(this->coordinate_dimension > 2){
1187 b3 = this->fromString<T>(value);
1190 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1193 else if (parameter ==
"c"){
1194 c = this->fromString<T>(value);
1196 else if (parameter ==
"x1"){
1197 x1 = this->fromString<T>(value);
1199 else if (parameter ==
"y1"){
1200 if(this->coordinate_dimension > 1){
1201 y1 = this->fromString<T>(value);
1204 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1207 else if (parameter ==
"z1"){
1208 if(this->coordinate_dimension > 2){
1209 z1 = this->fromString<T>(value);
1212 throw parameter+
" argument is not valid when dimension is " + toString<int>(this->coordinate_dimension);
1215 else if (parameter ==
"steps"){
1216 stepCount = this->countChar(value,
',') + 1;
1217 std::string *stepstr =
new std::string[stepCount];
1218 this->splitString(value,
',', stepstr);
1219 steps =
new T[stepCount];
1220 for (
int j = 0; j < stepCount; ++j){
1221 steps[j] = this->fromString<T>(stepstr[j]);
1225 else if (parameter ==
"values"){
1226 valueCount = this->countChar(value,
',') + 1;
1227 std::string *stepstr =
new std::string[valueCount];
1228 this->splitString(value,
',', stepstr);
1229 values =
new T[valueCount];
1230 for (
int j = 0; j < valueCount; ++j){
1231 values[j] = this->fromString<T>(stepstr[j]);
1236 throw "Invalid parameter name at " + splittedStr[i];
1240 delete []splittedStr;
1241 if(stepCount + 1!= valueCount){
1242 throw "Step count: " + this->toString<int>(stepCount) +
" must be 1 less than value count: " + this->toString<int>(valueCount);
1246 this->wd[wcount++] =
new SteppedEquation<T,T>(a1, a2, a3, b1, b2, b3, c, x1, y1, z1, steps, values, stepCount);
1254 if(wcount != this->weight_dimension){
1255 throw "Weight Dimension is provided as " + toString<int>(wdimension) +
". But " + toString<int>(wcount)+
" weight distributions are provided.";
1259 void parseParams(Teuchos::ParameterList params){
1261 std::string holeDescription =
"";
1262 std::string proc_load_distributions =
"";
1263 std::string distinctDescription =
"";
1264 std::string coordinate_distributions =
"";
1267 weight_dimension_parameters[i] =
"";
1271 for (Teuchos::ParameterList::ConstIterator pit = params.begin(); pit != params.end(); ++pit ){
1272 const std::string &
paramName = params.name(pit);
1274 const Teuchos::ParameterEntry &pe = params.entry(pit);
1276 if(paramName.find(
"hole-") == 0){
1277 if(holeDescription ==
""){
1278 holeDescription = getParamVal<std::string>(pe,
paramName);
1281 holeDescription +=
","+getParamVal<std::string>(pe,
paramName);
1284 else if(paramName.find(
"distribution-") == 0){
1285 if(coordinate_distributions ==
"")
1286 coordinate_distributions = getParamVal<std::string>(pe,
paramName);
1288 coordinate_distributions +=
","+getParamVal<std::string>(pe,
paramName);
1295 int dash_pos = weight_dist_param.find(
"-");
1296 std::string distribution_index_string = weight_dist_param.substr(0, dash_pos);
1297 int distribution_index = fromString<int>(distribution_index_string);
1299 if(distribution_index >= MAX_WEIGHT_DIM){
1300 throw "Given distribution index:" + distribution_index_string +
" larger than maximum allowed weight dimension:" + toString<int>(
MAX_WEIGHT_DIM);
1302 weight_dimension_parameters[distribution_index] +=
" " + weight_dist_param.substr(dash_pos + 1)+
"="+ getParamVal<std::string>(pe,
paramName);
1304 else if(paramName ==
"dim"){
1305 int dim = fromString<int>(getParamVal<std::string>(pe,
paramName));
1306 if(dim < 2 && dim > 3){
1309 this->coordinate_dimension = dim;
1312 else if(paramName ==
"wdim"){
1313 int dim = fromString<int>(getParamVal<std::string>(pe,
paramName));
1314 if(dim < 1 && dim > MAX_WEIGHT_DIM){
1317 this->weight_dimension = dim;
1321 else if(paramName ==
"proc_load_distributions"){
1322 proc_load_distributions = getParamVal<std::string>(pe,
paramName);
1323 this->loadDistSet =
true;
1326 else if(paramName ==
"distinct_coordinates"){
1327 distinctDescription = getParamVal<std::string>(pe,
paramName);
1328 if(distinctDescription ==
"T"){
1329 this->distinctCoordSet =
true;
1330 }
else if(distinctDescription ==
"F"){
1331 this->distinctCoordSet =
true;
1333 throw "Invalid parameter for distinct_coordinates: " + distinctDescription +
". Candiates: T or F." ;
1337 else if(paramName ==
"out_file"){
1338 this->outfile = getParamVal<std::string>(pe,
paramName);
1347 if(this->coordinate_dimension == 0){
1348 throw "Dimension must be provided to coordinate generator.";
1367 if (this->loadDistSet && this->distinctCoordSet){
1368 throw "distinct_coordinates and proc_load_distributions parameters cannot be satisfied together.";
1370 this->getHoles(holeDescription);
1372 this->getProcLoadDistributions(proc_load_distributions);
1373 this->getCoordinateDistributions(coordinate_distributions);
1374 this->getWeightDistribution(weight_dimension_parameters, this->weight_dimension);
1381 catch(std::string s){
1389 catch(
char const* s){
1398 for (
int i = 0; i < this->holeCount; ++i){
1399 delete this->holes[i];
1405 delete []loadDistributions;
1407 if(coordinateDistributions){
1409 for (
int i = 0; i < this->distributionCount; ++i){
1410 delete this->coordinateDistributions[i];
1412 free (this->coordinateDistributions);
1415 for (
int i = 0; i < this->weight_dimension; ++i){
1421 if(this->weight_dimension){
1422 for(
int i = 0; i < this->weight_dimension; ++i)
1423 delete [] this->wghts[i];
1424 delete []this->wghts;
1426 if(this->coordinate_dimension){
1427 for(
int i = 0; i < this->coordinate_dimension; ++i)
1428 delete [] this->coords[i];
1429 delete [] this->coords;
1435 cout <<
"\nGeometric Generator Parameter File Format:" << endl;
1436 cout <<
"- dim=Coordinate Dimension: 2 or 3" << endl;
1437 cout <<
"- Available distributions:" << endl;
1438 cout <<
"\tUNIFORM: -> distribution-1=UNIFORM,NUMCOORDINATES,XMIN,XMAX,YMIN,YMAX{,ZMIN,ZMAX}" << endl;
1439 cout <<
"\tGRID: -> distribution-2=GRID,XLENGTH,YLENGTH{,ZLENGTH},XMIN,XMAX,YMIN,YMAX{,ZMIN,ZMAX}" << endl;
1440 cout <<
"\tNORMAL: -> distribution-3=NORMAL,XCENTER,YCENTER{,ZCENTER},XSD,YSD,{,ZSD}" << endl;
1441 cout <<
"- wdim=weight_dimension: weight dimension >= 0. There should be as many weight function as weight dimension." << endl;
1442 cout <<
"- Weight Equation: w = (a1 * (x - x1)^b1) + (a2 * (y - y1)^b2) + (a3 * (z - z1)^b3) + c" << endl;
1443 cout <<
"Parameter settings:" << endl;
1444 cout <<
"\tWeightDistribution-1-a1=a1 " << endl;
1445 cout <<
"\tWeightDistribution-1-a2=a2 " << endl;
1446 cout <<
"\tWeightDistribution-1-a3=a3 " << endl;
1447 cout <<
"\tWeightDistribution-1-b1=b1 " << endl;
1448 cout <<
"\tWeightDistribution-1-b2=b2 " << endl;
1449 cout <<
"\tWeightDistribution-1-b3=b3 " << endl;
1450 cout <<
"\tWeightDistribution-1-x1=x1 " << endl;
1451 cout <<
"\tWeightDistribution-1-y1=y1 " << endl;
1452 cout <<
"\tWeightDistribution-1-z1=z1 " << endl;
1453 cout <<
"\tWeightDistribution-1-c=c " << endl;
1454 cout <<
"\tIt is possible to set step function to the result of weight equation." << endl;
1455 cout <<
"\tWeightDistribution-1-steps=step1,step2,step3:increasing order" << endl;
1456 cout <<
"\tWeightDistribution-1-values=val1,val2,val3,val4." << endl;
1457 cout <<
"\t\tIf w < step1 -> w = val1" << endl;
1458 cout <<
"\t\tElse if w < step2 -> w = val2" << endl;
1459 cout <<
"\t\tElse if w < step3 -> w = val3" << endl;
1460 cout <<
"\t\tElse -> w = val4" << endl;
1461 cout <<
"- Holes:" << endl;
1462 cout <<
"\thole-1:SPHERE,XCENTER,YCENTER,ZCENTER,RADIUS (only for dim=3)" << endl;
1463 cout <<
"\thole-2:CUBE,XCENTER,YCENTER,ZCENTER,EDGE (only for dim=3)" << endl;
1464 cout <<
"\thole-3:RECTANGULAR_PRISM,XCENTER,YCENTER,ZCENTER,XEDGE,YEDGE,ZEDGE (only for dim=3)" << endl;
1465 cout <<
"\thole-4:SQUARE,XCENTER,YCENTER,EDGE (only for dim=2)" << endl;
1466 cout <<
"\thole-5:RECTANGLE,XCENTER,YCENTER,XEDGE,YEDGE (only for dim=2)" << endl;
1467 cout <<
"\thole-6:CIRCLE,XCENTER,YCENTER,RADIUS (only for dim=2)" << endl;
1468 cout <<
"- out_file:out_file_path : if provided output will be written to files." << endl;
1469 cout <<
"- proc_load_distributions:ratio_0, ratio_1, ratio_2....ratio_n. Loads of each processor, should be as many as MPI ranks and should sum up to 1." << endl;
1476 this->coordinate_dimension = 0;
1477 this->weight_dimension = 0;
1478 this->worldSize = comm_->getSize();
1479 this->numGlobalCoords = 0;
1480 this->loadDistributions = NULL;
1482 this->coordinateDistributions = NULL;
1483 this->holeCount = 0;
1484 this->distributionCount = 0;
1496 this->loadDistSet =
false;
1497 this->distinctCoordSet =
false;
1498 this->myRank = comm_->getRank();
1501 this->parseParams(params);
1503 catch(std::string s){
1505 print_description();
1513 lno_t myPointCount = 0;
1514 this->numGlobalCoords = 0;
1516 gno_t prefixSum = 0;
1517 for(
int i = 0; i < this->distributionCount; ++i){
1518 for(
int ii = 0; ii < this->worldSize; ++ii){
1519 lno_t increment =
lno_t (this->coordinateDistributions[i]->numPoints * this->loadDistributions[ii]);
1520 if (ii < this->coordinateDistributions[i]->numPoints % this->worldSize){
1523 this->numGlobalCoords += increment;
1525 prefixSum += increment;
1528 myPointCount +=
lno_t(this->coordinateDistributions[i]->numPoints * this->loadDistributions[myRank]);
1529 if (myRank < this->coordinateDistributions[i]->numPoints % this->worldSize){
1534 this->coords =
new T *[this->coordinate_dimension];
1535 for(
int i = 0; i < this->coordinate_dimension; ++i){
1536 this->coords[i] =
new T[myPointCount];
1539 for (
int ii = 0; ii < this->coordinate_dimension; ++ii){
1540 #ifdef HAVE_ZOLTAN2_OMP 1541 #pragma omp parallel for 1543 for(
int i = 0; i < myPointCount; ++i){
1544 this->coords[ii][i] = 0;
1548 this->numLocalCoords = 0;
1550 for (
int i = 0; i < distributionCount; ++i){
1552 lno_t requestedPointCount =
lno_t(this->coordinateDistributions[i]->numPoints * this->loadDistributions[myRank]);
1553 if (myRank < this->coordinateDistributions[i]->numPoints % this->worldSize){
1554 requestedPointCount += 1;
1558 this->coordinateDistributions[i]->
GetPoints(requestedPointCount,this->coords, this->numLocalCoords, this->holes, this->holeCount, this->loadDistributions, myRank);
1559 this->numLocalCoords += requestedPointCount;
1564 if (this->distinctCoordSet){
1568 if(this->outfile !=
""){
1570 std::ofstream myfile;
1571 myfile.open ((this->outfile + toString<int>(myRank)).c_str());
1572 for(
lno_t i = 0; i < this->numLocalCoords; ++i){
1574 myfile << this->coords[0][i];
1575 if(this->coordinate_dimension > 1){
1576 myfile <<
" " << this->coords[1][i];
1578 if(this->coordinate_dimension > 2){
1579 myfile <<
" " << this->coords[2][i];
1581 myfile << std::endl;
1595 if (this->weight_dimension > 0){
1596 this->wghts =
new T *[this->weight_dimension];
1597 for(
int i = 0; i < this->weight_dimension; ++i){
1598 this->wghts[i] =
new T[this->numLocalCoords];
1602 for(
int ii = 0; ii < this->weight_dimension; ++ii){
1603 switch(this->coordinate_dimension){
1605 #ifdef HAVE_ZOLTAN2_OMP 1606 #pragma omp parallel for 1608 for (
lno_t i = 0; i < this->numLocalCoords; ++i){
1609 this->wghts[ii][i] = this->wd[ii]->
get1DWeight(this->coords[0][i]);
1613 #ifdef HAVE_ZOLTAN2_OMP 1614 #pragma omp parallel for 1616 for (
lno_t i = 0; i < this->numLocalCoords; ++i){
1617 this->wghts[ii][i] = this->wd[ii]->
get2DWeight(this->coords[0][i], this->coords[1][i]);
1621 #ifdef HAVE_ZOLTAN2_OMP 1622 #pragma omp parallel for 1624 for (
lno_t i = 0; i < this->numLocalCoords; ++i){
1625 this->wghts[ii][i] = this->wd[ii]->
get3DWeight(this->coords[0][i], this->coords[1][i], this->coords[2][i]);
1633 return this->weight_dimension;
1636 return this->coordinate_dimension;
1639 return this->numLocalCoords;
1642 return this->numGlobalCoords;
1646 return this->coords;
1654 for(
int ii = 0; ii < this->coordinate_dimension; ++ii){
1655 #ifdef HAVE_ZOLTAN2_OMP 1656 #pragma omp parallel for 1658 for (
lno_t i = 0; i < this->numLocalCoords; ++i){
1659 c[ii][i] = this->coords[ii][i];
1665 for(
int ii = 0; ii < this->weight_dimension; ++ii){
1666 #ifdef HAVE_ZOLTAN2_OMP 1667 #pragma omp parallel for 1669 for (
lno_t i = 0; i < this->numLocalCoords; ++i){
1670 w[ii][i] = this->wghts[ii][i];
virtual bool isInArea(CoordinatePoint< T > dot)
virtual bool isInArea(CoordinatePoint< T > dot)
T ** getLocalWeightsView()
virtual weighttype get1DWeight(T x)
T ** getLocalCoordinatesView()
SphereHole(CoordinatePoint< T > center_, T edge_)
CoordinateGridDistribution(gno_t alongX, gno_t alongY, gno_t alongZ, int dim, T l_x, T r_x, T l_y, T r_y, T l_z, T r_z, int myRank_, int wSize)
RectangularPrismHole(CoordinatePoint< T > center_, T edge_x_, T edge_y_, T edge_z_)
virtual weighttype get3DWeight(T x, T y, T z)=0
void print(T x, T y, T z)
Defines the PartitioningSolution class.
virtual ~SteppedEquation()
virtual bool isInArea(CoordinatePoint< T > dot)
void GetPoints(lno_t requestedPointcount, CoordinatePoint< T > *points, Hole< T > **holes, lno_t holeCount, float *sharedRatios_, int myRank)
virtual ~RectangularPrismHole()
CoordinatePoint< T > center
int getCoordinateDimension()
Expression is a generic following method.
CoordinateDistribution(gno_t np_, int dim, int wSize)
virtual ~CoordinateDistribution()
virtual weighttype get3DWeight(T x, T y, T z)
virtual CoordinatePoint< T > getPoint(gno_t pindex, unsigned int &state)
GeometricGenerator(Teuchos::ParameterList ¶ms, const RCP< const Teuchos::Comm< int > > &comm_)
const std::string shapes[]
void GetPoints(lno_t requestedPointcount, T **coords, lno_t tindex, Hole< T > **holes, lno_t holeCount, float *sharedRatios_, int myRank)
SteppedEquation(T a1_, T a2_, T a3_, T b1_, T b2_, T b3_, T c_, T x1_, T y1_, T z1_, T *steps_, T *values_, int stepCount_)
virtual CoordinatePoint< T > getPoint(gno_t pindex, unsigned int &state)
std::string toString(tt obj)
Hole(CoordinatePoint< T > center_, T edge1_, T edge2_, T edge3_)
lno_t getNumLocalCoords()
const std::string weight_distribution_string
virtual weighttype get2DWeight(T x, T y)=0
virtual ~WeightDistribution()
#define INVALID_SHAPE_ARG(SHAPE, REQUIRED)
RectangleHole(CoordinatePoint< T > center_, T edge_x_, T edge_y_)
virtual weighttype get2DWeight(T x, T y)
CircleHole(CoordinatePoint< T > center_, T edge_)
void getLocalCoordinatesCopy(T **c)
virtual bool isInArea(CoordinatePoint< T > dot)
#define INVALIDSHAPE(STR, DIM)
gno_t getNumGlobalCoords()
SquareHole(CoordinatePoint< T > center_, T edge_)
CoordinatePoint< T > center
virtual bool isInArea(CoordinatePoint< T > dot)
virtual weighttype get1DWeight(T x)=0
CubeHole(CoordinatePoint< T > center_, T edge_)
virtual bool isInArea(CoordinatePoint< T > dot)
virtual weighttype getWeight(CoordinatePoint< T > p)
virtual ~CoordinateGridDistribution()
virtual ~CoordinateNormalDistribution()
CoordinateNormalDistribution(gno_t np_, int dim, CoordinatePoint< T > center_, T sd_x, T sd_y, T sd_z, int wSize)
void getLocalWeightsCopy(T **w)