[569] | 1 | /*! |
---|
| 2 | \file client_server_mapping.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 27 Feb 2015 |
---|
| 5 | \date 09 Mars 2015 |
---|
| 6 | |
---|
| 7 | \brief Mapping between index client and server. |
---|
| 8 | Clients pre-calculate all information of server distribution. |
---|
| 9 | */ |
---|
| 10 | |
---|
[568] | 11 | #ifndef __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|
| 12 | #define __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|
| 13 | |
---|
| 14 | #include <client_server_mapping.hpp> |
---|
[591] | 15 | #include "xios_spl.hpp" |
---|
[568] | 16 | #include "array_new.hpp" |
---|
| 17 | #include "mpi.hpp" |
---|
| 18 | #include <boost/unordered_map.hpp> |
---|
| 19 | |
---|
| 20 | namespace xios |
---|
| 21 | { |
---|
[569] | 22 | /*! |
---|
| 23 | \class CClientServerMappingDistributed |
---|
| 24 | This class computes index of data which are sent to server as well as index of data |
---|
| 25 | on server side with a distributed alogrithm. Each client has a piece of information about the distribution |
---|
| 26 | of servers. To find out all these info, first of all, all client join a discovering process in which each client |
---|
| 27 | announces the others about the info they have as well as demand others info they are lacked of. After this process, |
---|
| 28 | each client has enough info to decide to which client it need to send a demand for corresponding server of a global index. |
---|
| 29 | The alogrithm depends on hashed index. |
---|
| 30 | */ |
---|
[568] | 31 | class CClientServerMappingDistributed : public CClientServerMapping |
---|
| 32 | { |
---|
| 33 | public: |
---|
| 34 | /** Default constructor */ |
---|
| 35 | CClientServerMappingDistributed(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
[585] | 36 | const MPI_Comm& clientIntraComm, bool isDataDistributed = true); |
---|
[568] | 37 | |
---|
[584] | 38 | virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClientSendToServer); |
---|
[569] | 39 | |
---|
[584] | 40 | // virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClientSendToServer, |
---|
| 41 | // const CArray<int,1>& localIndexOnClientSendToServer); |
---|
[568] | 42 | |
---|
[584] | 43 | std::vector<int> computeConnectedServerRank(const CArray<size_t,1> globalIndexClient); |
---|
| 44 | |
---|
[568] | 45 | /** Default destructor */ |
---|
| 46 | virtual ~CClientServerMappingDistributed(); |
---|
| 47 | |
---|
[584] | 48 | |
---|
| 49 | |
---|
[568] | 50 | protected: |
---|
[569] | 51 | // Redistribute global index and server index among clients |
---|
[568] | 52 | void computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
| 53 | const MPI_Comm& clientIntraComm); |
---|
| 54 | |
---|
[569] | 55 | // Send server index to clients |
---|
[568] | 56 | void sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer, |
---|
| 57 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); |
---|
| 58 | |
---|
[569] | 59 | // Send global index to clients |
---|
[568] | 60 | void sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal, |
---|
| 61 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal); |
---|
| 62 | |
---|
[569] | 63 | // Verify sending request |
---|
| 64 | void testSendRequest(std::list<MPI_Request>& sendRequest); |
---|
[568] | 65 | |
---|
[569] | 66 | // Process request |
---|
| 67 | void processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count); |
---|
| 68 | |
---|
| 69 | // Probe and receive message of global index |
---|
[568] | 70 | void probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount); |
---|
| 71 | |
---|
[569] | 72 | // Probe and receive message of server index |
---|
[568] | 73 | void probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount); |
---|
| 74 | |
---|
[569] | 75 | // Compute range of hashing |
---|
| 76 | void computeHashIndex(); |
---|
| 77 | |
---|
| 78 | // Compute size of receiving buffer for global index |
---|
[568] | 79 | int computeBuffCountIndexGlobal(MPI_Request& requestRecv); |
---|
| 80 | |
---|
[569] | 81 | // Compute size of receiving buffer for server index |
---|
[568] | 82 | int computeBuffCountIndexServer(MPI_Request& requestRecv); |
---|
[569] | 83 | |
---|
| 84 | // Reset request map |
---|
| 85 | void resetReceivingRequestAndCount(); |
---|
| 86 | |
---|
[568] | 87 | private: |
---|
[569] | 88 | //! Mapping of global index to the corresponding server |
---|
[568] | 89 | boost::unordered_map<size_t,int> globalIndexToServerMapping_; |
---|
| 90 | |
---|
[569] | 91 | //! Bounds of hash index |
---|
[568] | 92 | std::vector<size_t> indexClientHash_; |
---|
| 93 | |
---|
[569] | 94 | //! Number of client |
---|
[568] | 95 | int nbClient_; |
---|
| 96 | |
---|
[569] | 97 | //! Rank of client |
---|
[568] | 98 | int clientRank_; |
---|
| 99 | |
---|
[569] | 100 | //! Counting of buffer for receiving global index |
---|
[568] | 101 | int countIndexGlobal_; |
---|
| 102 | |
---|
[569] | 103 | //! Counting of buffer for receiving server index |
---|
[568] | 104 | int countIndexServer_; |
---|
| 105 | |
---|
[569] | 106 | //! intracommuntion of clients |
---|
[568] | 107 | MPI_Comm clientIntraComm_; |
---|
| 108 | |
---|
[569] | 109 | //! Request returned by MPI_IRecv function about global index |
---|
| 110 | std::map<int, MPI_Request> requestRecvIndexGlobal_; |
---|
| 111 | |
---|
| 112 | //! Request returned by MPI_IRecv function about index of server |
---|
| 113 | std::map<int, MPI_Request> requestRecvIndexServer_; |
---|
| 114 | |
---|
| 115 | //! Mapping client rank and the beginning position of receiving buffer for message of global index from this client |
---|
[568] | 116 | std::map<int, unsigned long*> indexGlobalBuffBegin_; |
---|
| 117 | |
---|
[569] | 118 | //! Mapping client rank and the begining position of receiving buffer for message of server index from this client |
---|
[568] | 119 | std::map<int, int*> indexServerBuffBegin_; |
---|
[585] | 120 | |
---|
| 121 | //! Flag to specify whether data is distributed or not |
---|
| 122 | bool isDataDistributed_; |
---|
[568] | 123 | }; |
---|
| 124 | |
---|
| 125 | } // namespace xios |
---|
| 126 | #endif // __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|