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

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

Exposing some functions to Fortran interface

+) Allow add axis and domain into grid with Fortran interface
+) Remove some redundant code

Test
+) On Curie
+) test_client passes

File size: 4.6 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 = 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                      int& recvNbRank, int& recvNbElements);
67
68  protected:
69    void probeIndexMessageFromClients(unsigned long* recvIndexGlobalBuff,
70                                      const int recvNbIndexCount,
71                                      int& countIndexGlobal,
72                                      std::map<int, unsigned long*>& indexGlobalBuffBegin,
73                                      std::map<int, MPI_Request>& requestRecvIndexGlobal,
74                                      const MPI_Comm& intraComm);
75
76    void probeInfoMessageFromClients(unsigned char* recvIndexServerBuff,
77                                     const int recvNbIndexCount,
78                                     int& countIndexServer,
79                                     std::map<int, unsigned char*>& infoBuffBegin,
80                                     std::map<int, MPI_Request>& requestRecvIndexServer,
81                                     const MPI_Comm& intraComm);
82
83    // Send information to clients
84    void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize,
85                           const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer);
86
87    // Send global index to clients
88    void sendIndexToClients(int clientDestRank, size_t* indices, size_t indiceSize,
89                            const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal);
90
91    // Verify sending request
92    void testSendRequest(std::list<MPI_Request>& sendRequest);
93
94    // Compute size of receiving buffer for global index
95    int computeBuffCountIndex(MPI_Request& requestRecv);
96
97    // Compute size of receiving buffer for server index
98    int computeBuffCountInfo(MPI_Request& requestRecv);
99
100  protected:
101    //! Mapping of global index to the corresponding client
102    Index2InfoTypeMap index2InfoMapping_;
103
104    //! A mapping of index to the corresponding information in each level of hierarchy
105    Index2InfoTypeMap indexToInfoMappingLevel_;
106
107    std::vector<std::vector<int> > sendRank_;
108
109    std::vector<std::vector<int> > recvRank_;
110
111    //! Flag to specify whether data is distributed or not
112    bool isDataDistributed_;
113};
114
115typedef CClientClientDHTTemplate<int> CClientClientDHTInt;
116typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt;
117
118} // namespace xios
119#endif // __XIOS_CLIENT_CLIENT_DHT_TEMPLATE_HPP__
Note: See TracBrowser for help on using the repository browser.