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

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

Implementing new hash algorithm and fixing bug related to zoom

+) Replace boost hash with hash algorithm of Jenkins
+) Domain, if an attribute is non-empty for one client, it should also be non-empty for others inspite of zoom
+) Replace the way to find the number of client connecting to a server to make sure every server receive a message

Test
+) On Curie
+) test_client: passed and results are same like before
+) test_complete: passed, results are partially the same, the different part comes from added working operation

File size: 5.7 KB
Line 
1/*!
2   \file distribution_client.hpp
3   \author Ha NGUYEN
4   \since 13 Jan 2015
5   \date 09 Mars 2015
6
7   \brief Index distribution on client side.
8 */
9#ifndef __XIOS_DISTRIBUTIONCLIENT_HPP__
10#define __XIOS_DISTRIBUTIONCLIENT_HPP__
11
12#include <distribution.hpp>
13#include "axis.hpp"
14#include "domain.hpp"
15#include "grid.hpp"
16
17namespace xios {
18
19class CGrid;
20class CDomain;
21class CAxis;
22
23/*!
24  \class CDistributionClient
25  This class bases on the knowledge of distribution on client side (decided by users)
26to calculate the global index of its local data.
27*/
28class CDistributionClient : public CDistribution
29{
30  public:
31    /** Default constructor */
32    CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex = 0);
33    CDistributionClient(int rank, CGrid* grid);
34
35    /** Default destructor */
36    virtual ~CDistributionClient();
37
38    virtual const CArray<int,1>& getLocalDataIndexOnClient() const;
39    virtual const CArray<int,1>& getLocalDataIndexSendToServer() const;
40    const CArray<size_t,1>& getGlobalDataIndexSendToServer() const;
41
42    std::vector<int> getNGlob() { return nGlob_; }
43    std::vector<int> getDataNIndex() { return dataNIndex_; }
44    bool isDataDistributed() { return isDataDistributed_; }
45
46  protected:
47    void createGlobalIndex();
48    void createGlobalIndexSendToServer();
49    void readDistributionInfo(CGrid* grid);
50    void readDistributionInfo(const std::vector<CDomain*>& domList,
51                              const std::vector<CAxis*>& axisList,
52                              const CArray<bool,1>& axisDomainOrder);
53    void readDomainIndex(const std::vector<CDomain*>& domList);
54    void readAxisIndex(const std::vector<CAxis*>& axisList);
55  private:
56    //! Create local index of a domain
57    void createLocalDomainDataIndex();
58
59    //! Create local index of an axis
60    void createLocalAxisDataIndex();
61
62    inline int getDomainIndex(const int& dataIIndex, const int& dataJIndex,
63                              const int& dataIBegin, const int& dataJBegin,
64                              const int& dataDim, const int& ni, int& j);
65    inline int getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni);
66
67    template<int N>
68    void readGridMaskInfo(const CArray<bool,N>& gridMask);
69
70  private:
71    //!< LocalData index on client
72    CArray<size_t,1>* globalDataSendToServer_;
73    CArray<int,1>* localDataIndex_;
74    CArray<int,1>* localDataIndexSendToServer_;
75
76  private:
77    /*! Domains and axis are considered elements.
78     * A grid composed of 1 domain and 1 axis has 2 elements */
79    int numElement_;
80    CArray<bool,1> axisDomainOrder_; //!< Order of axis and domain of a grid
81
82    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...)
83    std::vector<int> nGlob_; //!< Global size of each dimension (e.x: ni_glo, nj_glo, etc, ...)
84    std::vector<int> nBeginLocal_;//!< Begin index of each dimension (e.x: for domain, it's always 0, for axis, it's zoom_begin, ...)
85    std::vector<int> nBeginGlobal_; //!< Begin index of each dimension (e.x: ibegin, jbegin, ...)
86    std::vector<int> nZoomBegin_; //!< Begin index of zoom of each dimension
87    std::vector<int> nZoomEnd_; //!< End index of zoom of each dimension
88    std::vector<std::vector<CArray<int,2> > > nIndexDomain_; //!< Local index of each domain dimension (e.x: i_index, j_index)
89    std::vector<CArray<int,1> > nIndexAxis_;
90
91    // Data_n_index of domain or axis (For now, axis uses its size as data_n_index
92    std::vector<int> dataNIndex_; //!< Data_n_index in case of domain
93    std::vector<int> dataDims_; //!< Data_dim, domain can have data_dim == 1 or 2
94    std::vector<int> dataBegin_; //!< Data begin (data_ibegin, data_jbegin, etc)
95    std::vector<CArray<int,1> > dataIndex_; //!< Data index
96
97    std::vector<CArray<bool,2> > domainMasks_; //!< Domain mask
98    std::vector<CArray<bool,1> > axisMasks_; //!< Axis 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    // The correct index of a domain has true value, the ghost one has false value
105    std::vector<std::vector<bool> > indexDomainData_;
106    std::vector<std::vector<bool> > indexAxisData_;
107
108    //!< (Only for grid with one axis or scalar)Flag to determine whether data is distributed or not
109    bool isDataDistributed_;
110    int axisNum_;
111    int domainNum_;
112
113  private:
114    // Just suppose that grid mask has 3 dimension. Need change
115    CArray<bool,1> gridMask_; //!< Mask of grid
116
117  private:
118    CDistributionClient(const CDistributionClient& distClient); //! Not implement
119};
120
121/*!
122  A grid can have multiple dimension, so can its mask in the form of multi-dimension array.
123It's not a good idea to store all multi-dimension arrays corresponding to each mask.
124One of the ways is to convert this array into 1-dimension one and every process is taken place on it.
125  \param [in] multi-dimension array grid mask
126*/
127template<int N>
128void CDistributionClient::readGridMaskInfo(const CArray<bool,N>& gridMask)
129{
130  int dim = gridMask.dimensions();
131  std::vector<int> dimensionSizes(dim);
132  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i);
133
134  std::vector<int> idxLoop(dim,0);
135  int ssize = gridMask.numElements(), idx = 0;
136  gridMask_.resize(ssize);
137  while (idx < ssize)
138  {
139    for (int i = 0; i < dim-1; ++i)
140    {
141      if (idxLoop[i] == dimensionSizes[i])
142      {
143        idxLoop[i] = 0;
144        ++idxLoop[i+1];
145      }
146    }
147
148    int maskIndex = idxLoop[0];
149    int mulDim = 1;
150    for (int k = 1; k < dim; ++k)
151    {
152      mulDim *= dimensionSizes[k-1];
153      maskIndex += idxLoop[k]*mulDim;
154    }
155    gridMask_(maskIndex) = *(gridMask.dataFirst()+maskIndex);
156
157    ++idxLoop[0];
158    ++idx;
159  }
160}
161
162
163} // namespace xios
164#endif // __XIOS_DISTRIBUTIONCLIENT_HPP__
Note: See TracBrowser for help on using the repository browser.