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