[721] | 1 | /*! |
---|
| 2 | \file client_client_dht_template.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 01 Oct 2015 |
---|
| 5 | \date 06 Oct 2015 |
---|
| 6 | |
---|
| 7 | \brief Distributed hashed table implementation. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | #ifndef __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__ |
---|
| 11 | #define __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__ |
---|
| 12 | |
---|
| 13 | #include "xios_spl.hpp" |
---|
| 14 | #include "array_new.hpp" |
---|
| 15 | #include "mpi.hpp" |
---|
| 16 | #include "policy.hpp" |
---|
| 17 | #include <boost/unordered_map.hpp> |
---|
| 18 | |
---|
| 19 | namespace xios |
---|
| 20 | { |
---|
| 21 | template<typename T, class HierarchyPolicy = DivideCommByTwo> class CClientClientDHTTemplate; |
---|
| 22 | |
---|
| 23 | /*! |
---|
| 24 | \class CClientClientDHTTemplate |
---|
| 25 | This class provides the similar features like \class CClientServerMappingDistributed, |
---|
| 26 | which implements a simple distributed hashed table; Moreover, by extending with hierarchical structure, |
---|
| 27 | it allows to reduce greatly the number of communication among processes. |
---|
| 28 | */ |
---|
| 29 | template<typename T, typename HierarchyPolicy> |
---|
| 30 | class CClientClientDHTTemplate: public HierarchyPolicy |
---|
| 31 | { |
---|
| 32 | public: |
---|
| 33 | typedef T InfoType; |
---|
[727] | 34 | static const int infoTypeSize = sizeof(InfoType); |
---|
[721] | 35 | |
---|
| 36 | public: |
---|
| 37 | /** Default constructor */ |
---|
| 38 | CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoInitMap, |
---|
| 39 | const MPI_Comm& clientIntraComm, |
---|
| 40 | int hierarLvl = 2); |
---|
| 41 | |
---|
| 42 | void computeIndexInfoMapping(const CArray<size_t,1>& indices); |
---|
| 43 | |
---|
| 44 | const std::map<T, std::vector<size_t> >& getInfoIndexMap() const {return indexGlobalOnServer_; } |
---|
| 45 | |
---|
| 46 | /** Default destructor */ |
---|
| 47 | virtual ~CClientClientDHTTemplate(); |
---|
| 48 | |
---|
| 49 | protected: |
---|
| 50 | // Redistribute index and info among clients |
---|
| 51 | void computeDistributedIndex(const boost::unordered_map<size_t,T>& indexInfoInitMap, |
---|
| 52 | const MPI_Comm& intraCommLevel, |
---|
| 53 | int level); |
---|
| 54 | |
---|
| 55 | void computeHashIndex(std::vector<size_t>& indexClientHash, int nbClient); |
---|
| 56 | |
---|
| 57 | void computeIndexInfoMappingLevel(const CArray<size_t,1>& indices, |
---|
| 58 | const MPI_Comm& intraCommLevel, |
---|
| 59 | int level); |
---|
| 60 | |
---|
| 61 | protected: |
---|
| 62 | void probeIndexMessageFromClients(unsigned long* recvIndexGlobalBuff, |
---|
| 63 | const int recvNbIndexCount, |
---|
| 64 | int& countIndexGlobal, |
---|
| 65 | std::map<int, unsigned long*>& indexGlobalBuffBegin, |
---|
| 66 | std::map<int, MPI_Request>& requestRecvIndexGlobal, |
---|
| 67 | const MPI_Comm& intraComm); |
---|
| 68 | |
---|
| 69 | void probeInfoMessageFromClients(InfoType* recvIndexServerBuff, |
---|
| 70 | const int recvNbIndexCount, |
---|
| 71 | int& countIndexServer, |
---|
| 72 | std::map<int, InfoType*>& indexServerBuffBegin, |
---|
| 73 | std::map<int, MPI_Request>& requestRecvIndexServer, |
---|
| 74 | const MPI_Comm& intraComm); |
---|
| 75 | |
---|
| 76 | // Send server index to clients |
---|
| 77 | void sendInfoToClients(int clientDestRank, std::vector<InfoType>& indexServer, |
---|
| 78 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); |
---|
| 79 | |
---|
| 80 | // Send global index to clients |
---|
| 81 | void sendIndexToClients(int clientDestRank, std::vector<size_t>& indexGlobal, |
---|
| 82 | const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal); |
---|
| 83 | |
---|
| 84 | // Verify sending request |
---|
| 85 | void testSendRequest(std::list<MPI_Request>& sendRequest); |
---|
| 86 | |
---|
| 87 | // Compute size of receiving buffer for global index |
---|
| 88 | int computeBuffCountIndex(MPI_Request& requestRecv); |
---|
| 89 | |
---|
| 90 | // Compute size of receiving buffer for server index |
---|
| 91 | int computeBuffCountInfo(MPI_Request& requestRecv); |
---|
| 92 | |
---|
| 93 | protected: |
---|
| 94 | //! Mapping of global index to the corresponding client |
---|
| 95 | boost::unordered_map<size_t,InfoType> index2InfoMapping_; |
---|
| 96 | |
---|
| 97 | //! A temporary mapping of index to the corresponding information in each level of hierarchy |
---|
| 98 | boost::unordered_map<size_t,InfoType> indexToInfoMappingLevel_; |
---|
| 99 | |
---|
| 100 | //! Global index of data on SERVER, which are calculated by client(s) |
---|
| 101 | std::map<int, std::vector<size_t> > indexGlobalOnServer_; |
---|
| 102 | |
---|
| 103 | //! intracommuntion of clients |
---|
| 104 | MPI_Comm intraCommRoot_; |
---|
| 105 | |
---|
| 106 | //! Flag to specify whether data is distributed or not |
---|
| 107 | bool isDataDistributed_; |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | typedef CClientClientDHTTemplate<int> CClientClientDHTInt; |
---|
| 111 | |
---|
| 112 | } // namespace xios |
---|
| 113 | #endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__ |
---|