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