source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_transform_connector.cpp @ 2291

Last change on this file since 2291 was 2291, checked in by ymipsl, 2 years ago

Improve reduction transformation

  • make the difference between reduction over geometry or reduction between process.
  • geometrical reduction :

domain -> axis
axis -> scalar
domain -> scalar

  • reduction across processes for redondant geometrical cell :

axis -> axis
scalar -> scalar

Reduction can be local (only for the geometrical cell owned by current process) or global, using the "local" attribute (bool) over the reduction.

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.4 KB
Line 
1#include "grid_transform_connector.hpp"
2#include "element.hpp"
3#include "scatterer_connector.hpp"
4#include "gatherer_connector.hpp"
5#include "grid_remote_connector.hpp"
6#include "grid_redondant_remote_connector.hpp"
7
8
9namespace xios
10{
11  void CGridTransformConnector::computeConnector(bool eliminateRedundant)
12  {
13    int commSize ;
14    int commRank ;
15    MPI_Comm_size(localComm_, &commSize) ;
16    MPI_Comm_rank(localComm_, &commRank) ;
17    int nElements = srcViews_.size() ;
18
19    auto remoteConnector = make_shared<CGridRemoteConnector>(srcViews_, remoteViews_, localComm_, commSize) ; 
20    remoteConnector->computeConnector(eliminateRedundant) ; 
21   
22    vector<shared_ptr<CDistributedElement>> sendElements(nElements) ;
23    scattererConnector_.resize(nElements) ;
24    gathererConnector_.resize(nElements) ;
25
26    for(int i=0;i<nElements;i++)
27    {
28      sendElements[i] = make_shared<CDistributedElement>(srcViews_[i]->getGlobalSize(), remoteConnector->getDistributedGlobalIndex(i)) ;
29      sendElements[i]->addFullView() ;
30      scattererConnector_[i] = make_shared<CScattererConnector>(srcViews_[i], sendElements[i]->getView(CElementView::FULL), localComm_, commSize) ;
31      scattererConnector_[i]->computeConnector() ;
32      std::map<int, CArray<size_t,1>>& sendIndex = sendElements[i]->getGlobalIndex() ;
33
34      // how much sender ?
35      vector<int> nbSenders(commSize) ;
36      int nbSender ;
37      for(auto& it : sendIndex) nbSenders[it.first]=1 ;
38      vector<int> recvCounts(commSize,1) ;
39      MPI_Reduce_scatter(nbSenders.data(), &nbSender, recvCounts.data(), MPI_INT, MPI_SUM, localComm_) ;
40   
41      // transfer global index
42      // send Index
43      vector<MPI_Request> sendReq ;
44      for(auto& it : sendIndex)
45      {
46        MPI_Request req ;
47        MPI_Isend(it.second.dataFirst(), it.second.numElements(), MPI_SIZE_T, it.first,0, localComm_, &req) ;
48        sendReq.push_back(req) ;
49      }
50
51      // receive index
52      map<int,CArray<size_t,1>> recvIndex ;
53   
54      for(int j=0; j<nbSender; j++) 
55      {
56        int size ;
57        MPI_Status status ;
58        MPI_Probe(MPI_ANY_SOURCE, 0, localComm_, &status ) ;
59        MPI_Get_count(&status, MPI_SIZE_T, &size) ;
60        vector<size_t> recvBuff(size) ;
61        MPI_Recv(recvBuff.data(), size, MPI_SIZE_T, status.MPI_SOURCE,0, localComm_,&status) ;
62        if (size!=0) {
63            CArray<size_t,1> arrayTmp(recvBuff.data(), shape(recvBuff.size()), duplicateData) ;
64            recvIndex[status.MPI_SOURCE].reference(arrayTmp) ;
65        }
66        else {
67            CArray<size_t,1> arrayTmp(0) ;
68            recvIndex[status.MPI_SOURCE].reference(arrayTmp) ;
69        }
70        if (recvRankSize_.count(status.MPI_SOURCE)==0) recvRankSize_[status.MPI_SOURCE] = size ; 
71        else recvRankSize_[status.MPI_SOURCE] *= size ; 
72      }
73      vector<MPI_Status> sendStatus(sendReq.size()) ;
74      MPI_Waitall(sendReq.size(),sendReq.data(),sendStatus.data()) ;
75     
76      // create gatherer connector
77
78      auto recvElement = make_shared<CDistributedElement>(remoteViews_[i]->getGlobalSize(), recvIndex) ;
79      recvElement->addFullView() ;
80      gathererConnector_[i] = make_shared<CGathererConnector>(recvElement->getView(CElementView::FULL), remoteViews_[i]) ;
81      gathererConnector_[i]->computeConnector() ;
82    }
83
84    gridScattererConnector_ = make_shared<CGridScattererConnector>(scattererConnector_) ;
85    gridGathererConnector_  = make_shared<CGridGathererConnector>(gathererConnector_) ;
86  }
87
88}
Note: See TracBrowser for help on using the repository browser.