source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_transform_connector.hpp @ 2267

Last change on this file since 2267 was 2267, checked in by ymipsl, 3 years ago

tracking memory leak
Elements, views, and connectors are now managed with shared pointer.
YM

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#ifndef __GRID_TRANSFORM_CONNECTOR_HPP__
2#define __GRID_TRANSFORM_CONNECTOR_HPP__
3
4#include "xios_spl.hpp"
5#include "array_new.hpp"
6#include "distributed_view.hpp"
7#include "local_view.hpp"
8#include "grid_scatterer_connector.hpp"
9#include "grid_gatherer_connector.hpp"
10#include "mpi.hpp"
11
12namespace xios
13{
14 
15 
16  class CGridTransformConnector
17  {
18     
19    public:
20      CGridTransformConnector(vector<shared_ptr<CLocalView>> srcViews, vector<shared_ptr<CLocalView>> remoteViews, MPI_Comm localComm) 
21                          : srcViews_(srcViews), remoteViews_(remoteViews), localComm_(localComm) 
22                          { computeConnector();}
23   
24      void computeConnector(void) ; 
25    protected:
26     MPI_Comm localComm_ ;
27     vector<shared_ptr<CLocalView>> srcViews_ ;
28     vector<shared_ptr<CLocalView>> remoteViews_ ;
29     map<int,int> recvRankSize_ ;
30
31     vector<shared_ptr<CScattererConnector>> scattererConnector_ ;
32     vector<shared_ptr<CGathererConnector>>  gathererConnector_ ;
33     shared_ptr<CGridScattererConnector> gridScattererConnector_ ;
34     shared_ptr<CGridGathererConnector> gridGathererConnector_ ;
35 
36    public:
37      template<typename T> 
38      void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut)
39      {
40        map<int,CArray<T,1>> tmpArrayIn ;
41        gridScattererConnector_->transfer(dataIn, tmpArrayIn) ;
42        vector<MPI_Request> requests ;
43        MPI_Request request ;
44        for(auto it : tmpArrayIn)
45        {
46          auto& array = it.second ; 
47          MPI_Issend(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
48          requests.push_back(request) ;
49        }
50       
51        map<int,CArray<T,1>> tmpArrayOut ;
52        for(auto it : recvRankSize_)
53        {
54          auto& array = tmpArrayOut[it.first] ;
55          array.resize(it.second) ;
56          MPI_Irecv(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
57          requests.push_back(request) ;
58        }
59       
60        vector<MPI_Status> status(requests.size()) ;
61        MPI_Waitall(requests.size(), requests.data(),status.data()) ;
62       
63        const double nanValue = std::numeric_limits<double>::quiet_NaN();
64        gridGathererConnector_->transfer(tmpArrayOut, dataOut, nanValue) ;
65      }
66 
67  };
68
69}
70
71#endif
Note: See TracBrowser for help on using the repository browser.