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