source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_gatherer_connector.hpp @ 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:executable set to *
File size: 3.8 KB
Line 
1#ifndef __GRID_GATHERER_CONNECTOR_HPP__
2#define __GRID_GATHERER_CONNECTOR_HPP__
3
4#include "xios_spl.hpp"
5#include "array_new.hpp"
6#include "distributed_view.hpp"
7#include "mpi.hpp"
8#include "local_view.hpp"
9#include "distributed_view.hpp"
10#include "context_client.hpp"
11#include "gatherer_connector.hpp"
12#include "reduction_types.hpp"
13
14
15namespace xios
16{
17 
18  class CGridGathererConnector
19  {
20    private:
21   
22      vector<shared_ptr<CGathererConnector>> elementsConnector_ ;
23      int dstSize_ ;
24
25    public:
26      CGridGathererConnector(vector<shared_ptr<CGathererConnector>> elementsConnector) : elementsConnector_(elementsConnector)
27      {
28        dstSize_ = 1 ;
29        for(auto& connector : elementsConnector_) dstSize_=dstSize_*connector->getDstSize() ;
30      }
31
32      template<typename T> 
33      void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output, EReduction op = EReduction::none)
34      {
35        int n = elementsConnector_.size()-1 ;
36        shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
37        output.resize(dstSize_) ;
38       
39        if (op == EReduction::none)
40          for(auto& rankDataIn : input) 
41            elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
42        else
43        {
44          T defaultValue = std::numeric_limits<T>::quiet_NaN();
45          vector<int> count(dstSize_,0) ;
46          for(auto& rankDataIn : input) 
47            elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst(), op, count.data()) ;
48
49          for(int i=0;i<dstSize_;i++) if (count[i]==0) output(i)=defaultValue ;
50        }
51      } 
52
53      template<typename T> 
54      void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output, T missingValue)
55      {
56        int n = elementsConnector_.size()-1 ;
57        shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
58        output.resize(dstSize_) ;
59        output = missingValue ;
60        for(auto& rankDataIn : input) 
61        {
62          elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
63        }
64      } 
65
66      template<typename T>
67      void transfer(CEventServer& event, CArray<T,1>& dataOut, EReduction op = EReduction::none)
68      {
69        map<int, CArray<T,1>> dataIn ;
70        for (auto& subEvent : event.subEvents) 
71        {
72          auto& data = dataIn[subEvent.rank]; 
73          (*subEvent.buffer) >> data ;
74        }
75        transfer(dataIn, dataOut, op) ;
76      }
77     
78
79      void transfer_or(CEventServer& event, CArray<bool,1>& dataOut)
80      {
81        map<int, CArray<bool,1>> dataIn ;
82        for (auto& subEvent : event.subEvents) 
83        {
84          auto& data = dataIn[subEvent.rank]; 
85          (*subEvent.buffer) >> data ;
86        }
87        transfer_or(dataIn, dataOut) ;
88      }
89
90      template<typename T>
91      void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue)
92      {
93        map<int, CArray<T,1>> dataIn ;
94        for (auto& subEvent : event.subEvents) 
95        {
96          auto& data = dataIn[subEvent.rank]; 
97          (*subEvent.buffer) >> data ;
98        }
99        transfer(dataIn, dataOut, missingValue) ;
100      }
101
102      void transfer_or(const map<int, CArray<bool,1>>& input, CArray<bool,1>& output)
103      {
104        int n = elementsConnector_.size()-1 ;
105        shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
106        output.resize(dstSize_) ;
107        output = false ;
108        for(auto& rankDataIn : input) 
109        {
110          elementsConnector_[n]->transfer_or(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
111        }
112      } 
113
114  };
115}
116
117#endif
Note: See TracBrowser for help on using the repository browser.