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 | |
---|
11 | #ifndef __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|
12 | #define __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|
13 | |
---|
14 | #include <client_server_mapping.hpp> |
---|
15 | #include "xios_spl.hpp" |
---|
16 | #include "array_new.hpp" |
---|
17 | #include "mpi.hpp" |
---|
18 | #include <boost/unordered_map.hpp> |
---|
19 | |
---|
20 | namespace xios |
---|
21 | { |
---|
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 | */ |
---|
31 | class CClientServerMappingDistributed : public CClientServerMapping |
---|
32 | { |
---|
33 | public: |
---|
34 | /** Default constructor */ |
---|
35 | CClientServerMappingDistributed(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
36 | const MPI_Comm& clientIntraComm, bool isDataDistributed = true); |
---|
37 | |
---|
38 | virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClientSendToServer); |
---|
39 | |
---|
40 | std::vector<int> computeConnectedServerRank(const CArray<size_t,1> globalIndexClient); |
---|
41 | |
---|
42 | /** Default destructor */ |
---|
43 | virtual ~CClientServerMappingDistributed(); |
---|
44 | |
---|
45 | |
---|
46 | |
---|
47 | protected: |
---|
48 | // Redistribute global index and server index among clients |
---|
49 | void computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer, |
---|
50 | const MPI_Comm& clientIntraComm); |
---|
51 | |
---|
52 | // Send server index to clients |
---|
53 | void sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer, |
---|
54 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); |
---|
55 | |
---|
56 | // Send global index to clients |
---|
57 | void sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal, |
---|
58 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal); |
---|
59 | |
---|
60 | // Verify sending request |
---|
61 | void testSendRequest(std::list<MPI_Request>& sendRequest); |
---|
62 | |
---|
63 | // Process request |
---|
64 | void processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count); |
---|
65 | |
---|
66 | // Probe and receive message of global index |
---|
67 | void probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount); |
---|
68 | |
---|
69 | // Probe and receive message of server index |
---|
70 | void probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount); |
---|
71 | |
---|
72 | // Compute range of hashing |
---|
73 | void computeHashIndex(); |
---|
74 | |
---|
75 | // Compute size of receiving buffer for global index |
---|
76 | int computeBuffCountIndexGlobal(MPI_Request& requestRecv); |
---|
77 | |
---|
78 | // Compute size of receiving buffer for server index |
---|
79 | int computeBuffCountIndexServer(MPI_Request& requestRecv); |
---|
80 | |
---|
81 | // Reset request map |
---|
82 | void resetReceivingRequestAndCount(); |
---|
83 | |
---|
84 | protected: |
---|
85 | //! Mapping of global index to the corresponding server |
---|
86 | boost::unordered_map<size_t,int> globalIndexToServerMapping_; |
---|
87 | |
---|
88 | //! Bounds of hash index |
---|
89 | std::vector<size_t> indexClientHash_; |
---|
90 | |
---|
91 | //! Number of client |
---|
92 | int nbClient_; |
---|
93 | |
---|
94 | //! Rank of client |
---|
95 | int clientRank_; |
---|
96 | |
---|
97 | //! Counting of buffer for receiving global index |
---|
98 | int countIndexGlobal_; |
---|
99 | |
---|
100 | //! Counting of buffer for receiving server index |
---|
101 | int countIndexServer_; |
---|
102 | |
---|
103 | //! intracommuntion of clients |
---|
104 | MPI_Comm clientIntraComm_; |
---|
105 | |
---|
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 |
---|
113 | std::map<int, unsigned long*> indexGlobalBuffBegin_; |
---|
114 | |
---|
115 | //! Mapping client rank and the begining position of receiving buffer for message of server index from this client |
---|
116 | std::map<int, int*> indexServerBuffBegin_; |
---|
117 | |
---|
118 | //! Flag to specify whether data is distributed or not |
---|
119 | bool isDataDistributed_; |
---|
120 | }; |
---|
121 | |
---|
122 | } // namespace xios |
---|
123 | #endif // __XIOS_CLIENT_SERVER_MAPPING_DISTRIBUTED_HPP__ |
---|