source: XIOS/trunk/src/client_client_dht_template.hpp @ 863

Last change on this file since 863 was 860, checked in by mhnguyen, 8 years ago

Improvement of DHT: allow multiple values correspond to one key

+) If there are several returned values corresponding to one key,
all of them are returned by DHT in vector.

Test
+) Testing only very basic. This commit serves as temporary one.

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