Ignore:
Timestamp:
01/14/19 13:33:48 (5 years ago)
Author:
oabramkina
Message:

Merging dev to trunk. Major changes:

(1) Grid mask is applied in the source filter of clients: unmasked values are replaced by NaN. It is not reconstructed any more by servers.

(2) Domain/axis mask has been incorporated into data index, with only data index sent to servers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/distribution_client.cpp

    r1593 r1637  
    1515   , axisDomainOrder_() 
    1616   , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_() 
    17    , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() 
     17   , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_() 
    1818   , gridMask_(), indexMap_() 
    1919   , isDataDistributed_(true), axisNum_(0), domainNum_(0) 
     
    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: 
     
    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 
     
    282266 
    283267        if ((iIdx >= nBeginLocal_[indexMap_[i]]) && (iIdx < nLocal_[indexMap_[i]]) && 
    284            (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1]) && 
    285            (domainMasks_[idxDomain](iIdx + jIdx*nLocal_[indexMap_[i]]))) 
     268           (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1])) 
    286269        { 
    287270          ++count; 
     
    325308      elementIndexData_[i].resize(dataNIndex_[i]); 
    326309      elementIndexData_[i] = false; 
    327       int iIdx = 0, count = 0, localIndex = 0; 
     310      int iIdx = 0, count = 0; 
    328311      for (int j = 0; j < dataNIndex_[i]; ++j) 
    329312      { 
    330313        iIdx = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 
    331314        if ((iIdx >= nBeginLocal_[indexMap_[i]]) && 
    332            (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx))) 
     315           (iIdx < nLocal_[indexMap_[i]]) )//&& (axisMasks_[idxAxis](iIdx))) 
    333316        { 
    334317          ++count; 
     
    413396 
    414397  for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; 
    415   while (idx < ssize) 
    416   { 
    417     for (int i = 0; i < numElement_-1; ++i) 
    418     { 
    419       if (idxLoop[i] == eachElementSize[i]) 
    420       { 
    421         idxLoop[i] = 0; 
    422         ++idxLoop[i+1]; 
    423       } 
    424     } 
    425  
    426     // Find out outer index 
    427     // Depending the inner-most element is axis or domain, 
    428     // The outer loop index begins correspondingly at one (1) or zero (0) 
    429     for (int i = 1; i < numElement_; ++i) 
    430     { 
    431       currentIndex[i] = elementLocalIndex_[i](idxLoop[i]); 
    432     } 
    433  
    434     // Inner most index 
    435     for (int i = 0; i < innerLoopSize; ++i) 
    436     { 
    437       int gridMaskIndex = 0; 
    438       currentIndex[0] = elementLocalIndex_[0](i); 
    439  
    440       // If defined, iterate on grid mask 
    441       if (!gridMask_.isEmpty()) 
    442       { 
    443         for (int k = 0; k < this->numElement_; ++k) 
    444         { 
    445           gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 
    446         } 
    447         if (gridMask_(gridMaskIndex)) ++indexLocalDataOnClientCount; 
    448       } 
    449       // If grid mask is not defined, iterate on elements' mask 
    450       else 
    451       { 
    452         bool maskTmp = true; 
    453         int idxDomain = 0, idxAxis = 0; 
    454         for (int elem = 0; elem < numElement_; ++elem) 
    455         { 
    456           if (2 == axisDomainOrder_(elem)) 
    457           { 
    458             maskTmp = maskTmp && domainMasks_[idxDomain](currentIndex[elem]); 
    459             ++idxDomain; 
    460           } 
    461           else if (1 == axisDomainOrder_(elem)) 
    462           { 
    463             maskTmp = maskTmp && axisMasks_[idxAxis](currentIndex[elem]); 
    464             ++idxAxis; 
    465           } 
    466         } 
    467         if (maskTmp) ++indexLocalDataOnClientCount; 
    468       } 
    469  
    470     } 
    471     idxLoop[0] += innerLoopSize; 
    472     idx += innerLoopSize; 
    473   } 
    474  
    475   // Now allocate these arrays 
    476   localDataIndex_.resize(indexLocalDataOnClientCount); 
    477   localMaskIndex_.resize(indexLocalDataOnClientCount); 
    478   localMaskedDataIndex_.resize(indexLocalDataOnClientCount); 
    479   globalDataIndex_.rehash(std::ceil(indexLocalDataOnClientCount/globalDataIndex_.max_load_factor())); 
    480   globalLocalDataSendToServerMap_.rehash(std::ceil(indexLocalDataOnClientCount/globalLocalDataSendToServerMap_.max_load_factor())); 
     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 
    481405 
    482406  // We need to loop with data index 
     
    535459        if (isCurrentIndexDataCorrect) 
    536460        { 
    537           int gridMaskIndex = 0; 
    538           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) 
    539465          { 
    540             gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 
     466            globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 
    541467          } 
    542  
    543           bool maskTmp = true; 
    544           // If defined, apply grid mask 
    545          if (!gridMask_.isEmpty()) 
     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()) 
    546475          { 
    547             maskTmp =  gridMask_(gridMaskIndex); 
     476            int gridMaskIndex = 0; 
     477            for (int k = 0; k < this->numElement_; ++k) 
     478            { 
     479              gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 
     480            } 
     481            maskGridTmp =  gridMask_(gridMaskIndex); 
     482            if (maskGridTmp) 
     483              localMaskIndex_[indexLocalDataOnClientCount] = true; 
     484            else 
     485              localMaskIndex_[indexLocalDataOnClientCount] = false; 
    548486          } 
    549           // If grid mask is not defined, apply elements' mask 
    550           else 
    551           { 
    552             int idxDomain = 0, idxAxis = 0; 
    553             for (int elem = 0; elem < numElement_; ++elem) 
    554             { 
    555               if (2 == axisDomainOrder_(elem)) 
    556               { 
    557                 maskTmp = maskTmp && domainMasks_[idxDomain](currentIndex[elem]); 
    558                 ++idxDomain; 
    559               } 
    560               else if (1 == axisDomainOrder_(elem)) 
    561               { 
    562                 maskTmp = maskTmp && axisMasks_[idxAxis](currentIndex[elem]); 
    563                 ++idxAxis; 
    564               } 
    565             } 
    566           } 
    567  
    568           if (maskTmp) 
    569           { 
    570             size_t globalIndex = 0; 
    571             for (int k = 0; k < numElement_; ++k) 
    572             { 
    573               globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 
    574             } 
    575             globalDataIndex_[globalIndex] = indexLocalDataOnClientCount; 
    576             localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 
    577             globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; 
    578             localMaskIndex_[indexLocalDataOnClientCount] = gridMaskIndex; 
    579             localMaskedDataIndex_[indexLocalDataOnClientCount] = indexLocalDataOnClientCount; 
    580             ++indexLocalDataOnClientCount; 
    581           } 
     487 
     488          ++indexLocalDataOnClientCount; 
     489 
    582490        } 
    583491        ++countLocalData; 
     
    586494    } 
    587495    else countLocalData+=innerLoopSize ; 
    588      
     496 
    589497    idxLoop[0] += innerLoopSize; 
    590498    idx += innerLoopSize; 
     
    614522                                        const int& dataDim, const int& ni, int& j) 
    615523{ 
     524  int i; 
    616525  int tempI = dataIIndex + dataIBegin, 
    617526      tempJ = (dataJIndex + dataJBegin); 
    618527  if (ni == 0) 
    619528  { 
    620     int i = 0; 
    621     j = 0; 
     529    i = -1; 
     530    j = -1; 
    622531    return i; 
    623532  } 
    624   int i = (dataDim == 1) ? (tempI) % ni 
    625                          : (tempI) ; 
    626   j = (dataDim == 1) ? (tempI) / ni 
    627                      : (tempJ) ; 
    628  
     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  } 
    629544  return i; 
    630545} 
     
    643558    return -1; 
    644559  } 
    645   int tempI = dataIndex + dataBegin; 
     560  int tempI = dataIndex; 
    646561  if ((tempI < 0) || (tempI > ni)) 
    647562    return -1; 
     
    677592  Return local mask index of client 
    678593*/ 
    679 const std::vector<int>& CDistributionClient::getLocalMaskIndexOnClient() 
     594const std::vector<bool>& CDistributionClient::getLocalMaskIndexOnClient() 
    680595{ 
    681596  if (!isComputed_) createGlobalIndexSendToServer(); 
Note: See TracChangeset for help on using the changeset viewer.