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

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

Correcting a bug in dht

+) The exchange message (MPI_Isend,MPI_Irecv) must be finished in each level
+) If there are no corresponding information found, dht will return a empty array.
+) Remove some redundant codes

Test
+) On Curie
+) Up to 40 cores (3 levels)
+) All tests pass

File size: 4.1 KB
Line 
1/*!
2   \file client_client_dht_template.hpp
3   \author Ha NGUYEN
4   \since 01 Oct 2015
5   \date 15 April 2016
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 = DivideAdaptiveComm> 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
43    void computeIndexInfoMapping(const CArray<size_t,1>& indices);
44
45    const Index2InfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; }
46
47    /** Default destructor */
48    virtual ~CClientClientDHTTemplate();
49
50  protected:
51    // Redistribute index and info among clients
52    void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap,
53                                 const MPI_Comm& intraCommLevel,
54                                 int level);
55
56    void computeHashIndex(std::vector<size_t>& indexClientHash, int nbClient);
57
58    void computeIndexInfoMappingLevel(const CArray<size_t,1>& indices,
59                                      const MPI_Comm& intraCommLevel,
60                                      int level);
61
62    void computeSendRecvRank(int level, int rank);
63
64    void sendRecvRank(int level,
65                      const std::vector<int>& sendNbRank, const std::vector<int>& sendNbElements,
66                      std::vector<int>& recvNbRank, std::vector<int>& recvNbElements);
67
68  protected:
69    // Send information to clients
70    void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
71                           const MPI_Comm& clientIntraComm,
72                           std::vector<MPI_Request>& requestSendInfo);
73
74    void recvInfoFromClients(int clientSrcRank, unsigned char* info, int infoSize,
75                            const MPI_Comm& clientIntraComm,
76                            std::vector<MPI_Request>& requestRecvInfo);
77
78    // Send global index to clients
79    void sendIndexToClients(int clientDestRank, size_t* indices, size_t indiceSize,
80                            const MPI_Comm& clientIntraComm,
81                            std::vector<MPI_Request>& requestSendIndexGlobal);
82
83    void recvIndexFromClients(int clientSrcRank, size_t* indices, size_t indiceSize,
84                             const MPI_Comm& clientIntraComm,
85                             std::vector<MPI_Request>& requestRecvIndex);
86
87    void sendRecvOnReturn(const std::vector<int>& sendNbRank, std::vector<int>& sendNbElements,
88                          const std::vector<int>& recvNbRank, std::vector<int>& recvNbElements);
89
90  protected:
91    //! Mapping of global index to the corresponding client
92    Index2InfoTypeMap index2InfoMapping_;
93
94    //! A mapping of index to the corresponding information in each level of hierarchy
95    Index2InfoTypeMap indexToInfoMappingLevel_;
96
97    std::vector<std::vector<int> > sendRank_;
98
99    std::vector<std::vector<int> > recvRank_;
100
101    //! Flag to specify whether data is distributed or not
102    bool isDataDistributed_;
103};
104
105typedef CClientClientDHTTemplate<int> CClientClientDHTInt;
106typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt;
107
108} // namespace xios
109#endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__
Note: See TracBrowser for help on using the repository browser.