Ignore:
Timestamp:
01/23/19 10:31:44 (5 years ago)
Author:
yushan
Message:

dev on ADA. add flag switch _usingEP/_usingMPI

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/branch_openmp/src/distribution_client.cpp

    r1460 r1642  
    1414   : CDistribution(rank, 0) 
    1515   , 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_() 
    1818   , gridMask_(), indexMap_() 
    1919   , isDataDistributed_(true), axisNum_(0), domainNum_(0) 
     
    2222   , infoIndex_(), isComputed_(false) 
    2323   , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_() 
    24    , elementZoomMask_(), elementNLocal_(), elementNGlobal_() 
     24   , elementNLocal_(), elementNGlobal_() 
    2525{ 
    2626  readDistributionInfo(grid); 
     
    3636  GlobalLocalMap void2 ; 
    3737  std::vector<int> void3 ; 
    38   std::vector<int> void4 ; 
     38  std::vector<bool> void4 ; 
    3939 
    4040  globalLocalDataSendToServerMap_.swap(void1) ; 
     
    6161  // Then check mask of grid 
    6262  int gridDim = domList.size() * 2 + axisList.size(); 
    63   grid->checkMask(); 
    6463  switch (gridDim) { 
    6564    case 0: 
     
    6867      break; 
    6968    case 1: 
    70       readGridMaskInfo(grid->mask_1d); 
     69      if (!grid->mask_1d.isEmpty()) readGridMaskInfo(grid->mask_1d); 
    7170      break; 
    7271    case 2: 
    73       readGridMaskInfo(grid->mask_2d); 
     72      if (!grid->mask_2d.isEmpty()) readGridMaskInfo(grid->mask_2d); 
    7473      break; 
    7574    case 3: 
    76       readGridMaskInfo(grid->mask_3d); 
     75      if (!grid->mask_3d.isEmpty()) readGridMaskInfo(grid->mask_3d); 
    7776      break; 
    7877    case 4: 
    79       readGridMaskInfo(grid->mask_4d); 
     78      if (!grid->mask_4d.isEmpty()) readGridMaskInfo(grid->mask_4d); 
    8079      break; 
    8180    case 5: 
    82       readGridMaskInfo(grid->mask_5d); 
     81      if (!grid->mask_5d.isEmpty()) readGridMaskInfo(grid->mask_5d); 
    8382      break; 
    8483    case 6: 
    85       readGridMaskInfo(grid->mask_6d); 
     84      if (!grid->mask_6d.isEmpty()) readGridMaskInfo(grid->mask_6d); 
    8685      break; 
    8786    case 7: 
    88       readGridMaskInfo(grid->mask_7d); 
     87      if (!grid->mask_7d.isEmpty()) readGridMaskInfo(grid->mask_7d); 
    8988      break; 
    9089    default: 
     
    117116  axisDomainOrder_ = axisDomainOrder; 
    118117 
    119   // Each domain or axis has its mask, of course 
    120   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  
    134118  // Because domain and axis can be in any order (axis1, domain1, axis2, axis3, ) 
    135119  // their position should be specified. In axisDomainOrder, domain == true, axis == false 
     
    153137  nBeginLocal_.resize(this->dims_,0); 
    154138  nBeginGlobal_.resize(this->dims_,0); 
    155   nZoomBegin_.resize(this->dims_); 
    156   nZoomEnd_.resize(this->dims_); 
    157139 
    158140  // Data_n_index of domain or axis (For now, axis uses its size as data_n_index 
     
    172154  elementGlobalIndex_.resize(numElement_); 
    173155  elementIndexData_.resize(numElement_); 
    174   elementZoomMask_.resize(numElement_); 
    175156  elementNLocal_.resize(numElement_); 
    176157  elementNGlobal_.resize(numElement_); 
     
    195176      nBeginLocal_.at(indexMap_[idx]+1) = 0; 
    196177      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; 
    199178 
    200179      dataBegin_.at(indexMap_[idx]+1) = domList[domIndex]->data_jbegin.getValue(); 
     
    207186      nBeginLocal_.at(indexMap_[idx]) = 0; 
    208187      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; 
    211188 
    212189      dataBegin_.at(indexMap_[idx]) = domList[domIndex]->data_ibegin.getValue(); 
     
    229206      nBeginLocal_.at(indexMap_[idx]) = 0; 
    230207      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; 
    233208 
    234209      dataBegin_.at(indexMap_[idx]) = axisList[axisIndex]->data_begin.getValue(); 
     
    251226      nBeginLocal_.at(indexMap_[idx]) = 0; 
    252227      nBeginGlobal_.at(indexMap_[idx]) = 1; 
    253       nZoomBegin_.at((indexMap_[idx])) = 0; 
    254       nZoomEnd_.at((indexMap_[idx])) = 0; 
    255228 
    256229      dataBegin_.at(indexMap_[idx]) = 0; 
     
    293266 
    294267        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])) 
    297269        { 
    298270          ++count; 
     
    303275      elementLocalIndex_[i].resize(count); 
    304276      elementGlobalIndex_[i].resize(count); 
    305       elementZoomMask_[i].resize(count); 
    306       elementZoomMask_[i] = false; 
    307277      count = 0; 
    308278      CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 
    309       CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; 
    310279      CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 
    311280      CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; 
     
    319288          localIndex = tmpLocalElementIndex(count) = iIdx + jIdx * nLocal_[indexMap_[i]]; 
    320289          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           } 
    328290          ++count; 
    329291        } 
     
    346308      elementIndexData_[i].resize(dataNIndex_[i]); 
    347309      elementIndexData_[i] = false; 
    348       int iIdx = 0, count = 0, localIndex = 0; 
     310      int iIdx = 0, count = 0; 
    349311      for (int j = 0; j < dataNIndex_[i]; ++j) 
    350312      { 
    351313        iIdx = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 
    352314        if ((iIdx >= nBeginLocal_[indexMap_[i]]) && 
    353            (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx))) 
     315           (iIdx < nLocal_[indexMap_[i]]) )//&& (axisMasks_[idxAxis](iIdx))) 
    354316        { 
    355317          ++count; 
     
    360322      elementLocalIndex_[i].resize(count); 
    361323      elementGlobalIndex_[i].resize(count); 
    362       elementZoomMask_[i].resize(count); 
    363       elementZoomMask_[i] = false; 
    364324      count = 0; 
    365325      CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 
    366       CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; 
    367326      CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 
    368327      CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; 
     
    373332          iIdx = tmpLocalElementIndex(count) = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 
    374333          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           } 
    380334          ++count; 
    381335        } 
     
    404358      elementGlobalIndex_[i].resize(count); 
    405359      elementGlobalIndex_[i] = 0; 
    406       elementZoomMask_[i].resize(count); 
    407       elementZoomMask_[i] = true; 
    408360    } 
    409361  } 
     
    440392  std::vector<StdSize> currentGlobalIndex(numElement_,0); 
    441393  int innerLoopSize = eachElementSize[0]; 
    442   size_t idx = 0, indexLocalDataOnClientCount = 0, indexSend2ServerCount = 0; 
     394  size_t idx = 0, indexLocalDataOnClientCount = 0; 
    443395  size_t ssize = 1; 
     396 
    444397  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 
    496405 
    497406  // We need to loop with data index 
    498407  idxLoop.assign(numElement_,0); 
    499   idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; 
     408  idx = indexLocalDataOnClientCount = 0; 
    500409  ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 
    501410  innerLoopSize = dataNIndex_[0]; 
     
    550459        if (isCurrentIndexDataCorrect) 
    551460        { 
    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) 
    554465          { 
    555             gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 
     466            globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 
    556467          } 
    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()) 
    559475          { 
    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) 
    562478            { 
    563               globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 
     479              gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 
    564480            } 
    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; 
    581486          } 
     487 
     488          ++indexLocalDataOnClientCount; 
     489 
    582490        } 
    583491        ++countLocalData; 
     
    585493      } 
    586494    } 
     495    else countLocalData+=innerLoopSize ; 
     496 
    587497    idxLoop[0] += innerLoopSize; 
    588498    idx += innerLoopSize; 
     
    612522                                        const int& dataDim, const int& ni, int& j) 
    613523{ 
     524  int i; 
    614525  int tempI = dataIIndex + dataIBegin, 
    615526      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  } 
    621544  return i; 
    622545} 
     
    631554int CDistributionClient::getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni) 
    632555{ 
    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; 
    635565} 
    636566 
     
    662592  Return local mask index of client 
    663593*/ 
    664 const std::vector<int>& CDistributionClient::getLocalMaskIndexOnClient() 
     594const std::vector<bool>& CDistributionClient::getLocalMaskIndexOnClient() 
    665595{ 
    666596  if (!isComputed_) createGlobalIndexSendToServer(); 
Note: See TracChangeset for help on using the changeset viewer.