source: XIOS/trunk/src/node/distribution_client.hpp @ 552

Last change on this file since 552 was 552, checked in by mhnguyen, 9 years ago

Doing some cleans and improving a little bit performance of creating local index on server

+) Add some comments, add some initialization
+) Change the way to calculate local index on server

Test
+) On Curie

File size: 4.7 KB
Line 
1#ifndef __XIOS_DISTRIBUTIONCLIENT_HPP__
2#define __XIOS_DISTRIBUTIONCLIENT_HPP__
3
4#include <distribution.hpp>
5#include "axis.hpp"
6#include "domain.hpp"
7#include "grid.hpp"
8
9namespace xios {
10
11class CGrid;
12class CDomain;
13class CAxis;
14
15/*!
16  \class CDistributionClient
17  This class bases on the knowledge of distribution on client side as well as on server side
18to calculate the index mapping between client and server. Each client awaring of the existences of other clients
19and servers, firstly, computes the global index of its local data then use this information on taking into account of
20distribution of servers to calculate to which server(s) it connects (sends data)
21*/
22class CDistributionClient : public CDistribution
23{
24  public:
25    enum ServerDistributionType
26    {
27      BAND_DISTRIBUTION, PLAN_DISTRIBUTION
28    };
29
30    /** Default constructor */
31    CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex = 0);
32    CDistributionClient(int rank, CGrid* grid);
33    CDistributionClient(const CDistributionClient& distClient); //! Not implement
34
35    /** Default destructor */
36    virtual ~CDistributionClient();
37
38    void computeServerIndexMapping(int nServer, ServerDistributionType distType = BAND_DISTRIBUTION);
39    std::map<int,int> computeConnectedClients(int nbServer, int nbClient, MPI_Comm& clientIntraComm);
40
41    const CArray<int,1>& getLocalDataIndexOnClient() const;
42    const std::map<int, std::vector<size_t> >& getGlobalIndexOnServer() const;
43    const std::map<int, std::vector<int> >& getLocalIndexSendToServer() const;
44
45  protected:
46    void createGlobalIndex();
47    void readDistributionInfo(CGrid* grid);
48    void readDistributionInfo(const std::vector<CDomain*>& domList,
49                              const std::vector<CAxis*>& axisList,
50                              const CArray<bool,1>& axisDomainOrder,
51                              const CArray<bool,3>& gridMask);
52
53    inline int getDomainIndex(const int& dataIIndex, const int& dataJIndex,
54                              const int& dataIBegin, const int& dataJBegin,
55                              const int& dataDim, const int& ni, int& j);
56    inline int getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni);
57
58  private:
59    //! Create local index of a domain
60    void createLocalDomainDataIndex();
61    //! Create local index of an axis
62    void createLocalAxisDataIndex();
63
64    //! Compute band distribution on server
65    std::vector<CArray<size_t,1>* > computeServerBandDistribution(int nServer);
66  private:
67    //!< LocalData index on client
68    CArray<int,1>* localDataIndex_;
69
70    //! Index of the local data which will be sent to the corresponding server(s)
71    std::map<int, std::vector<int> >  localIndexSend2Server_;
72
73    //! Global index of data on SERVER, which are calculated by client(s)
74    std::map<int, std::vector<size_t> > indexGlobalOnServer_;
75  private:
76    /*! Domains and axis are considered elements.
77     * A grid composed of 1 domain and 1 axis has 2 elements */
78    int numElement_;
79    CArray<bool,1> axisDomainOrder_; //!<
80
81    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...)
82    std::vector<int> nGlob_; //!< Global size of each dimension (e.x: ni_glo, nj_glo, etc, ...)
83    std::vector<int> nBeginLocal_;//!< Begin index of each dimension (e.x: for domain, it's always 0, for axis, it's zoom_begin, ...)
84    std::vector<int> nBeginGlobal_; //!< Begin index of each dimension (e.x: ibegin, jbegin, ...)
85    std::vector<int> nZoomBegin_; //!< Begin index of zoom of each dimension
86    std::vector<int> nZoomEnd_; //!< End index of zoom of each dimension
87
88    // Data_n_index of domain or axis (For now, axis uses its size as data_n_index
89    std::vector<int> dataNIndex_; //!< Data_n_index in case of domain
90    std::vector<int> dataDims_; //!< Data_dim, domain can have data_dim == 1 or 2
91    std::vector<int> dataBegin_; //!< Data begin (data_ibegin, data_jbegin, etc)
92    std::vector<CArray<int,1> > dataIndex_; //!< Data index
93
94    std::vector<CArray<bool,2> > domainMasks_; //!< Domain mask
95    std::vector<CArray<bool,1> > axisMasks_; //!< Axis mask
96
97    // Just suppose that grid mask has 3 dimension. Need change
98    CArray<bool,3> gridMask_; // TODO: more general grid mask
99
100    std::vector<std::vector<int> > localDomainIndex_;
101    std::vector<std::vector<int> > localAxisIndex_;
102    std::vector<int> indexMap_; //!< Mapping element index to dimension index
103
104    std::map<int, int> connectedClients_; //!< number of clients connected to a server
105    bool isConnectedServerComputed_; //!< Guard flag
106
107    // The real index of a domain has true value, the ghost one has false value
108    std::vector<std::vector<bool> > indexDomainData_;
109};
110
111} // namespace xios
112#endif // __XIOS_DISTRIBUTIONCLIENT_HPP__
Note: See TracBrowser for help on using the repository browser.