[1918] | 1 | #ifndef __REMOTE_CONNECTOR_HPP__ |
---|
| 2 | #define __REMOTE_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 | |
---|
| 12 | |
---|
| 13 | namespace xios |
---|
| 14 | { |
---|
| 15 | |
---|
| 16 | class CRemoteConnector |
---|
| 17 | { |
---|
| 18 | private: |
---|
| 19 | CLocalView* srcView_; |
---|
| 20 | CDistributedView* dstView_; |
---|
| 21 | map<int, vector<int>> connector_ ; // connector[rank][srcIndex] |
---|
| 22 | |
---|
| 23 | MPI_Comm localComm_ ; |
---|
| 24 | map<int,int> nbSenders_ ; // number of participant when sending remote buffer |
---|
| 25 | map<int, CArray<size_t,1>> element_ ; // global index of elements to send |
---|
| 26 | |
---|
| 27 | public: |
---|
| 28 | CRemoteConnector(CLocalView* srcView, CDistributedView* dstView, MPI_Comm localComm) : srcView_(srcView), dstView_(dstView), localComm_(localComm){} ; |
---|
| 29 | void computeConnector(void) ; |
---|
| 30 | map<int, CArray<size_t,1>>& getDistributedGlobalIndex() { return element_ ;} |
---|
| 31 | |
---|
| 32 | template<typename T> |
---|
| 33 | void transfer(const CArray<T,1>& dataIn, map<int, CArray<T,1>>& dataOut) |
---|
| 34 | { |
---|
| 35 | auto ptrDataIn = dataIn.dataFirst() ; |
---|
| 36 | for(auto& indexRank : connector_) |
---|
| 37 | { |
---|
| 38 | int rank=indexRank.first ; |
---|
| 39 | auto& index=indexRank.second ; |
---|
| 40 | auto it = dataOut.emplace(rank, CArray<T,1>(index.size())).first ; // return an iterator on the obect inserted |
---|
| 41 | auto ptrDataOut = it->second.dataFirst() ; |
---|
| 42 | for(auto ind : index) |
---|
| 43 | { |
---|
| 44 | *ptrDataOut = ptrDataIn[ind] ; |
---|
| 45 | ptrDataOut++ ; |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | template<typename T> |
---|
| 51 | void sendToServer(map<int, CArray<T,1>>& dataOut, CContextClient* client, CEventClient& event, const CMessage& messageHeader) |
---|
| 52 | { |
---|
| 53 | list<CMessage> messages; |
---|
| 54 | for(auto ranksData : dataOut) |
---|
| 55 | { |
---|
| 56 | int rank = ranksData.first ; |
---|
| 57 | auto& data = ranksData.second ; |
---|
| 58 | |
---|
| 59 | messages.push_back(CMessage(messageHeader)); |
---|
| 60 | messages.back().push(data) ; |
---|
| 61 | event.push(rank, nbSenders_[rank], messages.back()); |
---|
| 62 | } |
---|
| 63 | client->sendEvent(event) ; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | template<typename T> |
---|
| 67 | void transferToServer(const CArray<T,1>& dataIn, CContextClient* client, CEventClient& event, const CMessage& messageHeader) |
---|
| 68 | { |
---|
| 69 | map<int, CArray<T,1>> dataOut ; |
---|
| 70 | transfer(dataIn, dataOut) ; |
---|
| 71 | sendToServer(dataOut, client, event,messageHeader) ; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | } ; |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | #endif |
---|