Ignore:
Timestamp:
08/30/17 15:33:51 (7 years ago)
Author:
mhnguyen
Message:

Various bug fixes on mask and zoom

+) Rearrange local index on the receiving side to be coherent global index
+) Include masking information in compress data (data_index) on the receiving side
+) Correct zoom to work in case there are several (not all) processes participating to write data

Test
+) On Curie
+) Simple test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/XIOS_DEV_CMIP6/src/node/domain.cpp

    r1236 r1249  
    8686     \return the number of indexes written by each server 
    8787   */ 
    88    int CDomain::getNumberWrittenIndexes() const 
    89    { 
    90      return numberWrittenIndexes_; 
     88   int CDomain::getNumberWrittenIndexes(MPI_Comm writtenCom) 
     89   { 
     90     int writtenSize; 
     91     MPI_Comm_size(writtenCom, &writtenSize); 
     92     return numberWrittenIndexes_[writtenSize]; 
    9193   } 
    9294 
     
    9597     \return the total number of indexes written by the servers 
    9698   */ 
    97    int CDomain::getTotalNumberWrittenIndexes() const 
    98    { 
    99      return totalNumberWrittenIndexes_; 
     99   int CDomain::getTotalNumberWrittenIndexes(MPI_Comm writtenCom) 
     100   { 
     101     int writtenSize; 
     102     MPI_Comm_size(writtenCom, &writtenSize); 
     103     return totalNumberWrittenIndexes_[writtenSize]; 
    100104   } 
    101105 
     
    104108     \return the offset of indexes written by each server 
    105109   */ 
    106    int CDomain::getOffsetWrittenIndexes() const 
    107    { 
    108      return offsetWrittenIndexes_; 
     110   int CDomain::getOffsetWrittenIndexes(MPI_Comm writtenCom) 
     111   { 
     112     int writtenSize; 
     113     MPI_Comm_size(writtenCom, &writtenSize); 
     114     return offsetWrittenIndexes_[writtenSize]; 
     115   } 
     116 
     117   CArray<int, 1>& CDomain::getCompressedIndexToWriteOnServer(MPI_Comm writtenCom) 
     118   { 
     119     int writtenSize; 
     120     MPI_Comm_size(writtenCom, &writtenSize); 
     121     return compressedIndexToWriteOnServer[writtenSize]; 
    109122   } 
    110123 
     
    14971510   void CDomain::checkArea(void) 
    14981511   { 
    1499      bool hasAreaValue = (0 != areavalue.numElements()); 
    1500      hasArea = !area.isEmpty() || !areavalue.isEmpty(); 
    1501      if (hasArea) 
     1512     bool hasAreaValue = (!areavalue.isEmpty() && 0 != areavalue.numElements()); 
     1513     hasArea = !area.isEmpty(); 
     1514     if (hasArea && !hasAreaValue) 
    15021515     { 
    15031516       if (area.extent(0) != ni || area.extent(1) != nj) 
     
    19021915      } 
    19031916       
    1904       if (isCompressible()) 
    1905       { 
    1906         nbWritten = 0; 
    1907         boost::unordered_map<size_t,size_t> localGlobalIndexMap; 
    1908         for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 
    1909         { 
    1910           indGlo = *itSrv; 
    1911           if (ite != globalLocalIndexMap_.find(indGlo)) 
    1912           { 
    1913             localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 
    1914             ++nbWritten; 
    1915           }                  
    1916         } 
    1917  
    1918         nbWritten = 0; 
    1919         for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
    1920         { 
    1921           if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
    1922           { 
    1923             ++nbWritten; 
    1924           } 
    1925         } 
    1926  
    1927         compressedIndexToWriteOnServer.resize(nbWritten); 
    1928         nbWritten = 0; 
    1929         for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
    1930         { 
    1931           if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
    1932           { 
    1933             compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 
    1934             ++nbWritten; 
    1935           } 
    1936         } 
    1937  
    1938         numberWrittenIndexes_ = nbWritten; 
    1939         if (isDistributed()) 
    1940         {             
    1941           MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
    1942           MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
    1943           offsetWrittenIndexes_ -= numberWrittenIndexes_; 
    1944         } 
    1945         else 
    1946           totalNumberWrittenIndexes_ = numberWrittenIndexes_; 
    1947       }       
    1948    } 
     1917      // if (isCompressible()) 
     1918      // { 
     1919      //   nbWritten = 0; 
     1920      //   boost::unordered_map<size_t,size_t> localGlobalIndexMap; 
     1921      //   for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 
     1922      //   { 
     1923      //     indGlo = *itSrv; 
     1924      //     if (ite != globalLocalIndexMap_.find(indGlo)) 
     1925      //     { 
     1926      //       localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 
     1927      //       ++nbWritten; 
     1928      //     }                  
     1929      //   } 
     1930 
     1931      //   nbWritten = 0; 
     1932      //   for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
     1933      //   { 
     1934      //     if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
     1935      //     { 
     1936      //       ++nbWritten; 
     1937      //     } 
     1938      //   } 
     1939 
     1940      //   compressedIndexToWriteOnServer.resize(nbWritten); 
     1941      //   nbWritten = 0; 
     1942      //   for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
     1943      //   { 
     1944      //     if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
     1945      //     { 
     1946      //       compressedIndexToWriteOnServer(nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 
     1947      //       ++nbWritten; 
     1948      //     } 
     1949      //   } 
     1950 
     1951      //   numberWrittenIndexes_ = nbWritten; 
     1952      //   if (isDistributed()) 
     1953      //   {             
     1954      //     MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     1955      //     MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); 
     1956      //     offsetWrittenIndexes_ -= numberWrittenIndexes_; 
     1957      //   } 
     1958      //   else 
     1959      //     totalNumberWrittenIndexes_ = numberWrittenIndexes_; 
     1960      // }       
     1961   } 
     1962 
     1963  void CDomain::computeWrittenCompressedIndex(MPI_Comm writtenComm) 
     1964  { 
     1965    int writtenCommSize; 
     1966    MPI_Comm_size(writtenComm, &writtenCommSize); 
     1967    if (compressedIndexToWriteOnServer.find(writtenCommSize) != compressedIndexToWriteOnServer.end()) 
     1968      return; 
     1969 
     1970    if (isCompressible()) 
     1971    { 
     1972      size_t nbWritten = 0, indGlo; 
     1973      CContext* context=CContext::getCurrent();       
     1974      CContextServer* server = context->server;   
     1975 
     1976      std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2); 
     1977      nBegin[0]       = zoom_ibegin;  nBegin[1] = zoom_jbegin; 
     1978      nSize[0]        = zoom_ni;      nSize[1]  = zoom_nj; 
     1979      nBeginGlobal[0] = 0; nBeginGlobal[1] = 0; 
     1980      nGlob[0]        = ni_glo;   nGlob[1] = nj_glo; 
     1981      CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob);  
     1982      const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex(); 
     1983 
     1984      boost::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(), 
     1985                                                          ite = globalLocalIndexMap_.end(), it;    
     1986      CArray<size_t,1>::const_iterator itSrvb = writtenGlobalIndex.begin(), 
     1987                                       itSrve = writtenGlobalIndex.end(), itSrv; 
     1988      boost::unordered_map<size_t,size_t> localGlobalIndexMap; 
     1989      for (itSrv = itSrvb; itSrv != itSrve; ++itSrv) 
     1990      { 
     1991        indGlo = *itSrv; 
     1992        if (ite != globalLocalIndexMap_.find(indGlo)) 
     1993        { 
     1994          localGlobalIndexMap[localIndexToWriteOnServer(nbWritten)] = indGlo; 
     1995          ++nbWritten; 
     1996        }                  
     1997      } 
     1998 
     1999      nbWritten = 0; 
     2000      for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
     2001      { 
     2002        if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
     2003        { 
     2004          ++nbWritten; 
     2005        } 
     2006      } 
     2007 
     2008      compressedIndexToWriteOnServer[writtenCommSize].resize(nbWritten); 
     2009      nbWritten = 0; 
     2010      for (int idx = 0; idx < data_i_index.numElements(); ++idx) 
     2011      { 
     2012        if (localGlobalIndexMap.end() != localGlobalIndexMap.find(data_i_index(idx))) 
     2013        { 
     2014          compressedIndexToWriteOnServer[writtenCommSize](nbWritten) = localGlobalIndexMap[data_i_index(idx)]; 
     2015          ++nbWritten; 
     2016        } 
     2017      } 
     2018 
     2019      numberWrittenIndexes_[writtenCommSize] = nbWritten; 
     2020      if (isDistributed()) 
     2021      { 
     2022              
     2023        MPI_Allreduce(&numberWrittenIndexes_[writtenCommSize], &totalNumberWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); 
     2024        MPI_Scan(&numberWrittenIndexes_[writtenCommSize], &offsetWrittenIndexes_[writtenCommSize], 1, MPI_INT, MPI_SUM, writtenComm); 
     2025        offsetWrittenIndexes_[writtenCommSize] -= numberWrittenIndexes_[writtenCommSize]; 
     2026      } 
     2027      else 
     2028        totalNumberWrittenIndexes_[writtenCommSize] = numberWrittenIndexes_[writtenCommSize]; 
     2029      } 
     2030  } 
    19492031 
    19502032  /*! 
     
    24062488  void CDomain::recvIndex(std::map<int, CBufferIn*>& rankBuffers) 
    24072489  { 
    2408     int nbReceived = rankBuffers.size(), i, ind, index, type_int; 
     2490    int nbReceived = rankBuffers.size(), i, ind, index, type_int, iIndex, jIndex; 
    24092491    recvClientRanks_.resize(nbReceived);         
    24102492 
     
    24262508    globalLocalIndexMap_.rehash(std::ceil(nbIndGlob/globalLocalIndexMap_.max_load_factor())); 
    24272509    i_index.resize(nbIndGlob); 
    2428     j_index.resize(nbIndGlob);     
     2510    j_index.resize(nbIndGlob);    
     2511    int nbIndexGlobMax = nbIndGlob, nbIndLoc; 
     2512 
    24292513    nbIndGlob = 0; 
    24302514    for (i = 0; i < nbReceived; ++i) 
     
    24362520         if (0 == globalLocalIndexMap_.count(index)) 
    24372521         { 
    2438            i_index(nbIndGlob) = index % ni_glo; 
    2439            j_index(nbIndGlob) = index / ni_glo; 
    2440            globalLocalIndexMap_[index] = nbIndGlob;   
    2441            ++nbIndGlob; 
     2522           iIndex = (index%ni_glo)-ibegin; 
     2523           iIndex = (iIndex < 0) ? 0 : iIndex; 
     2524           jIndex = (index/ni_glo)-jbegin; 
     2525           jIndex = (jIndex < 0) ? 0 : jIndex; 
     2526           nbIndLoc = iIndex + ni * jIndex; 
     2527           if (nbIndLoc < nbIndexGlobMax) 
     2528           { 
     2529             i_index(nbIndLoc) = index % ni_glo; 
     2530             j_index(nbIndLoc) = index / ni_glo; 
     2531             globalLocalIndexMap_[index] = nbIndLoc;   
     2532             ++nbIndGlob; 
     2533           } 
     2534           // i_index(nbIndGlob) = index % ni_glo; 
     2535           // j_index(nbIndGlob) = index / ni_glo; 
     2536           // globalLocalIndexMap_[index] = nbIndGlob;   
     2537           // ++nbIndGlob; 
    24422538         }  
    24432539      }  
     
    24972593    if (zoom_ni<=0 || zoom_nj<=0) 
    24982594    { 
    2499       zoom_ibegin=0 ; zoom_iend=0 ; zoom_ni=0 ; 
    2500       zoom_jbegin=0 ; zoom_jend=0 ; zoom_nj=0 ; 
     2595      zoom_ni=0 ; zoom_ibegin=global_zoom_ibegin ; //=0; zoom_iend=0 ;  
     2596      zoom_nj=0 ; zoom_jbegin=global_zoom_jbegin ; //=0; zoom_jend=0 ; 
    25012597    } 
    25022598 
     
    25552651    nbMaskInd = globalLocalIndexMap_.size(); 
    25562652    mask_1d.resize(nbMaskInd); 
     2653    mask_1d = false; 
    25572654     
    25582655    for (i = 0; i < nbReceived; ++i) 
     
    28622959    Receive data index information from client(s) 
    28632960    A client receives data index from different clients to rebuild its own data index. 
     2961    Because we use global index + mask info to calculate the sending data to client(s),  
     2962    this data index must be updated with mask info (maybe it will change in the future) 
    28642963    Because the data index is local, to rebuild data index of received client, we should use global index along with.  
     2964 
    28652965    \param[in] rankBuffers rank of sending client and the corresponding receive buffer      
    28662966  */ 
     
    29013001         lInd = globalLocalIndexMap_[size_t(tmpInd(ind))]; 
    29023002         dataIIndex(lInd) = (-1 == dataIIndex(lInd)) ? tmpI(ind) : dataIIndex(lInd); // Only fill in dataIndex if there is no data 
    2903          dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd);          
     3003         dataJIndex(lInd) = (-1 == dataJIndex(lInd)) ? tmpJ(ind) : dataJIndex(lInd);   
     3004 
     3005         if (!mask_1d(lInd))   // Include mask info into data index on the RECEIVE getServerDimensionSizes     
     3006         { 
     3007           dataIIndex(lInd) = dataJIndex(lInd) = -1; 
     3008         } 
    29043009      }  
    29053010    } 
Note: See TracChangeset for help on using the changeset viewer.