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