1 #ifndef _ZOLTAN2_COORD_PARTITIONMAPPING_HPP_
2 #define _ZOLTAN2_COORD_PARTITIONMAPPING_HPP_
8 #include "Teuchos_ArrayViewDecl.hpp"
11 #include "Teuchos_ReductionOp.hpp"
19 template <
typename Ordinal,
typename T>
32 void reduce(
const Ordinal count,
const T inBuffer[], T inoutBuffer[])
const
35 for (Ordinal i=0; i < count; i++){
36 if (inBuffer[0] - inoutBuffer[0] < -_EPSILON){
37 inoutBuffer[0] = inBuffer[0];
38 inoutBuffer[1] = inBuffer[1];
40 inBuffer[0] - inoutBuffer[0] < _EPSILON &&
41 inBuffer[1] - inoutBuffer[1] < _EPSILON){
42 inoutBuffer[0] = inBuffer[0];
43 inoutBuffer[1] = inBuffer[1];
55 template <
typename it>
57 return (x == 1 ? x : x * z2Fact<it>(x - 1));
60 template <
typename gno_t,
typename partId_t>
68 template <
typename IT>
78 fact[k] = fact[k - 1] * k;
81 for (k = 0; k < n; ++k)
83 perm[k] = i / fact[n - 1 - k];
84 i = i % fact[n - 1 - k];
89 for (k = n - 1; k > 0; --k)
90 for (j = k - 1; j >= 0; --j)
91 if (perm[j] <= perm[k])
97 template <
typename partId_t>
99 int dim = grid_dims.size();
100 int neighborCount = 2 * dim;
101 task_comm_xadj = allocMemory< partId_t>(taskCount);
102 task_comm_adj = allocMemory <partId_t>(taskCount * neighborCount);
105 for (
partId_t i = 0; i < taskCount; ++i){
107 for (
int j = 0; j < dim; ++j){
108 partId_t lNeighbor = i - prevDimMul;
109 partId_t rNeighbor = i + prevDimMul;
110 prevDimMul *= grid_dims[j];
111 if (lNeighbor >= 0 && lNeighbor/ prevDimMul == i / prevDimMul && lNeighbor < taskCount){
112 task_comm_adj[neighBorIndex++] = lNeighbor;
114 if (rNeighbor >= 0 && rNeighbor/ prevDimMul == i / prevDimMul && rNeighbor < taskCount){
115 task_comm_adj[neighBorIndex++] = rNeighbor;
118 task_comm_xadj[i] = neighBorIndex;
123 template <
typename Adapter,
typename scalar_t,
typename partId_t>
126 const Teuchos::Comm<int> *comm,
137 ArrayView<const gno_t> gnos;
138 ArrayView<input_t> xyz;
139 ArrayView<input_t> wgts;
149 gno_t *point_counts = allocMemory<gno_t>(ntasks);
150 memset(point_counts, 0,
sizeof(gno_t) * ntasks);
153 gno_t *global_point_counts = allocMemory<gno_t>(ntasks);
156 scalar_t **pqJagged_coordinates = allocMemory<scalar_t *>(coordDim);
158 for (
int dim=0; dim < coordDim; dim++){
159 ArrayRCP<const scalar_t> ar;
160 xyz[dim].getInputArray(ar);
162 pqJagged_coordinates[dim] = (
scalar_t *)ar.getRawPtr();
163 memset(partCenters[dim], 0,
sizeof(
scalar_t) * ntasks);
168 const gno_t *soln_gnos = soln_->
getIdList();
178 vector< vector <GNO_LNO_PAIR<gno_t, partId_t> > > hash(numLocalCoords);
181 for (lno_t i=0; i < numLocalCoords; i++){
183 tmp.
gno = soln_gnos[i];
187 ++point_counts[tmp.
part];
188 lno_t hash_index = tmp.
gno % numLocalCoords;
189 hash[hash_index].push_back(tmp);
194 reduceAll<int, gno_t>(*comm, Teuchos::REDUCE_SUM,
195 ntasks, point_counts, global_point_counts
202 for (lno_t i=0; i < numLocalCoords; i++){
204 lno_t hash_index = g % numLocalCoords;
205 lno_t hash_size = hash[hash_index].size();
207 for (
int j =0; j < hash_size; ++j){
208 if (hash[hash_index][j].gno == g){
209 p = hash[hash_index][j].part;
214 cerr <<
"ERROR AT HASHING FOR GNO:"<< g <<
" LNO:" << i << endl;
217 for(
int j = 0; j < coordDim; ++j){
218 scalar_t c = pqJagged_coordinates[j][i];
219 partCenters[j][p] += c;
224 for(
int j = 0; j < coordDim; ++j){
225 for (
partId_t i=0; i < ntasks; ++i){
226 partCenters[j][i] /= global_point_counts[i];
230 scalar_t *tmpCoords = allocMemory<scalar_t>(ntasks);
231 for(
int j = 0; j < coordDim; ++j){
232 reduceAll<int, scalar_t>(*comm, Teuchos::REDUCE_SUM,
233 ntasks, partCenters[j], tmpCoords
237 partCenters[j] = tmpCoords;
241 freeArray<gno_t> (point_counts);
242 freeArray<gno_t> (global_point_counts);
244 freeArray<scalar_t> (tmpCoords);
245 freeArray<scalar_t *>(pqJagged_coordinates);
251 template <
class IT,
class WT>
261 this->heapSize = heapsize_;
262 this->indices = allocMemory<IT>(heapsize_ );
263 this->values = allocMemory<WT>(heapsize_ );
264 this->_EPSILON = numeric_limits<WT>::epsilon();
268 freeArray<IT>(this->indices);
269 freeArray<WT>(this->values);
274 WT maxVal = this->values[0];
277 if (distance >= maxVal)
return;
279 this->values[0] = distance;
280 this->indices[0] = index;
287 IT child_index1 = 2 * index_on_heap + 1;
288 IT child_index2 = 2 * index_on_heap + 2;
291 if(child_index1 < this->heapSize && child_index2 < this->heapSize){
293 if (this->values[child_index1] < this->values[child_index2]){
294 biggerIndex = child_index2;
297 biggerIndex = child_index1;
300 else if(child_index1 < this->heapSize){
301 biggerIndex = child_index1;
304 else if(child_index2 < this->heapSize){
305 biggerIndex = child_index2;
307 if (biggerIndex >= 0 && this->values[biggerIndex] > this->values[index_on_heap]){
308 WT tmpVal = this->values[biggerIndex];
309 this->values[biggerIndex] = this->values[index_on_heap];
310 this->values[index_on_heap] = tmpVal;
312 IT tmpIndex = this->indices[biggerIndex];
313 this->indices[biggerIndex] = this->indices[index_on_heap];
314 this->indices[index_on_heap] = tmpIndex;
320 WT MAXVAL = numeric_limits<WT>::max();
321 for(IT i = 0; i < this->heapSize; ++i){
322 this->values[i] = MAXVAL;
323 this->indices[i] = -1;
331 for(IT j = 0; j < this->heapSize; ++j){
332 nc += this->values[j];
342 for(
int i = 0; i < dimension; ++i){
344 for(IT j = 0; j < this->heapSize; ++j){
345 IT k = this->indices[j];
349 nc /= this->heapSize;
350 moved = (
ABS(center[i] - nc) > this->_EPSILON || moved );
358 for(IT i = 0; i < this->heapSize; ++i){
359 permutation[i] = this->indices[i];
366 template <
class IT,
class WT>
379 this->dimension = dimension_;
380 this->
center = allocMemory<WT>(dimension_);
381 this->closestPoints.setHeapsize(heapsize);
385 this->closestPoints.initValues();
389 return this->closestPoints.getNewCenters(
center, coords, dimension);
396 for (
int i = 0; i < this->dimension; ++i){
397 WT d = (
center[i] - elementCoords[i][index]);
400 distance = pow(distance, WT(1.0 / this->dimension));
401 closestPoints.addPoint(index, distance);
406 return closestPoints.getTotalDistance();
410 closestPoints.copyCoordinates(permutation);
417 template <
class IT,
class WT>
424 IT required_elements;
430 freeArray<KMeansCluster <IT,WT> >(clusters);
431 freeArray<WT>(maxCoordinates);
432 freeArray<WT>(minCoordinates);
441 IT required_elements_):
443 numElements(numElements_),
444 elementCoords(elementCoords_),
445 numClusters ((1 << dim_) + 1),
446 required_elements(required_elements_)
448 this->clusters = allocMemory<KMeansCluster <IT,WT> >(this->numClusters);
450 for (
int i = 0; i < numClusters; ++i){
451 this->clusters[i].setParams(this->dim, this->required_elements);
454 this->maxCoordinates = allocMemory <WT> (this->dim);
455 this->minCoordinates = allocMemory <WT> (this->dim);
458 for (
int j = 0; j < dim; ++j){
459 this->minCoordinates[j] = this->maxCoordinates[j] = this->elementCoords[j][0];
460 for(IT i = 1; i < numElements; ++i){
461 WT t = this->elementCoords[j][i];
462 if(t > this->maxCoordinates[j]){
463 this->maxCoordinates[j] = t;
465 if (t < minCoordinates[j]){
466 this->minCoordinates[j] = t;
473 for (
int j = 0; j < dim; ++j){
474 int mod = (1 << (j+1));
475 for (
int i = 0; i < numClusters - 1; ++i){
477 if ( (i % mod) < mod / 2){
478 c = this->maxCoordinates[j];
482 c = this->minCoordinates[j];
484 this->clusters[i].center[j] = c;
489 for (
int j = 0; j < dim; ++j){
490 this->clusters[numClusters - 1].center[j] = (this->maxCoordinates[j] + this->minCoordinates[j]) / 2;
506 for(
int it = 0; it < 10; ++it){
508 for (IT j = 0; j < this->numClusters; ++j){
509 this->clusters[j].clearHeap();
511 for (IT i = 0; i < this->numElements; ++i){
513 for (IT j = 0; j < this->numClusters; ++j){
515 this->clusters[j].getDistance(i,this->elementCoords);
519 for (IT j = 0; j < this->numClusters; ++j){
520 moved =(this->clusters[j].getNewCenters(this->elementCoords) || moved );
533 WT minDistance = this->clusters[0].getDistanceToCenter();
536 for (IT j = 1; j < this->numClusters; ++j){
537 WT minTmpDistance = this->clusters[j].getDistanceToCenter();
539 if(minTmpDistance < minDistance){
540 minDistance = minTmpDistance;
546 this->clusters[minCluster].copyCoordinates(procPermutation);
552 #define MINOF(a,b) (((a)<(b))?(a):(b))
560 template <
typename T>
564 #ifdef HAVE_ZOLTAN2_OMP
565 #pragma omp parallel for
567 for(
size_t i = 0; i < arrSize; ++i){
574 #ifdef HAVE_ZOLTAN2_OMP
575 #pragma omp parallel for
577 for(
size_t i = 0; i < arrSize; ++i){
586 template <
typename procId_t>
608 procId_t *task_to_proc,
609 procId_t *task_communication_xadj,
610 procId_t *task_communication_adj){
612 double totalCost = 0;
614 procId_t commCount = 0;
615 for (procId_t task = 0; task < this->
no_tasks; ++task){
616 int assigned_proc = task_to_proc[task];
617 procId_t task_adj_begin = 0;
618 procId_t task_adj_end = task_communication_xadj[task];
619 if (task > 0) task_adj_begin = task_communication_xadj[task - 1];
621 commCount += task_adj_end - task_adj_begin;
623 for (procId_t task2 = task_adj_begin; task2 < task_adj_end; ++task2){
624 procId_t neighborTask = task_communication_adj[task2];
626 int neighborProc = task_to_proc[neighborTask];
630 totalCost += distance ;
634 this->
commCost = totalCost/ commCount;
651 RCP<const Environment> env,
652 ArrayRCP <procId_t> &proc_to_task_xadj,
653 ArrayRCP <procId_t> &proc_to_task_adj,
654 ArrayRCP <procId_t> &task_to_proc
660 template <
typename pcoord_t,
typename tcoord_t,
typename procId_t>
720 for(
int i = ntasks; i < nprocs; ++i){
721 proc_permutation[i] = -1;
745 lo = _u_umpa_seed % q;
746 hi = _u_umpa_seed / q;
747 test = (a*lo)-(r*hi);
751 _u_umpa_seed = test + m;
752 d = (double) ((
double) _u_umpa_seed / (double) m);
753 return (procId_t) (d*(double)l);
767 procId_t *a = visitOrder;
771 procId_t i, u, v, tmp;
779 for (i=0; i<n; i+=16)
783 SWAP(a[v], a[u], tmp);
784 SWAP(a[v+1], a[u+1], tmp);
785 SWAP(a[v+2], a[u+2], tmp);
786 SWAP(a[v+3], a[u+3], tmp);
790 procId_t i, end = n / 4;
792 for (i=1; i<end; i++)
812 RCP<const Environment> env,
813 ArrayRCP <procId_t> &rcp_proc_to_task_xadj,
814 ArrayRCP <procId_t> &rcp_proc_to_task_adj,
815 ArrayRCP <procId_t> &rcp_task_to_proc
818 rcp_proc_to_task_xadj = ArrayRCP <procId_t> (this->
no_procs);
819 rcp_proc_to_task_adj = ArrayRCP <procId_t> (this->
no_tasks);
820 rcp_task_to_proc = ArrayRCP <procId_t> (this->
no_tasks);
822 procId_t *proc_to_task_xadj = rcp_proc_to_task_xadj.getRawPtr();
823 procId_t *proc_to_task_adj = rcp_proc_to_task_adj.getRawPtr();
824 procId_t *task_to_proc = rcp_task_to_proc.getRawPtr();
827 procId_t invalid = 0;
828 fillContinousArray<procId_t> (proc_to_task_xadj, this->
no_procs, &invalid);
837 int permutations = taskPerm * procPerm;
840 procId_t *proc_xadj = allocMemory<procId_t> (num_parts);
843 procId_t *proc_adjList = allocMemory<procId_t>(this->
no_procs);
846 procId_t used_num_procs = this->
no_procs;
847 if(this->no_procs > this->
no_tasks){
853 fillContinousArray<procId_t>(proc_adjList,this->
no_procs, NULL);
856 int myPermutation = myRank % permutations;
858 int myProcPerm= myPermutation % procPerm;
859 int myTaskPerm = myPermutation / procPerm;
861 int *permutation = allocMemory<int> (taskPerm);
864 ithPermutation<int>(this->
proc_coord_dim, myProcPerm, permutation);
866 pcoord_t **pcoords = allocMemory<pcoord_t *> (this->
proc_coord_dim);
873 env->timerStart(
MACRO_TIMERS,
"Mapping - Proc Partitioning");
874 sequentialTaskPartitioning<pcoord_t, procId_t, procId_t>(
885 env->timerStop(
MACRO_TIMERS,
"Mapping - Proc Partitioning");
886 freeArray<pcoord_t *> (pcoords);
889 procId_t *task_xadj = allocMemory<procId_t> (num_parts);
890 procId_t *task_adjList = allocMemory<procId_t>(this->
no_tasks);
892 fillContinousArray<procId_t>(task_adjList,this->
no_tasks, NULL);
895 ithPermutation<int>(this->
task_coord_dim, myTaskPerm, permutation);
898 tcoord_t **tcoords = allocMemory<tcoord_t *> (this->
task_coord_dim);
903 env->timerStart(
MACRO_TIMERS,
"Mapping - Task Partitioning");
905 sequentialTaskPartitioning<tcoord_t, procId_t, procId_t>(
916 env->timerStop(
MACRO_TIMERS,
"Mapping - Task Partitioning");
917 freeArray<pcoord_t *> (tcoords);
918 freeArray<int> (permutation);
922 for(procId_t i = 0; i < num_parts; ++i){
924 procId_t proc_index_begin = 0;
925 procId_t task_begin_index = 0;
928 proc_index_begin = proc_xadj[i - 1];
929 task_begin_index = task_xadj[i - 1];
931 procId_t proc_index_end = proc_xadj[i];
932 procId_t task_end_index = task_xadj[i];
935 if(proc_index_end - proc_index_begin != 1){
936 cerr <<
"Error at partitioning of processors" << endl;
937 cerr <<
"PART:" << i <<
" is assigned to " << proc_index_end - proc_index_begin <<
" processors." << std::endl;
940 procId_t assigned_proc = proc_adjList[proc_index_begin];
941 proc_to_task_xadj[assigned_proc] = task_end_index - task_begin_index;
946 procId_t *proc_to_task_xadj_work = allocMemory<procId_t> (this->
no_procs);
947 proc_to_task_xadj_work[0] = proc_to_task_xadj[0];
948 for(procId_t i = 1; i < this->
no_procs; ++i){
949 proc_to_task_xadj[i] += proc_to_task_xadj[i - 1];
950 proc_to_task_xadj_work[i] = proc_to_task_xadj[i];
953 for(procId_t i = 0; i < num_parts; ++i){
955 procId_t proc_index_begin = 0;
956 procId_t task_begin_index = 0;
959 proc_index_begin = proc_xadj[i - 1];
960 task_begin_index = task_xadj[i - 1];
962 procId_t task_end_index = task_xadj[i];
964 procId_t assigned_proc = proc_adjList[proc_index_begin];
966 for (procId_t j = task_begin_index; j < task_end_index; ++j){
967 procId_t taskId = task_adjList[j];
969 task_to_proc[taskId] = assigned_proc;
971 proc_to_task_adj [ --proc_to_task_xadj_work[assigned_proc] ] = taskId;
975 freeArray<procId_t>(proc_to_task_xadj_work);
976 freeArray<procId_t>(task_xadj);
977 freeArray<procId_t>(task_adjList);
978 freeArray<procId_t>(proc_xadj);
979 freeArray<procId_t>(proc_adjList);
984 template <
typename Adapter,
typename procId_t>
988 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1028 const Teuchos::Comm<int> *comm_,
1057 tcoord_t **partCenters = NULL;
1058 partCenters = allocMemory<tcoord_t *>(coordDim);
1059 for (
int i = 0; i < coordDim; ++i){
1060 partCenters[i] = allocMemory<tcoord_t>(this->
ntasks);
1066 getSolutionCenterCoordinates<Adapter, typename Adapter::scalar_t,procId_t>(
1075 envConst->timerStop(
MACRO_TIMERS,
"Mapping - Solution Center");
1089 int myRank = comm_->getRank();
1092 envConst->timerStart(
MACRO_TIMERS,
"Mapping - Processor Task map");
1094 envConst->timerStop(
MACRO_TIMERS,
"Mapping - Processor Task map");
1097 envConst->timerStart(
MACRO_TIMERS,
"Mapping - Communication Graph");
1106 envConst->timerStop(
MACRO_TIMERS,
"Mapping - Communication Graph");
1108 if (comm_->getRank() == 0){
1113 for (procId_t i = 1; i < taskCommCount; ++i){
1115 if (maxN < nc) maxN = nc;
1117 std::cout <<
" maxNeighbor:" << maxN << std::endl;
1120 this->
writeGnuPlot(comm_, soln_, coordDim, partCenters);
1174 envConst->timerStart(
MACRO_TIMERS,
"Mapping - Communication Cost");
1181 envConst->timerStop(
MACRO_TIMERS,
"Mapping - Communication Cost");
1192 for (
int i = 0; i < coordDim; ++i){
1193 freeArray<tcoord_t>(partCenters[i]);
1195 freeArray<tcoord_t *>(partCenters);
1210 const Teuchos::Comm<int> *comm_,
1215 ArrayRCP<procId_t>task_communication_xadj_,
1216 ArrayRCP<procId_t>task_communication_adj_
1237 tcoord_t **partCenters = NULL;
1238 partCenters = allocMemory<tcoord_t *>(coordDim);
1239 for (
int i = 0; i < coordDim; ++i){
1240 partCenters[i] = allocMemory<tcoord_t>(this->
ntasks);
1243 getSolutionCenterCoordinates<Adapter, typename Adapter::scalar_t,procId_t>(
1263 int myRank = comm_->getRank();
1265 this->proc_task_comm->calculateCommunicationCost(
1281 for (
int i = 0; i < coordDim; ++i){
1282 freeArray<tcoord_t>(partCenters[i]);
1284 freeArray<tcoord_t *>(partCenters);
1300 nprocs(proc_task_comm_->getNProcs()),
1301 ntasks(proc_task_comm_->getNTasks()),
1313 const Teuchos::Comm<int> *comm_,
1317 tcoord_t **taskCoords
1324 nprocs(comm_->getSize()),
1332 taskDim, taskCoords,
1346 Teuchos::RCP<const Environment>(this->
env,
false),
1353 std::cerr <<
"communicationModel is not specified in the Mapper" << endl;
1375 int taskPerm = z2Fact<int>(procDim);
1376 int procPerm = z2Fact<int>(taskDim);
1377 int idealGroupSize = taskPerm * procPerm;
1379 int myRank = this->
comm->getRank();
1380 int commSize = this->
comm->getSize();
1382 int myGroupIndex = myRank / idealGroupSize;
1384 int prevGroupBegin = (myGroupIndex - 1)* idealGroupSize;
1385 if (prevGroupBegin < 0) prevGroupBegin = 0;
1386 int myGroupBegin = myGroupIndex * idealGroupSize;
1387 int myGroupEnd = (myGroupIndex + 1) * idealGroupSize;
1388 int nextGroupEnd = (myGroupIndex + 2)* idealGroupSize;
1390 if (myGroupEnd > commSize){
1391 myGroupBegin = prevGroupBegin;
1392 myGroupEnd = commSize;
1394 if (nextGroupEnd > commSize){
1395 myGroupEnd = commSize;
1397 int myGroupSize = myGroupEnd - myGroupBegin;
1399 int *myGroup = allocMemory<int>(myGroupSize);
1400 for (
int i = 0; i < myGroupSize; ++i){
1401 myGroup[i] = myGroupBegin + i;
1405 ArrayView<const partId_t> myGroupView(myGroup, myGroupSize);
1407 RCP<Comm<int> > subComm = this->
comm->createSubcommunicator(myGroupView);
1408 freeArray<int>(myGroup);
1419 double myCost = this->
proc_task_comm->getCommunicationCostMetric();
1420 double localCost[2], globalCost[2];
1422 localCost[0] = myCost;
1423 localCost[1] = double(subComm->getRank());
1425 globalCost[1] = globalCost[0] = std::numeric_limits<double>::max();
1427 reduceAll<int, double>(*subComm, reduceBest,
1428 2, localCost, globalCost
1431 int sender = int(globalCost[1]);
1464 procId_t task_begin = 0;
1468 numParts = taskend - task_begin;
1472 procId_t task_begin = 0;
1482 if (taskend - task_begin > 0){
1483 ArrayView <procId_t> assignedParts(this->
proc_to_task_adj.getRawPtr() + task_begin, taskend - task_begin);
1484 return assignedParts;
1487 ArrayView <procId_t> assignedParts;
1488 return assignedParts;
1494 std::ofstream gnuPlotCode (
"gnuPlot.plot", std::ofstream::out);
1498 for(procId_t i = 0; i < this->
nprocs; ++i){
1500 std::string procFile = toString<int>(i) +
"_mapping.txt";
1502 gnuPlotCode <<
"plot \"" << procFile <<
"\"\n";
1505 gnuPlotCode <<
"replot \"" << procFile <<
"\"\n";
1508 std::ofstream inpFile (procFile.c_str(), std::ofstream::out);
1510 string gnuPlotArrow =
"set arrow from ";
1511 for(
int j = 0; j < mindim; ++j){
1512 if (j == mindim - 1){
1514 gnuPlotArrow += toString<float>(
proc_task_comm->proc_coords[j][i]);
1519 gnuPlotArrow += toString<float>(
proc_task_comm->proc_coords[j][i]) +
",";
1522 gnuPlotArrow +=
" to ";
1525 inpFile << std::endl;
1527 for(
int k = 0; k < a.size(); ++k){
1530 string gnuPlotArrow2 = gnuPlotArrow;
1531 for(
int z = 0; z < mindim; ++z){
1532 if(z == mindim - 1){
1536 gnuPlotArrow2 += toString<float>(
proc_task_comm->task_coords[z][j]);
1540 gnuPlotArrow2 += toString<float>(
proc_task_comm->task_coords[z][j]) +
",";
1543 ss += gnuPlotArrow2 +
"\n";
1544 inpFile << std::endl;
1550 gnuPlotCode <<
"\nreplot\n pause -1 \n";
1551 gnuPlotCode.close();
1559 std::string rankStr = toString<int>(myRank);
1560 std::string gnuPlots =
"gnuPlot", extentionS =
".plot";
1561 std::string outF = gnuPlots + rankStr+ extentionS;
1562 std::ofstream gnuPlotCode ( outF.c_str(), std::ofstream::out);
1566 int mindim =
MINOF(tmpproc_task_comm->proc_coord_dim, tmpproc_task_comm->task_coord_dim);
1568 string procs =
"", parts =
"";
1569 for(procId_t i = 0; i < this->
nprocs; ++i){
1579 string gnuPlotArrow =
"set arrow from ";
1580 for(
int j = 0; j < mindim; ++j){
1581 if (j == mindim - 1){
1583 gnuPlotArrow += toString<float>(tmpproc_task_comm->proc_coords[j][i]);
1584 procs += toString<float>(tmpproc_task_comm->proc_coords[j][i]);
1589 gnuPlotArrow += toString<float>(tmpproc_task_comm->proc_coords[j][i]) +
",";
1590 procs += toString<float>(tmpproc_task_comm->proc_coords[j][i])+
" ";
1595 gnuPlotArrow +=
" to ";
1598 for(
int k = 0; k < a.size(); ++k){
1601 string gnuPlotArrow2 = gnuPlotArrow;
1602 for(
int z = 0; z < mindim; ++z){
1603 if(z == mindim - 1){
1607 gnuPlotArrow2 += toString<float>(tmpproc_task_comm->task_coords[z][j]);
1608 parts += toString<float>(tmpproc_task_comm->task_coords[z][j]);
1612 gnuPlotArrow2 += toString<float>(tmpproc_task_comm->task_coords[z][j]) +
",";
1613 parts += toString<float>(tmpproc_task_comm->task_coords[z][j]) +
" ";
1617 ss += gnuPlotArrow2 +
" nohead\n";
1625 std::ofstream procFile (
"procPlot.plot", std::ofstream::out);
1626 procFile << procs <<
"\n";
1629 std::ofstream partFile (
"partPlot.plot", std::ofstream::out);
1630 partFile << parts<<
"\n";
1633 std::ofstream extraProcFile (
"allProc.plot", std::ofstream::out);
1635 for(procId_t j = 0; j < this->
nprocs; ++j){
1636 for(
int i = 0; i < mindim; ++i){
1637 extraProcFile << tmpproc_task_comm->proc_coords[i][j] <<
" ";
1639 extraProcFile << endl;
1642 extraProcFile.close();
1646 gnuPlotCode <<
"plot \"procPlot.plot\" with points pointsize 3\n";
1648 gnuPlotCode <<
"splot \"procPlot.plot\" with points pointsize 3\n";
1650 gnuPlotCode <<
"replot \"partPlot.plot\" with points pointsize 3\n";
1651 gnuPlotCode <<
"replot \"allProc.plot\" with points pointsize 0.65\n";
1652 gnuPlotCode <<
"\nreplot\n pause -1 \n";
1653 gnuPlotCode.close();
1659 const Teuchos::Comm<int> *comm_,
1662 tcoord_t **partCenters
1664 std::string file =
"gggnuPlot";
1665 std::string exten =
".plot";
1666 ofstream mm(
"2d.txt");
1667 file += toString<int>(comm_->getRank()) + exten;
1668 std::ofstream ff(file.c_str());
1673 (*outPartBoxes)[i].writeGnuPlot(ff, mm);
1676 ff <<
"plot \"2d.txt\"" << endl;
1680 ff <<
"splot \"2d.txt\"" << endl;
1685 ff <<
"set style arrow 5 nohead size screen 0.03,15,135 ls 1" << endl;
1690 for (procId_t p = pb; p < pe; ++p){
1694 std::string arrowline =
"set arrow from ";
1695 for (
int j = 0; j < coordDim - 1; ++j){
1696 arrowline += toString<tcoord_t>(partCenters[j][n]) +
",";
1698 arrowline += toString<tcoord_t>(partCenters[coordDim -1][n]) +
" to ";
1701 for (
int j = 0; j < coordDim - 1; ++j){
1702 arrowline += toString<tcoord_t>(partCenters[j][i]) +
",";
1704 arrowline += toString<tcoord_t>(partCenters[coordDim -1][i]) +
" as 5\n";
1711 ff <<
"replot\n pause -1" << endl;
void setParams(int dimension_, int heapsize)
CommunicationModel Base Class that performs mapping between the coordinate partitioning result...
ArrayRCP< procId_t > task_to_proc
void ithPermutation(const IT n, IT i, IT *perm)
static procId_t umpa_uRandom(procId_t l, int &_u_umpa_seed)
void doMapping(int myRank)
doMapping function, calls getMapping function of communicationModel object.
CoordinateCommunicationModel< pcoord_t, tcoord_t, procId_t > * proc_task_comm
Time an algorithm (or other entity) as a whole.
RCP< Comm< int > > create_subCommunicatior()
creates and returns the subcommunicator for the processor group.
void update_visit_order(procId_t *visitOrder, procId_t n, int &_u_umpa_seed, procId_t rndm)
pcoord_t ** getProcCoords() const
getProcDim function returns the coordinates of processors in two dimensional array.
WT getDistance(IT index, WT **elementCoords)
const Teuchos::Comm< int > * comm
virtual size_t getLocalNumberOfParts() const
Returns the number of parts to be assigned to this process.
virtual void getMapping(int myRank, RCP< const Environment > env, ArrayRCP< procId_t > &proc_to_task_xadj, ArrayRCP< procId_t > &proc_to_task_adj, ArrayRCP< procId_t > &task_to_proc) const =0
Function is called whenever nprocs > no_task. Function returns only the subset of processors that are...
Zoltan2::StridedData< lno_t, scalar_t > input_t
const Zoltan2::PartitioningSolution< Adapter > * soln
ArrayRCP< procId_t > task_communication_xadj
bool getNewCenters(WT **coords)
ArrayView< procId_t > getAssignedTaksForProc(procId_t procId)
CoordinateCommunicationModel(int pcoord_dim_, pcoord_t **pcoords_, int tcoord_dim_, tcoord_t **tcoords_, procId_t no_procs_, procId_t no_tasks_)
Class Constructor:
zoltan2_partId_t partId_t
procId_t getNTasks() const
double getCommunicationCostMetric()
ArrayRCP< procId_t > proc_to_task_xadj
void getSolutionCenterCoordinates(const Environment *envConst, const Teuchos::Comm< int > *comm, const Zoltan2::CoordinateModel< typename Adapter::base_adapter_t > *coords, const Zoltan2::PartitioningSolution< Adapter > *soln_, int coordDim, partId_t ntasks, scalar_t **partCenters)
void getMinDistanceCluster(IT *procPermutation)
virtual ~CoordinateTaskMapper()
CoordinateTaskMapper(const Environment *env_, const Teuchos::Comm< int > *comm_, const MachineRepresentation< pcoord_t > *machine_, int taskDim, procId_t taskCount, tcoord_t **taskCoords)
Constructor. Given the machine object and task centers, performs mapping.
procId_t getNProcs() const
virtual double getProcDistance(int procId1, int procId2) const =0
CoordinateCommunicationModel()
void timerStop(TimerType tt, const char *timerName) const
Stop a named timer.
This class provides geometric coordinates with optional weights to the Zoltan2 algorithm.
CoordinateTaskMapper(const Environment *env_, CoordinateCommunicationModel< pcoord_t, tcoord_t, procId_t > *proc_task_comm_)
Constructor. Sequential Constructor for test.
virtual ~CommunicationModel()
size_t getCoordinates(ArrayView< const gno_t > &Ids, ArrayView< input_t > &xyz, ArrayView< input_t > &wgts) const
Returns the coordinate ids, values and optional weights.
PartitionMapping maps a solution or an input distribution to ranks.
const zoltan2_partId_t * getPartList() const
Returns the part list corresponding to the global ID list.
A PartitioningSolution is a solution to a partitioning problem.
void copyCoordinates(IT *permutation)
void getClosestSubset(procId_t *proc_permutation, procId_t nprocs, procId_t ntasks) const
Function is called whenever nprocs > no_task. Function returns only the subset of processors that are...
Zoltan2_ReduceBestMapping Class, reduces the minimum cost mapping, ties breaks with minimum proc id...
procId_t getAssignedProcForTask(procId_t taskId)
getAssignedProcForTask function, returns the assigned processor id for the given task ...
void reduce(const Ordinal count, const T inBuffer[], T inoutBuffer[]) const
Implement Teuchos::ValueTypeReductionOp interface.
The StridedData class manages lists of weights or coordinates.
ArrayRCP< procId_t > task_communication_adj
virtual double getProcDistance(int procId1, int procId2) const
CommunicationModel(procId_t no_procs_, procId_t no_tasks_)
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
void addPoint(IT index, WT distance)
bool getNewCenters(WT *center, WT **coords, int dimension)
MachineRepresentation Class Finds the coordinate of the processor. Used to find the processor coordin...
virtual void getMapping(int myRank, RCP< const Environment > env, ArrayRCP< procId_t > &rcp_proc_to_task_xadj, ArrayRCP< procId_t > &rcp_proc_to_task_adj, ArrayRCP< procId_t > &rcp_task_to_proc) const
Function is called whenever nprocs > no_task. Function returns only the subset of processors that are...
size_t getLocalNumCoordinates() const
Returns the number of coordinates on this process.
virtual void getProcsForPart(partId_t taskId, int &numProcs, int *procs) const
getAssignedProcForTask function, returns the assigned tasks with the number of tasks.
CoordinateModelInput Class that performs mapping between the coordinate partitioning result and mpi r...
const gid_t * getIdList() const
Returns the user's global ID list.
CoordinateTaskMapper(const Teuchos::Comm< int > *comm_, const MachineRepresentation< pcoord_t > *machine_, const Zoltan2::Model< typename Adapter::base_adapter_t > *model_, const Zoltan2::PartitioningSolution< Adapter > *soln_, const Environment *envConst)
Constructor. When this constructor is called, in order to calculate the communication metric...
void getBestMapping()
finds the lowest cost mapping and broadcasts solution to everyone.
virtual ~CoordinateCommunicationModel()
Zoltan2_ReduceBestMapping()
Default Constructor.
CoordinateTaskMapper(const Teuchos::Comm< int > *comm_, const MachineRepresentation< pcoord_t > *machine_, const Zoltan2::Model< typename Adapter::base_adapter_t > *model_, const Zoltan2::PartitioningSolution< Adapter > *soln_, const Environment *envConst_, ArrayRCP< procId_t >task_communication_xadj_, ArrayRCP< procId_t >task_communication_adj_)
Constructor When this constructor is called, it is assumed that the communication graph is already co...
void writeGnuPlot(const Teuchos::Comm< int > *comm_, const Zoltan2::PartitioningSolution< Adapter > *soln_, int coordDim, tcoord_t **partCenters)
int getProcDim() const
getProcDim function returns the dimension of the physical processor layout.
KmeansHeap Class, max heap, but holds the minimum values.
void fillContinousArray(T *arr, size_t arrSize, T *val)
fillContinousArray function
void push_down(IT index_on_heap)
void calculateCommunicationCost(procId_t *task_to_proc, procId_t *task_communication_xadj, procId_t *task_communication_adj)
size_t getActualGlobalNumberOfParts() const
Returns the actual global number of parts provided in setParts().
KMeansAlgorithm Class that performs clustering of the coordinates, and returns the closest set of coo...
void timerStart(TimerType tt, const char *timerName) const
Start a named timer.
KMeansAlgorithm(int dim_, IT numElements_, WT **elementCoords_, IT required_elements_)
KMeansAlgorithm Constructor.
ArrayRCP< procId_t > proc_to_task_adj
int getNumProcs() const
getNumProcs function returns the number of processors.
void copyCoordinates(IT *permutation)
Contains the PQ-jagged algorthm.
size_t getTargetGlobalNumberOfParts() const
Returns the global number of parts desired in the solution.
double getCommunicationCostMetric()
virtual void getPartsForProc(int procId, partId_t &numParts, partId_t *parts) const
getAssignedProcForTask function, returns the assigned tasks with the number of tasks.
void getGridCommunicationGraph(partId_t taskCount, partId_t *&task_comm_xadj, partId_t *&task_comm_adj, vector< int > grid_dims)
void setHeapsize(IT heapsize_)
void writeMapping2(int myRank)