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

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

Various clean up

+) Remove some redundant codes

Test
+) On Curie
+) tests pass

File size: 4.7 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    typedef typename boost::unordered_map<size_t,std::vector<InfoType> > Index2VectorInfoTypeMap;
39
40  public:
41    CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap,
42                             const MPI_Comm& clientIntraComm);
43
44    CClientClientDHTTemplate(const Index2VectorInfoTypeMap& indexInfoInitMap,
45                             const MPI_Comm& clientIntraComm);
46
47    void computeIndexInfoMapping(const CArray<size_t,1>& indices);
48
49    const Index2VectorInfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; }
50    int getNbClient() { return nbClient_; }
51
52    /** Default destructor */
53    virtual ~CClientClientDHTTemplate();
54
55  protected:
56    // Redistribute index and info among clients
57    void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap,
58                                 const MPI_Comm& intraCommLevel,
59                                 int level);
60
61    void computeDistributedIndex(const Index2VectorInfoTypeMap& indexInfoInitMap,
62                                 const MPI_Comm& intraCommLevel,
63                                 int level);
64
65
66    void computeHashIndex(std::vector<size_t>& indexClientHash, int nbClient);
67
68    void computeIndexInfoMappingLevel(const CArray<size_t,1>& indices,
69                                      const MPI_Comm& intraCommLevel,
70                                      int level);
71
72    void computeSendRecvRank(int level, int rank);
73
74    void sendRecvRank(int level,
75                      const std::vector<int>& sendNbRank, const std::vector<int>& sendNbElements,
76                      std::vector<int>& recvNbRank, std::vector<int>& recvNbElements);
77
78  protected:
79    // Send information to clients
80    void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
81                           const MPI_Comm& clientIntraComm,
82                           std::vector<MPI_Request>& requestSendInfo);
83
84    void recvInfoFromClients(int clientSrcRank, unsigned char* info, int infoSize,
85                            const MPI_Comm& clientIntraComm,
86                            std::vector<MPI_Request>& requestRecvInfo);
87
88    // Send global index to clients
89    void sendIndexToClients(int clientDestRank, size_t* indices, size_t indiceSize,
90                            const MPI_Comm& clientIntraComm,
91                            std::vector<MPI_Request>& requestSendIndexGlobal);
92
93    void recvIndexFromClients(int clientSrcRank, size_t* indices, size_t indiceSize,
94                             const MPI_Comm& clientIntraComm,
95                             std::vector<MPI_Request>& requestRecvIndex);
96
97    void sendRecvOnReturn(const std::vector<int>& sendNbRank, std::vector<int>& sendNbElements,
98                          const std::vector<int>& recvNbRank, std::vector<int>& recvNbElements);
99
100  protected:
101    //! Mapping of global index to the corresponding client
102    Index2VectorInfoTypeMap index2InfoMapping_;
103
104    //! A mapping of index to the corresponding information in each level of hierarchy
105    Index2VectorInfoTypeMap indexToInfoMappingLevel_;
106
107    //! Rank of client to send on each DHT level
108    std::vector<std::vector<int> > sendRank_;
109
110    //! Rank of client to receive on each DHT level
111    std::vector<std::vector<int> > recvRank_;
112
113    //! Flag to specify whether data is distributed or not
114    bool isDataDistributed_;
115
116    //! Number of client
117    int nbClient_;
118};
119
120typedef CClientClientDHTTemplate<int> CClientClientDHTInt;
121typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt;
122
123} // namespace xios
124#endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__
Note: See TracBrowser for help on using the repository browser.