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