[721] | 1 | /*! |
---|
| 2 | \file client_client_dht_template.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 01 Oct 2015 |
---|
[839] | 5 | \date 15 April 2016 |
---|
[721] | 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" |
---|
[1542] | 17 | #include <unordered_map> |
---|
[829] | 18 | #include "dht_data_types.hpp" |
---|
[721] | 19 | |
---|
| 20 | namespace xios |
---|
| 21 | { |
---|
[833] | 22 | template<typename T, class HierarchyPolicy = DivideAdaptiveComm> class CClientClientDHTTemplate; |
---|
[721] | 23 | |
---|
| 24 | /*! |
---|
| 25 | \class CClientClientDHTTemplate |
---|
| 26 | This class provides the similar features like \class CClientServerMappingDistributed, |
---|
| 27 | which implements a simple distributed hashed table; Moreover, by extending with hierarchical structure, |
---|
| 28 | it allows to reduce greatly the number of communication among processes. |
---|
| 29 | */ |
---|
| 30 | template<typename T, typename HierarchyPolicy> |
---|
| 31 | class CClientClientDHTTemplate: public HierarchyPolicy |
---|
| 32 | { |
---|
| 33 | public: |
---|
| 34 | typedef T InfoType; |
---|
[727] | 35 | static const int infoTypeSize = sizeof(InfoType); |
---|
[1542] | 36 | // typedef typename std::unordered_map<InfoType, std::vector<size_t> > InfoType2IndexMap; |
---|
| 37 | typedef typename std::unordered_map<size_t,InfoType> Index2InfoTypeMap; |
---|
| 38 | typedef typename std::unordered_map<size_t,std::vector<InfoType> > Index2VectorInfoTypeMap; |
---|
[721] | 39 | |
---|
| 40 | public: |
---|
[829] | 41 | CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap, |
---|
[1639] | 42 | const MPI_Comm& clientIntraComm); |
---|
[721] | 43 | |
---|
[860] | 44 | CClientClientDHTTemplate(const Index2VectorInfoTypeMap& indexInfoInitMap, |
---|
[1639] | 45 | const MPI_Comm& clientIntraComm); |
---|
[860] | 46 | |
---|
[721] | 47 | void computeIndexInfoMapping(const CArray<size_t,1>& indices); |
---|
| 48 | |
---|
[860] | 49 | const Index2VectorInfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; } |
---|
[869] | 50 | Index2VectorInfoTypeMap& getInfoIndexMap() {return indexToInfoMappingLevel_; } |
---|
[843] | 51 | int getNbClient() { return nbClient_; } |
---|
| 52 | |
---|
[721] | 53 | /** Default destructor */ |
---|
| 54 | virtual ~CClientClientDHTTemplate(); |
---|
| 55 | |
---|
| 56 | protected: |
---|
[1639] | 57 | CClientClientDHTTemplate(const MPI_Comm& clientIntraComm); |
---|
[892] | 58 | |
---|
| 59 | protected: |
---|
| 60 | |
---|
| 61 | |
---|
[721] | 62 | // Redistribute index and info among clients |
---|
[829] | 63 | void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap, |
---|
[1639] | 64 | const MPI_Comm& intraCommLevel, |
---|
[721] | 65 | int level); |
---|
| 66 | |
---|
[860] | 67 | void computeDistributedIndex(const Index2VectorInfoTypeMap& indexInfoInitMap, |
---|
[1639] | 68 | const MPI_Comm& intraCommLevel, |
---|
[860] | 69 | int level); |
---|
| 70 | |
---|
| 71 | |
---|
[721] | 72 | void computeHashIndex(std::vector<size_t>& indexClientHash, int nbClient); |
---|
| 73 | |
---|
| 74 | void computeIndexInfoMappingLevel(const CArray<size_t,1>& indices, |
---|
[1639] | 75 | const MPI_Comm& intraCommLevel, |
---|
[721] | 76 | int level); |
---|
| 77 | |
---|
[833] | 78 | void computeSendRecvRank(int level, int rank); |
---|
| 79 | |
---|
| 80 | void sendRecvRank(int level, |
---|
| 81 | const std::vector<int>& sendNbRank, const std::vector<int>& sendNbElements, |
---|
[839] | 82 | std::vector<int>& recvNbRank, std::vector<int>& recvNbElements); |
---|
[833] | 83 | |
---|
[721] | 84 | protected: |
---|
[830] | 85 | // Send information to clients |
---|
| 86 | void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize, |
---|
[1639] | 87 | const MPI_Comm& clientIntraComm, |
---|
| 88 | std::vector<MPI_Request>& requestSendInfo); |
---|
[721] | 89 | |
---|
[839] | 90 | void recvInfoFromClients(int clientSrcRank, unsigned char* info, int infoSize, |
---|
[1639] | 91 | const MPI_Comm& clientIntraComm, |
---|
| 92 | std::vector<MPI_Request>& requestRecvInfo); |
---|
[839] | 93 | |
---|
[721] | 94 | // Send global index to clients |
---|
[833] | 95 | void sendIndexToClients(int clientDestRank, size_t* indices, size_t indiceSize, |
---|
[1639] | 96 | const MPI_Comm& clientIntraComm, |
---|
| 97 | std::vector<MPI_Request>& requestSendIndexGlobal); |
---|
[721] | 98 | |
---|
[839] | 99 | void recvIndexFromClients(int clientSrcRank, size_t* indices, size_t indiceSize, |
---|
[1639] | 100 | const MPI_Comm& clientIntraComm, |
---|
| 101 | std::vector<MPI_Request>& requestRecvIndex); |
---|
[721] | 102 | |
---|
[839] | 103 | void sendRecvOnReturn(const std::vector<int>& sendNbRank, std::vector<int>& sendNbElements, |
---|
| 104 | const std::vector<int>& recvNbRank, std::vector<int>& recvNbElements); |
---|
[721] | 105 | |
---|
| 106 | protected: |
---|
| 107 | //! Mapping of global index to the corresponding client |
---|
[860] | 108 | Index2VectorInfoTypeMap index2InfoMapping_; |
---|
[721] | 109 | |
---|
[830] | 110 | //! A mapping of index to the corresponding information in each level of hierarchy |
---|
[860] | 111 | Index2VectorInfoTypeMap indexToInfoMappingLevel_; |
---|
[721] | 112 | |
---|
[867] | 113 | //! Rank of client to send on each DHT level |
---|
[833] | 114 | std::vector<std::vector<int> > sendRank_; |
---|
[721] | 115 | |
---|
[867] | 116 | //! Rank of client to receive on each DHT level |
---|
[833] | 117 | std::vector<std::vector<int> > recvRank_; |
---|
| 118 | |
---|
[721] | 119 | //! Flag to specify whether data is distributed or not |
---|
| 120 | bool isDataDistributed_; |
---|
[843] | 121 | |
---|
| 122 | //! Number of client |
---|
| 123 | int nbClient_; |
---|
[721] | 124 | }; |
---|
| 125 | |
---|
| 126 | typedef CClientClientDHTTemplate<int> CClientClientDHTInt; |
---|
[924] | 127 | typedef CClientClientDHTTemplate<size_t> CClientClientDHTSizet; |
---|
[941] | 128 | typedef CClientClientDHTTemplate<double> CClientClientDHTDouble; |
---|
[829] | 129 | typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt; |
---|
[721] | 130 | |
---|
| 131 | } // namespace xios |
---|
| 132 | #endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__ |
---|