source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/transform_connector.hpp @ 2338

Last change on this file since 2338 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.5 KB
Line 
1#ifndef __TRANSFORM_CONNECTOR_HPP__
2#define __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 "scatterer_connector.hpp"
9#include "gatherer_connector.hpp"
10#include "mpi.hpp"
11
12namespace xios
13{
14 
15 
16  class CTransformConnector
17  {
18     
19    public:
20      CTransformConnector(shared_ptr<CLocalView> srcView, shared_ptr<CLocalView> dstView, MPI_Comm localComm) 
21                          : srcView_(srcView), dstView_(dstView), localComm_(localComm) {}
22   
23      void computeConnector(void) ; 
24    private:
25
26      MPI_Comm localComm_ ;
27      shared_ptr<CLocalView> srcView_ ;
28      shared_ptr<CLocalView> dstView_ ;
29      map<int,int> recvRankSize_ ;
30      shared_ptr<CScattererConnector> scattererConnector_ ;
31      shared_ptr<CGathererConnector>  gathererConnector_ ;
32   
33    public:
34      template<typename T> 
35      void transfer(int repeat, int sizeT, const CArray<T,1>& dataIn, CArray<T,1>& dataOut)
36      {
37        map<int,CArray<T,1>> tmpArrayIn ;
38        scattererConnector_->transfer(repeat, sizeT, dataIn, tmpArrayIn) ;
39        vector<MPI_Request> requests ;
40        MPI_Request request ;
41        for(auto it : tmpArrayIn)
42        {
43          auto& array = it.second ; 
44          MPI_Issend(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
45          requests.push_back(request) ;
46        }
47       
48        map<int,CArray<T,1>> tmpArrayOut ;
49        for(auto it : recvRankSize_)
50        {
51          auto& array = tmpArrayOut[it.first] ;
52          array.resize(it.second*repeat*sizeT) ;
53          MPI_Irecv(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
54          requests.push_back(request) ;
55        }
56       
57        vector<MPI_Status> status(requests.size()) ;
58        MPI_Waitall(requests.size(), requests.data(),status.data()) ;
59       
60        const double nanValue = std::numeric_limits<double>::quiet_NaN();
61        gathererConnector_->transfer(repeat, sizeT , tmpArrayOut, dataOut, nanValue) ;
62      }
63
64      template<typename T> 
65      void transfer(int sizeT, const CArray<T,1>& dataIn, CArray<T,1>& dataOut)
66      {
67        transfer(1, sizeT, dataIn, dataOut) ;
68      }
69   
70      template<typename T> 
71      void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut)
72      {
73        transfer(1, 1, dataIn, dataOut) ;
74      }
75
76  };
77
78}
79
80#endif
Note: See TracBrowser for help on using the repository browser.