source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/remote_connector.cpp @ 2230

Last change on this file since 2230 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: 2.4 KB
Line 
1#include "remote_connector.hpp"
2#include "client_client_dht_template.hpp"
3
4
5namespace xios
6{
7
8  void CRemoteConnector::computeConnector(void)
9  {
10    CClientClientDHTTemplate<int>::Index2VectorInfoTypeMap info ;
11    for(auto& dstIndex : dstView_->getIndex())
12    {
13      int rank=dstIndex.first ;
14      auto& indexList=dstIndex.second ;
15      auto& globalIndex = dstView_->getGlobalIndex()[rank] ;
16      for(int i=0;i<indexList.numElements();i++) info[globalIndex(indexList(i))].push_back(rank) ; 
17    }
18    CClientClientDHTTemplate<int> dataRanks(info, localComm_) ;
19   
20    set<size_t> setGlobalIndex ; // all global index from src
21    auto& srcIndex = srcView_->getIndex() ;
22    auto& globalIndex = srcView_->getGlobalIndex() ;
23    int globalIndexSize = globalIndex.numElements() ;
24    int indexSize = srcIndex.numElements() ;
25    for(int i=0;i<indexSize;i++) 
26    {
27      if (srcIndex(i)>=0 & srcIndex(i)<globalIndexSize) setGlobalIndex.insert(globalIndex(srcIndex(i))) ;
28    }
29   
30    CArray<size_t,1> srcGlobalIndex(setGlobalIndex.size()) ;
31    int i=0 ;
32    for(auto& globalIndex : setGlobalIndex) 
33    {
34      srcGlobalIndex(i) = globalIndex ;
35      i++ ;
36    }
37
38    dataRanks.computeIndexInfoMapping(srcGlobalIndex) ;
39    const auto& returnInfo = dataRanks.getInfoIndexMap() ;
40
41    // so we have the info where to send data : rank and local index.
42    // create the interconnector :
43    map<int,vector<size_t>> element ;
44    for(int i=0;i<indexSize;i++)
45    {
46      if (srcIndex(i)>=0 & srcIndex(i)<globalIndexSize)
47      {
48        size_t indGlo = globalIndex(srcIndex(i)) ;
49        // don't forget that a single point can be sent multiple time (redondency ?)
50        for(auto& rank : returnInfo.at(indGlo))
51        {
52          connector_[rank].push_back(i) ;
53          element[rank].push_back(indGlo) ;
54        }
55      }
56    }
57
58    for(auto rankIndex : element)
59    {
60      CArray<size_t,1> arrayTmp(rankIndex.second.data(), shape(rankIndex.second.size()), duplicateData) ;
61      element_[rankIndex.first].reference(arrayTmp) ;
62    }
63   
64    // compute the number of senders for a remote destination view
65    int commSize ;
66    MPI_Comm_size(localComm_, &commSize) ;
67    vector<int> ranks(commSize,0) ;
68    for(auto& rank : connector_) ranks[rank.first] = 1 ;
69    MPI_Allreduce(MPI_IN_PLACE,ranks.data(),commSize,MPI_INT,MPI_SUM,localComm_) ;
70    for(auto& rank : connector_) nbSenders_[rank.first] = ranks[rank.first] ;
71  }
72
73
74
75
76
77}
Note: See TracBrowser for help on using the repository browser.