source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/scatterer_connector.cpp @ 1918

Last change on this file since 1918 was 1918, checked in by ymipsl, 4 years ago

Big update on on going work related to data distribution and transfer between clients and servers.

  • move all related file into distribution directorie
  • implement the concept of data "View"
  • implement the concept of "connector" which make the data transfer between 2 differents "Views"

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#include "scatterer_connector.hpp"
2
3
4namespace xios
5{
6
7  void CScattererConnector::computeConnector(void)
8  {
9    auto& srcGlobalIndex = srcView_->getGlobalIndex() ;
10    auto& srcIndex = srcView_->getIndex() ;
11    srcSize_=srcIndex.numElements() ;
12    auto srcSize = srcView_->getSize() ;
13    auto srcLocalSize = srcView_->getLocalSize() ;
14   
15    auto& dstIndex = dstView_->getIndex() ;
16    for(auto& rankIndex : dstIndex) dstSize_[rankIndex.first]=rankIndex.second.numElements() ;
17    auto& dstGlobalIndex = dstView_->getGlobalIndex() ;
18
19    unordered_map<size_t,int> mapGlobalLocalIndex ;
20    int globalIndexSize=srcGlobalIndex.size() ;
21   
22    for(int i=0 ; i<srcSize ; i++) 
23      if (srcIndex(i) >=0 && srcIndex(i) <srcLocalSize) mapGlobalLocalIndex[srcGlobalIndex(srcIndex(i))] = i ;
24   
25    for(auto& rankIndex : dstIndex)
26    {
27      int rank = rankIndex.first ;
28      auto& index = rankIndex.second ;
29      int size = index.numElements() ;
30      auto& globalIndex = dstGlobalIndex[rank] ;
31      int localSize = globalIndex.numElements() ;
32      auto& connector = connector_[rank] ;
33      auto& mask = mask_[rank] ;
34      mask.resize(size) ;
35
36      for(int i=0 ; i<size ; i++) 
37      {
38        if (index(i) >= 0  && index(i) < localSize)
39        {
40          const auto& it = mapGlobalLocalIndex.find(globalIndex(index(i))) ;
41          if (it != mapGlobalLocalIndex.end()) 
42          {
43            connector.push_back(it->second) ;
44            mask[i] = true ;
45          }
46          else mask[i]=false ;
47        }
48        else mask[i]=false ;
49      }
50    }
51
52   // compute the number of senders for a remote destination view
53    int commSize ;
54    MPI_Comm_size(localComm_, &commSize) ;
55    vector<int> ranks(commSize,0) ;
56    for(auto& rank : connector_) ranks[rank.first] = 1 ;
57    MPI_Allreduce(MPI_IN_PLACE,ranks.data(),commSize,MPI_INT,MPI_SUM,localComm_) ;
58    for(auto& rank : connector_) nbSenders_[rank.first] = ranks[rank.first] ;
59
60  }
61
62}
Note: See TracBrowser for help on using the repository browser.