source: XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_gatherer_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: 3.3 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
13
14namespace xios
15{
16 
17  class CGridGathererConnector
18  {
19    private:
20   
21      vector<shared_ptr<CGathererConnector>> elementsConnector_ ;
22      int dstSize_ ;
23
24    public:
25      CGridGathererConnector(vector<shared_ptr<CGathererConnector>> elementsConnector) : elementsConnector_(elementsConnector)
26      {
27        dstSize_ = 1 ;
28        for(auto& connector : elementsConnector_) dstSize_=dstSize_*connector->getDstSize() ;
29      }
30
31      template<typename T> 
32      void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output)
33      {
34        int n = elementsConnector_.size()-1 ;
35       shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
36        output.resize(dstSize_) ;
37        for(auto& rankDataIn : input) 
38        {
39          elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
40        }
41      } 
42
43      template<typename T> 
44      void transfer(const map<int, CArray<T,1>>& input, CArray<T,1>& output, T missingValue)
45      {
46        int n = elementsConnector_.size()-1 ;
47        shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
48        output.resize(dstSize_) ;
49        output = missingValue ;
50        for(auto& rankDataIn : input) 
51        {
52          elementsConnector_[n]->transfer(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
53        }
54      } 
55
56      template<typename T>
57      void transfer(CEventServer& event, CArray<T,1>& dataOut)
58      {
59        map<int, CArray<T,1>> dataIn ;
60        for (auto& subEvent : event.subEvents) 
61        {
62          auto& data = dataIn[subEvent.rank]; 
63          (*subEvent.buffer) >> data ;
64        }
65        transfer(dataIn, dataOut) ;
66      }
67     
68
69      void transfer_or(CEventServer& event, CArray<bool,1>& dataOut)
70      {
71        map<int, CArray<bool,1>> dataIn ;
72        for (auto& subEvent : event.subEvents) 
73        {
74          auto& data = dataIn[subEvent.rank]; 
75          (*subEvent.buffer) >> data ;
76        }
77        transfer_or(dataIn, dataOut) ;
78      }
79
80      template<typename T>
81      void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue)
82      {
83        map<int, CArray<T,1>> dataIn ;
84        for (auto& subEvent : event.subEvents) 
85        {
86          auto& data = dataIn[subEvent.rank]; 
87          (*subEvent.buffer) >> data ;
88        }
89        transfer(dataIn, dataOut, missingValue) ;
90      }
91
92      void transfer_or(const map<int, CArray<bool,1>>& input, CArray<bool,1>& output)
93      {
94        int n = elementsConnector_.size()-1 ;
95        shared_ptr<CGathererConnector>* connector = elementsConnector_.data() + n ;
96        output.resize(dstSize_) ;
97        output = false ;
98        for(auto& rankDataIn : input) 
99        {
100          elementsConnector_[n]->transfer_or(rankDataIn.first, connector, n, rankDataIn.second.dataFirst(), output.dataFirst()) ;
101        }
102      } 
103
104  };
105}
106
107#endif
Note: See TracBrowser for help on using the repository browser.