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 | |
---|
13 | namespace xios |
---|
14 | { |
---|
15 | |
---|
16 | |
---|
17 | class CGridTransformConnector |
---|
18 | { |
---|
19 | |
---|
20 | public: |
---|
21 | CGridTransformConnector(vector<shared_ptr<CLocalView>> srcViews, vector<shared_ptr<CLocalView>> remoteViews, MPI_Comm localComm) |
---|
22 | : srcViews_(srcViews), remoteViews_(remoteViews), localComm_(localComm) |
---|
23 | { } |
---|
24 | |
---|
25 | void computeConnector(bool eliminateRedundant=true) ; |
---|
26 | protected: |
---|
27 | MPI_Comm localComm_ ; |
---|
28 | vector<shared_ptr<CLocalView>> srcViews_ ; |
---|
29 | vector<shared_ptr<CLocalView>> remoteViews_ ; |
---|
30 | map<int,int> recvRankSize_ ; |
---|
31 | |
---|
32 | vector<shared_ptr<CScattererConnector>> scattererConnector_ ; |
---|
33 | vector<shared_ptr<CGathererConnector>> gathererConnector_ ; |
---|
34 | shared_ptr<CGridScattererConnector> gridScattererConnector_ ; |
---|
35 | shared_ptr<CGridGathererConnector> gridGathererConnector_ ; |
---|
36 | |
---|
37 | public: |
---|
38 | template<typename T> |
---|
39 | void transfer(const CArray<T,1>& dataIn, CArray<T,1>& dataOut, EReduction op = EReduction::none) |
---|
40 | { |
---|
41 | map<int,CArray<T,1>> tmpArrayIn ; |
---|
42 | gridScattererConnector_->transfer(dataIn, tmpArrayIn) ; |
---|
43 | vector<MPI_Request> requests ; |
---|
44 | MPI_Request request ; |
---|
45 | for(auto it : tmpArrayIn) |
---|
46 | { |
---|
47 | auto& array = it.second ; |
---|
48 | MPI_Issend(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ; |
---|
49 | requests.push_back(request) ; |
---|
50 | } |
---|
51 | |
---|
52 | map<int,CArray<T,1>> tmpArrayOut ; |
---|
53 | for(auto it : recvRankSize_) |
---|
54 | { |
---|
55 | auto& array = tmpArrayOut[it.first] ; |
---|
56 | array.resize(it.second) ; |
---|
57 | MPI_Irecv(array.dataFirst(), array.numElements(), MPI_GetType<T>(), it.first, 0, localComm_, &request) ; |
---|
58 | requests.push_back(request) ; |
---|
59 | } |
---|
60 | |
---|
61 | vector<MPI_Status> status(requests.size()) ; |
---|
62 | MPI_Waitall(requests.size(), requests.data(),status.data()) ; |
---|
63 | |
---|
64 | const double nanValue = std::numeric_limits<double>::quiet_NaN(); |
---|
65 | |
---|
66 | if (op == EReduction::none) gridGathererConnector_->transfer(tmpArrayOut, dataOut, nanValue) ; |
---|
67 | else gridGathererConnector_->transfer(tmpArrayOut, dataOut, op) ; |
---|
68 | } |
---|
69 | |
---|
70 | }; |
---|
71 | |
---|
72 | } |
---|
73 | |
---|
74 | #endif |
---|