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