[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 | std::vector<int> computeConnectedServerRank(const CArray<size_t,1> globalIndexClient); |
---|
| 41 | |
---|
[568] | 42 | /** Default destructor */ |
---|
| 43 | virtual ~CClientServerMappingDistributed(); |
---|
| 44 | |
---|
[584] | 45 | |
---|
| 46 | |
---|
[568] | 47 | protected: |
---|
[569] | 48 | // Redistribute global index and server index among clients |
---|
[568] | 49 | void computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
| 50 | const MPI_Comm& clientIntraComm); |
---|
| 51 | |
---|
[569] | 52 | // Send server index to clients |
---|
[568] | 53 | void sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer, |
---|
| 54 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); |
---|
| 55 | |
---|
[569] | 56 | // Send global index to clients |
---|
[568] | 57 | void sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal, |
---|
| 58 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal); |
---|
| 59 | |
---|
[569] | 60 | // Verify sending request |
---|
| 61 | void testSendRequest(std::list<MPI_Request>& sendRequest); |
---|
[568] | 62 | |
---|
[569] | 63 | // Process request |
---|
| 64 | void processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count); |
---|
| 65 | |
---|
| 66 | // Probe and receive message of global index |
---|
[568] | 67 | void probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount); |
---|
| 68 | |
---|
[569] | 69 | // Probe and receive message of server index |
---|
[568] | 70 | void probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount); |
---|
| 71 | |
---|
[569] | 72 | // Compute range of hashing |
---|
| 73 | void computeHashIndex(); |
---|
| 74 | |
---|
| 75 | // Compute size of receiving buffer for global index |
---|
[568] | 76 | int computeBuffCountIndexGlobal(MPI_Request& requestRecv); |
---|
| 77 | |
---|
[569] | 78 | // Compute size of receiving buffer for server index |
---|
[568] | 79 | int computeBuffCountIndexServer(MPI_Request& requestRecv); |
---|
[569] | 80 | |
---|
| 81 | // Reset request map |
---|
| 82 | void resetReceivingRequestAndCount(); |
---|
| 83 | |
---|
[620] | 84 | protected: |
---|
[569] | 85 | //! Mapping of global index to the corresponding server |
---|
[568] | 86 | boost::unordered_map<size_t,int> globalIndexToServerMapping_; |
---|
| 87 | |
---|
[569] | 88 | //! Bounds of hash index |
---|
[568] | 89 | std::vector<size_t> indexClientHash_; |
---|
| 90 | |
---|
[569] | 91 | //! Number of client |
---|
[568] | 92 | int nbClient_; |
---|
| 93 | |
---|
[569] | 94 | //! Rank of client |
---|
[568] | 95 | int clientRank_; |
---|
| 96 | |
---|
[569] | 97 | //! Counting of buffer for receiving global index |
---|
[568] | 98 | int countIndexGlobal_; |
---|
| 99 | |
---|
[569] | 100 | //! Counting of buffer for receiving server index |
---|
[568] | 101 | int countIndexServer_; |
---|
| 102 | |
---|
[569] | 103 | //! intracommuntion of clients |
---|
[568] | 104 | MPI_Comm clientIntraComm_; |
---|
| 105 | |
---|
[569] | 106 | //! Request returned by MPI_IRecv function about global index |
---|
| 107 | std::map<int, MPI_Request> requestRecvIndexGlobal_; |
---|
| 108 | |
---|
| 109 | //! Request returned by MPI_IRecv function about index of server |
---|
| 110 | std::map<int, MPI_Request> requestRecvIndexServer_; |
---|
| 111 | |
---|
| 112 | //! Mapping client rank and the beginning position of receiving buffer for message of global index from this client |
---|
[568] | 113 | std::map<int, unsigned long*> indexGlobalBuffBegin_; |
---|
| 114 | |
---|
[569] | 115 | //! Mapping client rank and the begining position of receiving buffer for message of server index from this client |
---|
[568] | 116 | std::map<int, int*> indexServerBuffBegin_; |
---|
[585] | 117 | |
---|
| 118 | //! Flag to specify whether data is distributed or not |
---|
| 119 | bool isDataDistributed_; |
---|
[568] | 120 | }; |
---|
| 121 | |
---|
| 122 | } // namespace xios |
---|
| 123 | #endif // __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|