[1918] | 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 | |
---|
| 14 | namespace xios |
---|
| 15 | { |
---|
| 16 | |
---|
| 17 | class CGridGathererConnector |
---|
| 18 | { |
---|
| 19 | private: |
---|
| 20 | |
---|
| 21 | vector<CGathererConnector*> elementsConnector_ ; |
---|
| 22 | int dstSize_ ; |
---|
| 23 | |
---|
| 24 | public: |
---|
| 25 | CGridGathererConnector(vector<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 | 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 | |
---|
[1943] | 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 | 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 | |
---|
[1918] | 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 | } |
---|
[1943] | 67 | |
---|
| 68 | template<typename T> |
---|
| 69 | void transfer(CEventServer& event, CArray<T,1>& dataOut, T missingValue) |
---|
| 70 | { |
---|
| 71 | map<int, CArray<T,1>> dataIn ; |
---|
| 72 | for (auto& subEvent : event.subEvents) |
---|
| 73 | { |
---|
| 74 | auto& data = dataIn[subEvent.rank]; |
---|
| 75 | (*subEvent.buffer) >> data ; |
---|
| 76 | } |
---|
| 77 | transfer(dataIn, dataOut, missingValue) ; |
---|
| 78 | } |
---|
| 79 | |
---|
[1918] | 80 | }; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | #endif |
---|