Ignore:
Timestamp:
09/10/20 13:51:02 (4 years ago)
Author:
ymipsl
Message:

Big update on on going work related to data distribution and transfer between clients and servers.
Revisite of the source and store filter using "connectors".

YM

Location:
XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.cpp

    r1918 r1930  
    99                                    : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_)  
    1010  { 
    11     for(auto index : indexView)  
     11    for(auto& index : indexView)  
    1212    { 
    1313      index_[index.first].reference(index.second.copy()) ; 
     
    1616  } 
    1717 
    18  
    19 }  
     18  CDistributedView::CDistributedView(CDistributedElement* parent, CElementView::type, const std::map<int,CArray<bool,1>>& maskView)  
     19                                    : globalIndex_(parent->globalIndex_), globalSize_(parent->globalSize_), localSize_(parent->localSize_)  
     20  { 
     21    for(auto& it : maskView)  
     22    { 
     23      int rank = it.first ; 
     24      auto& mask = it.second ; 
     25      int size = mask.numElements() ; 
     26      auto& index = index_[rank] ;  
     27      index.resize(size) ; 
     28      int pos=0 ; 
     29      for(int i=0 ; i < size ; i++) 
     30        if (mask(i)) { index(pos) = i ; pos++ ; } 
     31      index.resizeAndPreserve(pos) ; 
     32      size_[rank] = pos ; 
     33    } 
     34  }  
     35} 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/distributed_view.hpp

    r1918 r1930  
    1515 
    1616      CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<int,1>>& indexView) ; 
     17      CDistributedView(CDistributedElement* parent, CElementView::type type, const std::map<int,CArray<bool,1>>& maskView) ; 
    1718       
    1819      std::map<int,CArray<int,1>>&  getIndex(void) { return index_ ;} 
     
    2122      std::map<int, int>& getLocalSize(void) { return localSize_ ;} 
    2223      size_t getGlobalSize(void) { return globalSize_ ;} 
     24 
     25      void getGlobalIndexView(map<int,CArray<size_t,1>>& globalIndexView) 
     26      { 
     27        for(auto& it : globalIndex_) 
     28        { 
     29          int rank=it.first ; 
     30          auto& globalIndex = it.second; 
     31          auto& globalIndView = globalIndexView[rank] ; 
     32          auto& index = index_[rank] ; 
     33          auto& size = size_[rank] ; 
     34          auto& localSize = localSize_[rank] ; 
     35          globalIndView.resize(size) ; 
     36          int pos=0 ; 
     37          for(int i=0 ; i<size ; i++) 
     38          { 
     39            if (index(i)>=0 && index(i)<localSize)  
     40            { 
     41              globalIndView(i) = globalIndex(index(i)) ; 
     42              pos++ ; 
     43            } 
     44          } 
     45          globalIndView.resizeAndPreserve(pos) ; 
     46      } 
     47    }    
    2348 
    2449      void getGlobalIndex(int rank, vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CDistributedView** view, int pos) 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.cpp

    r1918 r1930  
    2929  { 
    3030    views_[type] = new CDistributedView(this, type, indexView) ; 
     31  }  
     32 
     33  void CDistributedElement::addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) 
     34  { 
     35    views_[type] = new CDistributedView(this, type, maskView) ; 
    3136  }  
    3237 
     
    118123  }  
    119124 
     125  void CLocalElement::addView(CElementView::type type, CArray<bool,1>& maskView) 
     126  { 
     127    views_[type] = new CLocalView(this, type, maskView) ; 
     128  }  
     129 
    120130  void CLocalElement::addFullView(void) 
    121131  { 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/element.hpp

    r1918 r1930  
    4040 
    4141    void addView(CElementView::type type, std::map<int, CArray<int,1>>& indexView) ; 
     42    void addView(CElementView::type type, std::map<int, CArray<bool,1>>& maskView) ; 
    4243    void sendToServer(CEventClient& event, const CMessage& messageHeader) ; 
    4344 
     
    5556      CLocalElement(int localRank, CEventServer& event) ; 
    5657      void recvFromClient(int localRank, CEventServer& event) ; 
    57        
     58      const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 
    5859      void addView(CElementView::type type, CArray<int,1>& indexView) ; 
     60      void addView(CElementView::type type, CArray<bool,1>& maskView) ; 
    5961      void addFullView(void) ; 
    6062      CLocalView* getView(CElementView::type type)  
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.cpp

    r1918 r1930  
    1515    unordered_map<size_t,int> mapGlobalLocalIndex ; 
    1616    int globalIndexSize=dstGlobalIndex.size() ; 
    17     for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 
     17    //for(auto& ind : dstIndex) mapGlobalLocalIndex[dstGlobalIndex(ind)] = ind ; 
     18    for(int i=0; i<dstSize_ ; i++) if (dstIndex(i)>=0 && dstIndex(i)<globalIndexSize) mapGlobalLocalIndex[dstGlobalIndex(dstIndex(i))] = i ; 
     19 
    1820    for(auto& rankIndex : srcIndex) 
    1921    { 
     
    2729      for(int ind=0; ind<indexSize ; ind++) 
    2830      { 
    29         if (ind>=0 && ind<globalIndexSize) 
     31        if (index(ind)>=0 && index(ind)<globalIndexSize) 
    3032        { 
    31            auto it=mapGlobalLocalIndex.find(globalIndex(ind)) ; 
     33           auto it=mapGlobalLocalIndex.find(globalIndex(index(ind))) ; 
    3234           if (it != mapGlobalLocalIndex.end())  
    3335           { 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/gatherer_connector.hpp

    r1918 r1930  
    2929       
    3030      template<typename T> 
    31       void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 
     31      void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 
    3232      { 
    33         dataOut.resize(dstSize_) ; 
     33        // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 
     34        dataOut.resize(dstSize_*sizeT) ;   
    3435        T* output = dataOut.dataFirst() ; 
    3536        for(auto& data : dataIn) 
     
    3940          auto& connector=connector_[rank] ; 
    4041          auto& mask=mask_[rank] ; 
    41           int size=data.second.numElements() ; 
     42          int size=mask.size() ; 
    4243 
    4344          for(int i=0, j=0 ;i<size;i++) 
     
    4546            if (mask[i])  
    4647            { 
    47               output[connector[j]] = input[i] ; 
     48              int cj = connector[j]*sizeT ; 
     49              int ci = i*sizeT ; 
     50              for (int k=0;k<sizeT;k++) output[cj+k] = input[ci+k] ; 
    4851              j++ ; 
    4952            } 
     
    5255      } 
    5356     
     57      template<typename T> 
     58      void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) 
     59      { 
     60        transfer(1,dataIn,dataOut) ; 
     61      } 
    5462 
    5563      template<typename T> 
     
    93101      void transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 
    94102      { 
    95         dataOut.resize(dstSize_) ; 
    96         dataOut=missingValue ; 
    97         transfer(map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut) ; 
     103        transfer(1, dataIn, dataout, missingValue) 
    98104      } 
    99105       
    100106      template<typename T> 
    101       void transfer(CEventServer& event, CArray<T,1>& dataOut) 
     107      void transfer(int sizeT, map<int, CArray<T,1>>& dataIn, CArray<T,1>& dataOut, T missingValue) 
     108      { 
     109        dataOut.resize(dstSize_*sizeT) ; 
     110        dataOut=missingValue ; 
     111        transfer(sizeT, dataIn, dataOut) ; 
     112      } 
     113 
     114      template<typename T> 
     115      void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut) 
    102116      { 
    103117        map<int, CArray<T,1>> dataIn ; 
     
    107121          (*subEvent.buffer) >> data ; 
    108122        } 
    109         transfer(dataIn, dataOut) ; 
     123        transfer(sizeT, dataIn, dataOut) ; 
     124      } 
     125       
     126      template<typename T> 
     127      void transfer(CEventServer& event, CArray<T,1>& dataOut) 
     128      { 
     129        transfer(event, 1, dataOut) ; 
     130      } 
     131 
     132      template<typename T> 
     133      void transfer(CEventServer& event, int sizeT, CArray<T,1>& dataOut, T missingValue) 
     134      { 
     135        map<int, CArray<T,1>> dataIn ; 
     136        for (auto& subEvent : event.subEvents)  
     137        { 
     138          auto& data = dataIn[subEvent.rank];  
     139          (*subEvent.buffer) >> data ; 
     140        } 
     141        transfer(sizeT, dataIn, dataOut, missingValue) ; 
    110142      } 
    111143 
     
    119151          (*subEvent.buffer) >> data ; 
    120152        } 
    121         transfer(dataIn, dataOut, missingValue) ; 
     153        transfer(1, dataIn, dataOut, missingValue) ; 
    122154      } 
    123155 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.cpp

    r1918 r1930  
    66  CGridLocalView::CGridLocalView(CGridLocalElements* parent, CElementView::type type) : localMask_(parent->getLocalMask()) 
    77  { 
    8     for(auto element : parent->getElements()) views_.push_back(element->getView(type)) ; 
     8    size_ = 1 ; 
     9    for(auto element : parent->getElements())  
     10    { 
     11      views_.push_back(element->getView(type)) ; 
     12      size_ *= element->getView(type)->getSize() ; 
     13    } 
     14 
    915  } 
    1016 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_local_view.hpp

    r1918 r1930  
    1414      std::vector<CLocalView*> views_ ; 
    1515      std::vector<bool>& localMask_ ; 
     16      int size_ ; 
    1617     
    1718    public: 
    1819      CGridLocalView(CGridLocalElements* parent, CElementView::type type) ; 
    1920      std::vector<CLocalView*>& getViews(void) {return views_ ;} 
     21      int getSize() { return size_ ;} 
    2022  } ; 
    2123} 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_remote_connector.cpp

    r1918 r1930  
    1919  { 
    2020    // generic method, every element can be distributed 
     21    int nDst = dstView_.size() ; 
     22    vector<size_t> dstSliceSize(nDst) ; 
     23    dstSliceSize[0] = 1 ;   
     24    for(int i=1; i<nDst; i++)  dstSliceSize[i] = dstView_[i-1]->getGlobalSize()*dstSliceSize[i-1] ; 
     25   
     26    CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap dataInfo ; 
     27 
     28    CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap info ; // info map 
     29    for(int pos=0; pos<nDst; pos++) 
     30    { 
     31      size_t sliceSize=dstSliceSize[pos] ; 
     32      map<int,CArray<size_t,1>> globalIndexView ; 
     33      dstView_[pos]->getGlobalIndexView(globalIndexView) ; 
     34       
     35      CClientClientDHTTemplate<size_t>::Index2VectorInfoTypeMap lastInfo(info) ; 
     36 
     37      if (pos>0) 
     38      { 
     39        CArray<size_t,1> ranks(globalIndexView.size()) ; 
     40        auto it=globalIndexView.begin() ; 
     41        for(int i=0 ; i<ranks.numElements();i++,it++) ranks(i)=it->first ; 
     42        CClientClientDHTTemplate<size_t> dataRanks(info, localComm_) ; 
     43        dataRanks.computeIndexInfoMapping(ranks) ; 
     44        lastInfo = dataRanks.getInfoIndexMap() ; 
     45      } 
     46       
     47      info.clear() ; 
     48      for(auto& it : globalIndexView) 
     49      { 
     50        int rank = it.first ; 
     51        auto& globalIndex = it.second ; 
     52        auto& inf = info[rank] ; 
     53        if (pos==0) for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)) ; 
     54        else 
     55        { 
     56          auto& lastGlobalIndex = lastInfo[rank] ; 
     57          for(size_t lastGlobalInd : lastGlobalIndex) 
     58          { 
     59            for(int i=0;i<globalIndex.numElements();i++) inf.push_back(globalIndex(i)*sliceSize+lastGlobalInd) ; 
     60          } 
     61        }  
     62      } 
     63 
     64      if (pos==nDst-1) 
     65      { 
     66         for(auto& it : info) 
     67         { 
     68           int rank=it.first ; 
     69           auto& globalIndex = it.second ; 
     70           for(auto globalInd : globalIndex) dataInfo[globalInd].push_back(rank) ; 
     71         } 
     72      }  
     73    } 
     74 
     75    CClientClientDHTTemplate<int> dataRanks(dataInfo, localComm_) ; 
     76/* 
    2177    CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap info ; // info map 
    2278         
     
    3793     
    3894    CClientClientDHTTemplate<int> dataRanks(info, localComm_) ; 
    39      
     95*/     
    4096    // generate list of global index for src view 
    4197    int nSrc = srcView_.size() ; 
    4298    vector<size_t> srcSliceSize(nSrc) ; 
    43     srcSliceSize[nSrc-1] = 1 ; 
    44     for(int i=nSrc-2; i>=0; i--)  srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 
    45      
     99//    srcSliceSize[nSrc-1] = 1 ; 
     100//    for(int i=nSrc-2; i>=0; i--)  srcSliceSize[i] = srcView_[i+1]->getGlobalSize()*srcSliceSize[i+1] ; 
     101    
     102    srcSliceSize[0] = 1 ;   
     103    for(int i=1; i<nSrc; i++)  srcSliceSize[i] = srcView_[i-1]->getGlobalSize()*srcSliceSize[i-1] ; 
     104 
    46105    vector<size_t> srcGlobalIndex ; 
    47106    size_t sliceIndex=0 ; 
     
    54113    vector<map<int, set<size_t>>> elements(nSrc) ; // internal representation of elements composing the grid 
    55114 
    56     srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ; 
    57     for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ; 
     115//    srcSliceSize[nSrc-1] = srcView_[nSrc-1]->getGlobalSize() ; 
     116//    for(int i=nSrc-2 ; i>=0 ; i--) srcSliceSize[i] = srcView_[i]->getGlobalSize()*srcSliceSize[i+1] ; 
    58117 
    59118    for(auto& indRanks : returnInfo) 
     
    61120      size_t gridIndexGlo=indRanks.first ; 
    62121      auto& ranks = indRanks.second ; 
    63       for(int i=0;i<nSrc;i++) 
     122      for(int i=nSrc-1; i>=0; i--) 
    64123      { 
    65124        auto& element = elements[i] ; 
    66         size_t localIndGlo = gridIndexGlo % srcSliceSize[i] ; 
     125        size_t localIndGlo = gridIndexGlo / srcSliceSize[i] ; 
     126        gridIndexGlo = gridIndexGlo % srcSliceSize[i] ; 
    67127        for(int rank : ranks) element[rank].insert(localIndGlo) ; 
    68128      } 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.cpp

    r1918 r1930  
    1515  } 
    1616 
     17  CLocalView::CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView)  
     18                        : CDistributedView( parent, type, {{  parent->localRank_,  maskView }} ), 
     19                          localRank_(parent->localRank_), 
     20                          globalIndex_(parent->globalIndex_), size_(CDistributedView::size_[parent->localRank_]), 
     21                          index_(CDistributedView::index_[parent->localRank_]), localSize_(CDistributedView::localSize_[parent->localRank_])  
     22  { 
     23 
     24  } 
    1725 
    1826  void CLocalView::sendRemoteElement(CRemoteConnector& connector, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/local_view.hpp

    r1918 r1930  
    1717    public: 
    1818    CLocalView(CLocalElement* parent, CElementView::type type, const CArray<int,1>& indexView) ; 
     19    CLocalView(CLocalElement* parent, CElementView::type type, const CArray<bool,1>& maskView) ; 
     20 
    1921    const CArray<int,1>& getIndex(void) { return index_ ;} 
    2022    const CArray<size_t,1>& getGlobalIndex(void) { return globalIndex_ ;} 
     23     
     24    void getGlobalIndexView(CArray<size_t,1>& globalIndexView) 
     25    { 
     26      globalIndexView.resize(size_) ; 
     27      int pos=0 ; 
     28      for(int i=0 ; i<size_ ; i++) 
     29      { 
     30        if (index_(i)>=0 && index_(i)<localSize_)  
     31        { 
     32          globalIndexView(i) = globalIndex_(index_(i)) ; 
     33          pos++ ; 
     34        } 
     35      } 
     36      globalIndexView.resizeAndPreserve(pos) ; 
     37    }     
    2138 
    2239    void getGlobalIndex(vector<size_t>& globalIndex, size_t sliceIndex, size_t* sliceSize, CLocalView** localView, int pos) 
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/scatterer_connector.hpp

    r1918 r1930  
    3434    void computeConnector(void) ; 
    3535     
    36     template<typename T> 
    37     void transfer(const CArray<T,1>& dataIn, map<int, CArray<T,1>>& dataOut) 
     36    template<typename T, int n> 
     37    void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 
    3838    { 
     39      transfer(1, dataIn, dataOut) ; 
     40    } 
     41 
     42    template<typename T, int n> 
     43    void transfer(const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 
     44    { 
     45      transfer(1, dataIn, dataOut, missingValue) ; 
     46    } 
     47 
     48    template<typename T, int n> 
     49    void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut) 
     50    { 
     51      // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 
    3952      for(auto& rankConnector : connector_) 
    4053      { 
     
    4457        int dstSize = mask.size() ; 
    4558        auto& data = dataOut[rank] ; 
    46         data.resize(dstSize) ; 
     59        data.resize(dstSize * sizeT) ; 
    4760        T* dstData = data.dataFirst() ; 
    4861        const T* srcData = dataIn.dataFirst() ; 
     
    5063          if (mask[i])  
    5164          { 
    52             dstData[i] = srcData[connector[j]] ; 
     65            for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 
     66            j++ ; 
     67          } 
     68      } 
     69    } 
     70 
     71    template<typename T, int n> 
     72    void transfer(int sizeT, const CArray<T,n>& dataIn, map<int, CArray<T,1>>& dataOut, T missingValue) 
     73    { 
     74      // for future, make a specific transfer function for sizeT=1 to avoid multiplication (increasing performance) 
     75      for(auto& rankConnector : connector_) 
     76      { 
     77        int rank = rankConnector.first ; 
     78        auto& connector = rankConnector.second ; 
     79        auto& mask = mask_[rank] ; 
     80        int dstSize = mask.size() ; 
     81        auto& data = dataOut[rank] ; 
     82        data.resize(dstSize * sizeT) ; 
     83        T* dstData = data.dataFirst() ; 
     84        const T* srcData = dataIn.dataFirst() ; 
     85        for(int i=0, j=0; i<dstSize; i++) 
     86          if (mask[i])  
     87          { 
     88            for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = srcData[connector[j]*sizeT+k] ; 
     89            j++ ; 
     90          } 
     91          else  
     92          { 
     93            for(int k=0;k<sizeT;k++) dstData[i*sizeT+k] = missingValue ; 
    5394            j++ ; 
    5495          } 
     
    5697    } 
    5798     
    58     template<typename T> 
    59     void transfer(const CArray<T,1>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
     99    template<typename T,int n> 
     100    void transfer(const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
     101    { 
     102      transfer(1, dataIn, client, event, messageHeader) ; 
     103    } 
     104 
     105    template<typename T,int n> 
     106    void transfer(const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
     107    { 
     108      transfer(1, dataIn, missingValue, client, event, messageHeader) ; 
     109    } 
     110 
     111    template<typename T, int n> 
     112    void transfer(int sizeT, const CArray<T,n>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
    60113    { 
    61114      map<int, CArray<T,1>> dataOut ; 
    62       transfer(dataIn, dataOut) ; 
     115      transfer(sizeT, dataIn, dataOut) ; 
     116      sendToServer(dataOut, client, event, messageHeader) ; 
     117    } 
     118 
     119    template<typename T, int n> 
     120    void transfer(int sizeT, const CArray<T,n>& dataIn, T missingValue, CContextClient* client, CEventClient& event, const CMessage& messageHeader) 
     121    { 
     122      map<int, CArray<T,1>> dataOut ; 
     123      transfer(sizeT, dataIn, dataOut, missingValue) ; 
    63124      sendToServer(dataOut, client, event, messageHeader) ; 
    64125    } 
Note: See TracChangeset for help on using the changeset viewer.