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

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

Several improvements

+) Replace some time-consuming operations by simpler ones

Test
+) On Curie
+) All tests pass

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