source: XIOS3/trunk/src/distribution/grid_transform_connector.hpp @ 2628

Last change on this file since 2628 was 2628, checked in by jderouillat, 7 weeks ago

New timers integration/reporting

  • Property svn:executable set to *
File size: 2.7 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 "reduction_types.hpp"
11#include "mpi.hpp"
12#include "timer.hpp"
13
14namespace xios
15{
16 
17  extern CLogType logProfile ;
18
19  class CGridTransformConnector
20  {
21     
22    public:
23      CGridTransformConnector(vector<shared_ptr<CLocalView>> srcViews, vector<shared_ptr<CLocalView>> remoteViews, MPI_Comm localComm) 
24                          : srcViews_(srcViews), remoteViews_(remoteViews), localComm_(localComm) 
25                          { }
26   
27      void computeConnector(bool eliminateRedundant=true) ; 
28    protected:
29     MPI_Comm localComm_ ;
30     vector<shared_ptr<CLocalView>> srcViews_ ;
31     vector<shared_ptr<CLocalView>> remoteViews_ ;
32     map<int,int> recvRankSize_ ;
33
34     vector<shared_ptr<CScattererConnector>> scattererConnector_ ;
35     vector<shared_ptr<CGathererConnector>>  gathererConnector_ ;
36     shared_ptr<CGridScattererConnector> gridScattererConnector_ ;
37     shared_ptr<CGridGathererConnector> gridGathererConnector_ ;
38 
39    public:
40      template<typename T> 
41      void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none)
42      {
43        map<int,CArray<T,1>> tmpArrayIn ;
44        gridScattererConnector_->transfer(dataIn, tmpArrayIn) ;
45        if (info.isActive(logProfile)) CTimer::get("Transformation MPI").resume();
46        vector<MPI_Request> requests ;
47        MPI_Request request ;
48        for(auto it : tmpArrayIn)
49        {
50          auto& array = it.second ; 
51          MPI_Issend(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
52          requests.push_back(request) ;
53        }
54       
55        map<int,CArray<T,1>> tmpArrayOut ;
56        for(auto it : recvRankSize_)
57        {
58          auto& array = tmpArrayOut[it.first] ;
59          array.resize(it.second) ;
60          MPI_Irecv(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ;
61          requests.push_back(request) ;
62        }
63       
64        vector<MPI_Status> status(requests.size()) ;
65        MPI_Waitall(requests.size(), requests.data(),status.data()) ;
66        if (info.isActive(logProfile)) CTimer::get("Transformation MPI").suspend();
67       
68        const double nanValue = std::numeric_limits<double>::quiet_NaN();
69
70        if (op == EReduction::none) gridGathererConnector_->transfer(tmpArrayOut, dataOut, nanValue) ;
71        else gridGathererConnector_->transfer(tmpArrayOut, dataOut, op) ;
72      }
73 
74  };
75
76}
77
78#endif
Note: See TracBrowser for help on using the repository browser.