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

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

Implementing pack and unpack function for generic type of dht

+) Replace union with the more generic function for packing data into buffer and unpacking data from buffer
+) Change PairIntInt? from struct to std::pair<int,int>

Test
+) On Curie
+) All tests pass

File size: 4.3 KB
Line 
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#include "dht_data_types.hpp"
19
20namespace xios
21{
22template<typename T, class HierarchyPolicy = DivideCommByTwo> class CClientClientDHTTemplate;
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;
35    static const int infoTypeSize = sizeof(InfoType);
36    typedef typename boost::unordered_map<InfoType, std::vector<size_t> > InfoType2IndexMap;
37    typedef typename boost::unordered_map<size_t,InfoType> Index2InfoTypeMap;
38
39  public:
40    CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap,
41                             const MPI_Comm& clientIntraComm,
42                             int hierarLvl = 2);
43
44    void computeIndexInfoMapping(const CArray<size_t,1>& indices);
45
46    const Index2InfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; }
47
48    /** Default destructor */
49    virtual ~CClientClientDHTTemplate();
50
51  protected:
52    // Redistribute index and info among clients
53    void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap,
54                                 const MPI_Comm& intraCommLevel,
55                                 int level);
56
57    void computeHashIndex(std::vector<size_t>& indexClientHash, int nbClient);
58
59    void computeIndexInfoMappingLevel(const CArray<size_t,1>& indices,
60                                      const MPI_Comm& intraCommLevel,
61                                      int level);
62
63  protected:
64    void probeIndexMessageFromClients(unsigned long* recvIndexGlobalBuff,
65                                      const int recvNbIndexCount,
66                                      int& countIndexGlobal,
67                                      std::map<int, unsigned long*>& indexGlobalBuffBegin,
68                                      std::map<int, MPI_Request>& requestRecvIndexGlobal,
69                                      const MPI_Comm& intraComm);
70
71    void probeInfoMessageFromClients(unsigned char* recvIndexServerBuff,
72                                     const int recvNbIndexCount,
73                                     int& countIndexServer,
74                                     std::map<int, unsigned char*>& infoBuffBegin,
75                                     std::map<int, MPI_Request>& requestRecvIndexServer,
76                                     const MPI_Comm& intraComm);
77
78    // Send information to clients
79    void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
80                           const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer);
81
82    // Send global index to clients
83    void sendIndexToClients(int clientDestRank, std::vector<size_t>& indexGlobal,
84                            const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal);
85
86    // Verify sending request
87    void testSendRequest(std::list<MPI_Request>& sendRequest);
88
89    // Compute size of receiving buffer for global index
90    int computeBuffCountIndex(MPI_Request& requestRecv);
91
92    // Compute size of receiving buffer for server index
93    int computeBuffCountInfo(MPI_Request& requestRecv);
94
95  protected:
96    //! Mapping of global index to the corresponding client
97    Index2InfoTypeMap index2InfoMapping_;
98
99    //! A mapping of index to the corresponding information in each level of hierarchy
100    Index2InfoTypeMap indexToInfoMappingLevel_;
101
102    //! intracommuntion of clients
103    MPI_Comm intraCommRoot_;
104
105    //! Flag to specify whether data is distributed or not
106    bool isDataDistributed_;
107};
108
109typedef CClientClientDHTTemplate<int> CClientClientDHTInt;
110typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt;
111
112} // namespace xios
113#endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__
Note: See TracBrowser for help on using the repository browser.