Changeset 1642 for XIOS/dev/branch_openmp/src/distribution_client.cpp
- Timestamp:
- 01/23/19 10:31:44 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/branch_openmp/src/distribution_client.cpp
r1460 r1642 14 14 : CDistribution(rank, 0) 15 15 , axisDomainOrder_() 16 , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_() ,nZoomBegin_(), nZoomEnd_()17 , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_() , domainMasks_(), axisMasks_()16 , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_() 17 , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_() 18 18 , gridMask_(), indexMap_() 19 19 , isDataDistributed_(true), axisNum_(0), domainNum_(0) … … 22 22 , infoIndex_(), isComputed_(false) 23 23 , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_() 24 , element ZoomMask_(), elementNLocal_(), elementNGlobal_()24 , elementNLocal_(), elementNGlobal_() 25 25 { 26 26 readDistributionInfo(grid); … … 36 36 GlobalLocalMap void2 ; 37 37 std::vector<int> void3 ; 38 std::vector< int> void4 ;38 std::vector<bool> void4 ; 39 39 40 40 globalLocalDataSendToServerMap_.swap(void1) ; … … 61 61 // Then check mask of grid 62 62 int gridDim = domList.size() * 2 + axisList.size(); 63 grid->checkMask();64 63 switch (gridDim) { 65 64 case 0: … … 68 67 break; 69 68 case 1: 70 readGridMaskInfo(grid->mask_1d);69 if (!grid->mask_1d.isEmpty()) readGridMaskInfo(grid->mask_1d); 71 70 break; 72 71 case 2: 73 readGridMaskInfo(grid->mask_2d);72 if (!grid->mask_2d.isEmpty()) readGridMaskInfo(grid->mask_2d); 74 73 break; 75 74 case 3: 76 readGridMaskInfo(grid->mask_3d);75 if (!grid->mask_3d.isEmpty()) readGridMaskInfo(grid->mask_3d); 77 76 break; 78 77 case 4: 79 readGridMaskInfo(grid->mask_4d);78 if (!grid->mask_4d.isEmpty()) readGridMaskInfo(grid->mask_4d); 80 79 break; 81 80 case 5: 82 readGridMaskInfo(grid->mask_5d);81 if (!grid->mask_5d.isEmpty()) readGridMaskInfo(grid->mask_5d); 83 82 break; 84 83 case 6: 85 readGridMaskInfo(grid->mask_6d);84 if (!grid->mask_6d.isEmpty()) readGridMaskInfo(grid->mask_6d); 86 85 break; 87 86 case 7: 88 readGridMaskInfo(grid->mask_7d);87 if (!grid->mask_7d.isEmpty()) readGridMaskInfo(grid->mask_7d); 89 88 break; 90 89 default: … … 117 116 axisDomainOrder_ = axisDomainOrder; 118 117 119 // Each domain or axis has its mask, of course120 domainMasks_.resize(domainNum_);121 for (int i = 0; i < domainNum_;++i)122 {123 domainMasks_[i].resize(domList[i]->domainMask.numElements());124 domainMasks_[i] = domList[i]->domainMask;125 }126 127 axisMasks_.resize(axisNum_);128 for (int i = 0; i < axisNum_; ++i)129 {130 axisMasks_[i].resize(axisList[i]->mask.numElements());131 axisMasks_[i] = axisList[i]->mask;132 }133 134 118 // Because domain and axis can be in any order (axis1, domain1, axis2, axis3, ) 135 119 // their position should be specified. In axisDomainOrder, domain == true, axis == false … … 153 137 nBeginLocal_.resize(this->dims_,0); 154 138 nBeginGlobal_.resize(this->dims_,0); 155 nZoomBegin_.resize(this->dims_);156 nZoomEnd_.resize(this->dims_);157 139 158 140 // Data_n_index of domain or axis (For now, axis uses its size as data_n_index … … 172 154 elementGlobalIndex_.resize(numElement_); 173 155 elementIndexData_.resize(numElement_); 174 elementZoomMask_.resize(numElement_);175 156 elementNLocal_.resize(numElement_); 176 157 elementNGlobal_.resize(numElement_); … … 195 176 nBeginLocal_.at(indexMap_[idx]+1) = 0; 196 177 nBeginGlobal_.at(indexMap_[idx]+1) = domList[domIndex]->jbegin; 197 nZoomBegin_.at((indexMap_[idx]+1)) = 0; //domList[domIndex]->global_zoom_jbegin;198 nZoomEnd_.at((indexMap_[idx]+1)) = domList[domIndex]->nj_glo.getValue()- 1; //domList[domIndex]->global_zoom_jbegin + domList[domIndex]->global_zoom_nj-1;199 178 200 179 dataBegin_.at(indexMap_[idx]+1) = domList[domIndex]->data_jbegin.getValue(); … … 207 186 nBeginLocal_.at(indexMap_[idx]) = 0; 208 187 nBeginGlobal_.at(indexMap_[idx]) = domList[domIndex]->ibegin; 209 nZoomBegin_.at((indexMap_[idx])) = 0; // domList[domIndex]->global_zoom_ibegin;210 nZoomEnd_.at((indexMap_[idx])) = domList[domIndex]->ni_glo.getValue() -1; //domList[domIndex]->global_zoom_ibegin + domList[domIndex]->global_zoom_ni-1;211 188 212 189 dataBegin_.at(indexMap_[idx]) = domList[domIndex]->data_ibegin.getValue(); … … 229 206 nBeginLocal_.at(indexMap_[idx]) = 0; 230 207 nBeginGlobal_.at(indexMap_[idx]) = axisList[axisIndex]->begin.getValue(); 231 nZoomBegin_.at((indexMap_[idx])) = 0; //axisList[axisIndex]->global_zoom_begin;232 nZoomEnd_.at((indexMap_[idx])) = axisList[axisIndex]->n_glo.getValue() - 1; //axisList[axisIndex]->global_zoom_begin + axisList[axisIndex]->global_zoom_n-1;233 208 234 209 dataBegin_.at(indexMap_[idx]) = axisList[axisIndex]->data_begin.getValue(); … … 251 226 nBeginLocal_.at(indexMap_[idx]) = 0; 252 227 nBeginGlobal_.at(indexMap_[idx]) = 1; 253 nZoomBegin_.at((indexMap_[idx])) = 0;254 nZoomEnd_.at((indexMap_[idx])) = 0;255 228 256 229 dataBegin_.at(indexMap_[idx]) = 0; … … 293 266 294 267 if ((iIdx >= nBeginLocal_[indexMap_[i]]) && (iIdx < nLocal_[indexMap_[i]]) && 295 (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1]) && 296 (domainMasks_[idxDomain](iIdx + jIdx*nLocal_[indexMap_[i]]))) 268 (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1])) 297 269 { 298 270 ++count; … … 303 275 elementLocalIndex_[i].resize(count); 304 276 elementGlobalIndex_[i].resize(count); 305 elementZoomMask_[i].resize(count);306 elementZoomMask_[i] = false;307 277 count = 0; 308 278 CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 309 CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i];310 279 CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 311 280 CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; … … 319 288 localIndex = tmpLocalElementIndex(count) = iIdx + jIdx * nLocal_[indexMap_[i]]; 320 289 tmpGlobalElementIndex(count) = (infoIndex_[indexMap_[i]])(localIndex) + ((infoIndex_[indexMap_[i]+1])(localIndex))*nGlob_[indexMap_[i]]; 321 if ((((infoIndex_[indexMap_[i]])(localIndex)) <= nZoomEnd_[indexMap_[i]])322 && (nZoomBegin_[indexMap_[i]] <= ((infoIndex_[indexMap_[i]])(localIndex)))323 && (((infoIndex_[indexMap_[i]+1])(localIndex)) <= nZoomEnd_[indexMap_[i]+1])324 && (nZoomBegin_[indexMap_[i]+1] <= ((infoIndex_[indexMap_[i]+1])(localIndex))))325 {326 tmpZoomMaskElement(count) = true;327 }328 290 ++count; 329 291 } … … 346 308 elementIndexData_[i].resize(dataNIndex_[i]); 347 309 elementIndexData_[i] = false; 348 int iIdx = 0, count = 0 , localIndex = 0;310 int iIdx = 0, count = 0; 349 311 for (int j = 0; j < dataNIndex_[i]; ++j) 350 312 { 351 313 iIdx = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 352 314 if ((iIdx >= nBeginLocal_[indexMap_[i]]) && 353 (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx)))315 (iIdx < nLocal_[indexMap_[i]]) )//&& (axisMasks_[idxAxis](iIdx))) 354 316 { 355 317 ++count; … … 360 322 elementLocalIndex_[i].resize(count); 361 323 elementGlobalIndex_[i].resize(count); 362 elementZoomMask_[i].resize(count);363 elementZoomMask_[i] = false;364 324 count = 0; 365 325 CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 366 CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i];367 326 CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 368 327 CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; … … 373 332 iIdx = tmpLocalElementIndex(count) = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 374 333 tmpGlobalElementIndex(count) = (infoIndex_[indexMap_[i]])(iIdx); 375 if ((((infoIndex_[indexMap_[i]])(iIdx)) <= nZoomEnd_[indexMap_[i]])376 && (nZoomBegin_[indexMap_[i]] <= ((infoIndex_[indexMap_[i]])(iIdx))))377 {378 tmpZoomMaskElement(count) = true;379 }380 334 ++count; 381 335 } … … 404 358 elementGlobalIndex_[i].resize(count); 405 359 elementGlobalIndex_[i] = 0; 406 elementZoomMask_[i].resize(count);407 elementZoomMask_[i] = true;408 360 } 409 361 } … … 440 392 std::vector<StdSize> currentGlobalIndex(numElement_,0); 441 393 int innerLoopSize = eachElementSize[0]; 442 size_t idx = 0, indexLocalDataOnClientCount = 0 , indexSend2ServerCount = 0;394 size_t idx = 0, indexLocalDataOnClientCount = 0; 443 395 size_t ssize = 1; 396 444 397 for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; 445 while (idx < ssize) 446 { 447 for (int i = 0; i < numElement_-1; ++i) 448 { 449 if (idxLoop[i] == eachElementSize[i]) 450 { 451 idxLoop[i] = 0; 452 ++idxLoop[i+1]; 453 } 454 } 455 456 // Find out outer index 457 // Depending the inner-most element is axis or domain, 458 // The outer loop index begins correspondingly at one (1) or zero (0) 459 for (int i = 1; i < numElement_; ++i) 460 { 461 currentIndex[i] = elementLocalIndex_[i](idxLoop[i]); 462 } 463 464 // Inner most index 465 for (int i = 0; i < innerLoopSize; ++i) 466 { 467 int gridMaskIndex = 0; 468 currentIndex[0] = elementLocalIndex_[0](i); 469 for (int k = 0; k < this->numElement_; ++k) 470 { 471 gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 472 } 473 474 if (gridMask_(gridMaskIndex)) 475 { 476 ++indexLocalDataOnClientCount; 477 bool isIndexOnServer = true; 478 479 for (int idxElement = 0; idxElement < this->numElement_; ++idxElement) 480 { 481 isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](idxLoop[idxElement]); 482 } 483 if (isIndexOnServer) ++indexSend2ServerCount; 484 } 485 } 486 idxLoop[0] += innerLoopSize; 487 idx += innerLoopSize; 488 } 489 490 // Now allocate these arrays 491 localDataIndex_.resize(indexLocalDataOnClientCount); 492 localMaskIndex_.resize(indexSend2ServerCount); 493 localMaskedDataIndex_.resize(indexSend2ServerCount); 494 globalDataIndex_.rehash(std::ceil(indexLocalDataOnClientCount/globalDataIndex_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); 495 globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); 398 399 localDataIndex_.resize(ssize); 400 if (!gridMask_.isEmpty()) localMaskIndex_.resize(ssize); 401 localMaskedDataIndex_.resize(ssize); 402 globalDataIndex_.rehash(std::ceil(ssize/globalDataIndex_.max_load_factor())); 403 globalLocalDataSendToServerMap_.rehash(std::ceil(ssize/globalLocalDataSendToServerMap_.max_load_factor())); 404 496 405 497 406 // We need to loop with data index 498 407 idxLoop.assign(numElement_,0); 499 idx = indexLocalDataOnClientCount = indexSend2ServerCount =0;408 idx = indexLocalDataOnClientCount = 0; 500 409 ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 501 410 innerLoopSize = dataNIndex_[0]; … … 550 459 if (isCurrentIndexDataCorrect) 551 460 { 552 int gridMaskIndex = 0; 553 for (int k = 0; k < this->numElement_; ++k) 461 bool maskTmp = true; 462 bool maskGridTmp = true; 463 size_t globalIndex = 0; 464 for (int k = 0; k < numElement_; ++k) 554 465 { 555 g ridMaskIndex += (currentIndex[k])*elementNLocal_[k];466 globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 556 467 } 557 558 if (gridMask_(gridMaskIndex)) 468 globalDataIndex_[globalIndex] = indexLocalDataOnClientCount; 469 localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 470 globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; 471 localMaskedDataIndex_[indexLocalDataOnClientCount] = indexLocalDataOnClientCount; 472 473 // Grid mask: unmasked values will be replaces by NaN and then all values will be sent 474 if (!gridMask_.isEmpty()) 559 475 { 560 size_t globalIndex = 0;561 for (int k = 0; k < numElement_; ++k)476 int gridMaskIndex = 0; 477 for (int k = 0; k < this->numElement_; ++k) 562 478 { 563 g lobalIndex += (currentGlobalIndex[k])*elementNGlobal_[k];479 gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 564 480 } 565 globalDataIndex_[globalIndex] = indexLocalDataOnClientCount; 566 localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 567 bool isIndexOnServer = true; 568 for (int idxElement = 0; idxElement < this->numElement_; ++idxElement) 569 { 570 isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](correctIndexOfElement[idxElement]); 571 } 572 573 if (isIndexOnServer) 574 { 575 globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; 576 localMaskIndex_[indexSend2ServerCount] = gridMaskIndex; 577 localMaskedDataIndex_[indexSend2ServerCount] = indexLocalDataOnClientCount; 578 ++indexSend2ServerCount; 579 } 580 ++indexLocalDataOnClientCount; 481 maskGridTmp = gridMask_(gridMaskIndex); 482 if (maskGridTmp) 483 localMaskIndex_[indexLocalDataOnClientCount] = true; 484 else 485 localMaskIndex_[indexLocalDataOnClientCount] = false; 581 486 } 487 488 ++indexLocalDataOnClientCount; 489 582 490 } 583 491 ++countLocalData; … … 585 493 } 586 494 } 495 else countLocalData+=innerLoopSize ; 496 587 497 idxLoop[0] += innerLoopSize; 588 498 idx += innerLoopSize; … … 612 522 const int& dataDim, const int& ni, int& j) 613 523 { 524 int i; 614 525 int tempI = dataIIndex + dataIBegin, 615 526 tempJ = (dataJIndex + dataJBegin); 616 int i = (dataDim == 1) ? (tempI) % ni 617 : (tempI) ; 618 j = (dataDim == 1) ? (tempI) / ni 619 : (tempJ) ; 620 527 if (ni == 0) 528 { 529 i = -1; 530 j = -1; 531 return i; 532 } 533 if ((tempI < 0) || (tempJ < 0)) 534 { 535 i = -1; 536 j = -1; 537 return i; 538 } 539 else 540 { 541 i = (dataDim == 1) ? (tempI) % ni : (tempI) ; 542 j = (dataDim == 1) ? (tempI) / ni : (tempJ) ; 543 } 621 544 return i; 622 545 } … … 631 554 int CDistributionClient::getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni) 632 555 { 633 int tempI = dataIndex + dataBegin; 634 return ((tempI)%ni); 556 if (ni == 0) 557 { 558 return -1; 559 } 560 int tempI = dataIndex; 561 if ((tempI < 0) || (tempI > ni)) 562 return -1; 563 else 564 return tempI; 635 565 } 636 566 … … 662 592 Return local mask index of client 663 593 */ 664 const std::vector< int>& CDistributionClient::getLocalMaskIndexOnClient()594 const std::vector<bool>& CDistributionClient::getLocalMaskIndexOnClient() 665 595 { 666 596 if (!isComputed_) createGlobalIndexSendToServer();
Note: See TracChangeset
for help on using the changeset viewer.