source: XIOS/trunk/src/distribution_client.hpp @ 930

Last change on this file since 930 was 930, checked in by mhnguyen, 4 years ago

Improving the performance of on server side

+) Replace searching algorithm for global-local index with a better one

Test
+) On Curie
+) Work correct

File size: 5.9 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;
22class CScalar;
23
24/*!
25  \class CDistributionClient
26  This class bases on the knowledge of distribution on client side (decided by users)
27to calculate the global index of its local data.
28*/
29class CDistributionClient : public CDistribution
30{
31public:
32  typedef CDistribution::GlobalLocalMap GlobalLocalDataMap;
33
34  public:
35    /** Default constructor */
36    CDistributionClient(int rank, int dims, const CArray<size_t,1>& globalIndex = CArray<size_t,1>());
37    CDistributionClient(int rank, CGrid* grid);
38
39    void createGlobalIndexSendToServer();
40
41    /** Default destructor */
42    virtual ~CDistributionClient();
43
44    virtual const std::vector<int>& getLocalDataIndexOnClient();
45    GlobalLocalDataMap& getGlobalLocalDataSendToServer();
46    const std::vector<int>& getLocalMaskIndexOnClient();
47
48    std::vector<int> getNGlob() { return nGlob_; }
49    std::vector<int> getDataNIndex() { return dataNIndex_; }
50
51    bool isDataDistributed() { return isDataDistributed_; }
52
53    static 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    static int getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni);
57
58  protected:
59    void createGlobalIndex();
60    void readDistributionInfo(CGrid* grid);
61    void readDistributionInfo(const std::vector<CDomain*>& domList,
62                              const std::vector<CAxis*>& axisList,
63                              const std::vector<CScalar*>& scalarList,
64                              const CArray<int,1>& axisDomainOrder);
65  private:
66    //! Create local index of a domain
67    void createLocalDomainDataIndex();
68
69    //! Create local index of an axis
70    void createLocalAxisDataIndex();
71
72    //! Create local index of a scalar
73    void createLocalScalarDataIndex();
74
75    template<int N>
76    void readGridMaskInfo(const CArray<bool,N>& gridMask);
77
78  private:
79    //!< LocalData index on client
80    GlobalLocalDataMap globalLocalDataSendToServerMap_;
81    std::vector<int> localDataIndex_;
82    std::vector<int> localMaskIndex_;
83
84  private:
85    /*! Domains and axis are considered elements.
86     * A grid composed of 1 domain and 1 axis has 2 elements */
87    int numElement_;
88    CArray<int,1> axisDomainOrder_; //!< Order of axis and domain of a grid
89
90    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...)
91    std::vector<int> nGlob_; //!< Global size of each dimension (e.x: ni_glo, nj_glo, etc, ...)
92    std::vector<int> nBeginLocal_;//!< Begin index of each dimension (e.x: for domain, it's always 0, for axis, it's zoom_begin, ...)
93    std::vector<int> nBeginGlobal_; //!< Begin index of each dimension (e.x: ibegin, jbegin, ...)
94    std::vector<int> nZoomBegin_; //!< Begin index of zoom of each dimension
95    std::vector<int> nZoomEnd_; //!< End index of zoom of each dimension
96
97    // Data_n_index of domain or axis (For now, axis uses its size as data_n_index
98    std::vector<int> dataNIndex_; //!< Data_n_index in case of domain
99    std::vector<int> dataDims_; //!< Data_dim, domain can have data_dim == 1 or 2
100    std::vector<int> dataBegin_; //!< Data begin (data_ibegin, data_jbegin, etc)
101    std::vector<CArray<int,1> > dataIndex_; //!< Data index
102    std::vector<CArray<int,1> > infoIndex_; //!< i_index, j_index
103
104    std::vector<CArray<bool,1> > domainMasks_; //!< Domain mask
105    std::vector<CArray<bool,1> > axisMasks_; //!< Axis mask
106
107    std::vector<int> indexMap_; //!< Mapping element index to dimension index
108    std::vector<CArray<int,1> > elementLocalIndex_;  //!< Local index of each element
109    std::vector<CArray<size_t,1> > elementGlobalIndex_; //!< Global index of each element
110    std::vector<CArray<bool,1> > elementIndexData_; //!< // The correct index of a domain has true value, the ghost one has false value
111    std::vector<CArray<bool,1> > elementZoomMask_; //!< Only zoomed region are true
112    std::vector<size_t> elementNLocal_;
113    std::vector<size_t> elementNGlobal_;
114
115    //!< (Only for grid with one axis or scalar)Flag to determine whether data is distributed or not
116    bool isDataDistributed_;
117    int axisNum_;
118    int domainNum_;
119    bool isComputed_;
120
121  private:
122    // Just suppose that grid mask has 3 dimension. Need change
123    CArray<bool,1> gridMask_; //!< Mask of grid
124
125  private:
126    CDistributionClient(const CDistributionClient& distClient); //! Not implement
127};
128
129/*!
130  A grid can have multiple dimension, so can its mask in the form of multi-dimension array.
131It's not a good idea to store all multi-dimension arrays corresponding to each mask.
132One of the ways is to convert this array into 1-dimension one and every process is taken place on it.
133  \param [in] multi-dimension array grid mask
134*/
135template<int N>
136void CDistributionClient::readGridMaskInfo(const CArray<bool,N>& gridMask)
137{
138  int dim = gridMask.dimensions();
139  std::vector<int> dimensionSizes(dim);
140  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i);
141
142  std::vector<int> idxLoop(dim,0);
143  int ssize = gridMask.numElements(), idx = 0;
144  gridMask_.resize(ssize);
145  while (idx < ssize)
146  {
147    for (int i = 0; i < dim-1; ++i)
148    {
149      if (idxLoop[i] == dimensionSizes[i])
150      {
151        idxLoop[i] = 0;
152        ++idxLoop[i+1];
153      }
154    }
155
156    int maskIndex = idxLoop[0];
157    int mulDim = 1;
158    for (int k = 1; k < dim; ++k)
159    {
160      mulDim *= dimensionSizes[k-1];
161      maskIndex += idxLoop[k]*mulDim;
162    }
163    gridMask_(maskIndex) = *(gridMask.dataFirst()+maskIndex);
164
165    ++idxLoop[0];
166    ++idx;
167  }
168}
169
170} // namespace xios
171#endif // __XIOS_DISTRIBUTIONCLIENT_HPP__
Note: See TracBrowser for help on using the repository browser.