[553] | 1 | /*! |
---|
| 2 | \file distribution_client.cpp |
---|
| 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 | #include "distribution_client.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
| 12 | |
---|
| 13 | CDistributionClient::CDistributionClient(int rank, CGrid* grid) |
---|
[653] | 14 | : CDistribution(rank, 0) |
---|
| 15 | , axisDomainOrder_() |
---|
| 16 | , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_() |
---|
| 17 | , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() |
---|
[861] | 18 | , gridMask_(), indexMap_() |
---|
[843] | 19 | , isDataDistributed_(true), axisNum_(0), domainNum_(0) |
---|
[833] | 20 | , localDataIndex_(), localMaskIndex_() |
---|
[831] | 21 | , globalLocalDataSendToServerMap_() |
---|
[834] | 22 | , infoIndex_(), isComputed_(false) |
---|
[861] | 23 | , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_() |
---|
| 24 | , elementZoomMask_(), elementNLocal_(), elementNGlobal_() |
---|
[551] | 25 | { |
---|
| 26 | readDistributionInfo(grid); |
---|
| 27 | createGlobalIndex(); |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | CDistributionClient::~CDistributionClient() |
---|
[653] | 31 | { /* Nothing to do */ } |
---|
[551] | 32 | |
---|
| 33 | /*! |
---|
| 34 | Read information of a grid to generate distribution. |
---|
| 35 | Every grid is composed of several axis or/and domain(s). Their information are processed |
---|
| 36 | stored and used to calculate index distribution between client and server |
---|
| 37 | \param [in] grid Grid to read |
---|
| 38 | */ |
---|
| 39 | void CDistributionClient::readDistributionInfo(CGrid* grid) |
---|
| 40 | { |
---|
| 41 | std::vector<CDomain*> domList = grid->getDomains(); |
---|
| 42 | std::vector<CAxis*> axisList = grid->getAxis(); |
---|
[887] | 43 | std::vector<CScalar*> scalarList = grid->getScalars(); |
---|
| 44 | CArray<int,1> axisDomainOrder = grid->axis_domain_order; |
---|
[551] | 45 | |
---|
[887] | 46 | readDistributionInfo(domList, axisList, scalarList, axisDomainOrder); |
---|
[551] | 47 | |
---|
| 48 | // Then check mask of grid |
---|
[653] | 49 | int gridDim = domList.size() * 2 + axisList.size(); |
---|
[551] | 50 | grid->checkMask(); |
---|
[567] | 51 | switch (gridDim) { |
---|
[888] | 52 | case 0: |
---|
| 53 | gridMask_.resize(1); |
---|
| 54 | gridMask_(0) = true; |
---|
| 55 | break; |
---|
[567] | 56 | case 1: |
---|
[817] | 57 | readGridMaskInfo(grid->mask_1d); |
---|
[567] | 58 | break; |
---|
| 59 | case 2: |
---|
[817] | 60 | readGridMaskInfo(grid->mask_2d); |
---|
[567] | 61 | break; |
---|
| 62 | case 3: |
---|
[817] | 63 | readGridMaskInfo(grid->mask_3d); |
---|
[567] | 64 | break; |
---|
[932] | 65 | case 4: |
---|
| 66 | readGridMaskInfo(grid->mask_4d); |
---|
| 67 | break; |
---|
| 68 | case 5: |
---|
| 69 | readGridMaskInfo(grid->mask_5d); |
---|
| 70 | break; |
---|
| 71 | case 6: |
---|
| 72 | readGridMaskInfo(grid->mask_6d); |
---|
| 73 | break; |
---|
| 74 | case 7: |
---|
| 75 | readGridMaskInfo(grid->mask_7d); |
---|
| 76 | break; |
---|
[567] | 77 | default: |
---|
| 78 | break; |
---|
| 79 | } |
---|
[551] | 80 | } |
---|
| 81 | |
---|
| 82 | /*! |
---|
| 83 | Read information from domain(s) and axis to generate distribution. |
---|
| 84 | All information related to domain, e.g ibegin, jbegin, ni, nj, ni_glo, nj_glo |
---|
| 85 | as well as related to axis, e.g dataNIndex, dataIndex will be stored to compute |
---|
| 86 | the distribution between clients and servers. Till now, every data structure of domain has been kept |
---|
| 87 | like before, e.g: data_n_index to make sure a compability, however, it should be changed? |
---|
| 88 | \param [in] domList List of domains of grid |
---|
| 89 | \param [in] axisList List of axis of grid |
---|
[887] | 90 | \param [in] scalarList List of scalar of grid |
---|
| 91 | \param [in] axisDomainOrder order of axis and domain inside a grid. 2 if domain, 1 if axis and zero if scalar |
---|
[567] | 92 | // \param [in] gridMask Mask of grid, for now, keep it 3 dimension, but it needs changing |
---|
[551] | 93 | */ |
---|
| 94 | void CDistributionClient::readDistributionInfo(const std::vector<CDomain*>& domList, |
---|
| 95 | const std::vector<CAxis*>& axisList, |
---|
[887] | 96 | const std::vector<CScalar*>& scalarList, |
---|
| 97 | const CArray<int,1>& axisDomainOrder) |
---|
[551] | 98 | { |
---|
[567] | 99 | domainNum_ = domList.size(); |
---|
| 100 | axisNum_ = axisList.size(); |
---|
[551] | 101 | numElement_ = axisDomainOrder.numElements(); // Number of element, e.x: Axis, Domain |
---|
| 102 | |
---|
| 103 | axisDomainOrder_.resize(numElement_); |
---|
| 104 | axisDomainOrder_ = axisDomainOrder; |
---|
| 105 | |
---|
| 106 | // Each domain or axis has its mask, of course |
---|
[567] | 107 | domainMasks_.resize(domainNum_); |
---|
| 108 | for (int i = 0; i < domainNum_;++i) |
---|
[551] | 109 | { |
---|
[664] | 110 | domainMasks_[i].resize(domList[i]->mask_1d.numElements()); |
---|
| 111 | domainMasks_[i] = domList[i]->mask_1d; |
---|
[551] | 112 | } |
---|
| 113 | |
---|
[567] | 114 | axisMasks_.resize(axisNum_); |
---|
| 115 | for (int i = 0; i < axisNum_; ++i) |
---|
[551] | 116 | { |
---|
| 117 | axisMasks_[i].resize(axisList[i]->mask.numElements()); |
---|
| 118 | axisMasks_[i] = axisList[i]->mask; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | // Because domain and axis can be in any order (axis1, domain1, axis2, axis3, ) |
---|
| 122 | // their position should be specified. In axisDomainOrder, domain == true, axis == false |
---|
| 123 | int idx = 0; |
---|
| 124 | indexMap_.resize(numElement_); |
---|
| 125 | this->dims_ = numElement_; |
---|
| 126 | for (int i = 0; i < numElement_; ++i) |
---|
| 127 | { |
---|
| 128 | indexMap_[i] = idx; |
---|
[887] | 129 | if (2 == axisDomainOrder(i)) |
---|
[551] | 130 | { |
---|
| 131 | ++(this->dims_); |
---|
| 132 | idx += 2; |
---|
| 133 | } |
---|
[567] | 134 | else ++idx; |
---|
[551] | 135 | } |
---|
| 136 | |
---|
| 137 | // Size of each dimension (local and global) |
---|
| 138 | nLocal_.resize(this->dims_); |
---|
| 139 | nGlob_.resize(this->dims_); |
---|
| 140 | nBeginLocal_.resize(this->dims_,0); |
---|
| 141 | nBeginGlobal_.resize(this->dims_,0); |
---|
| 142 | nZoomBegin_.resize(this->dims_); |
---|
| 143 | nZoomEnd_.resize(this->dims_); |
---|
| 144 | |
---|
| 145 | // Data_n_index of domain or axis (For now, axis uses its size as data_n_index |
---|
| 146 | dataNIndex_.resize(numElement_); |
---|
| 147 | dataDims_.resize(numElement_); |
---|
| 148 | dataBegin_.resize(this->dims_); |
---|
| 149 | |
---|
| 150 | // Data_*_index of each dimension |
---|
| 151 | dataIndex_.resize(this->dims_); |
---|
[818] | 152 | infoIndex_.resize(this->dims_); |
---|
[551] | 153 | |
---|
[1158] | 154 | // A trick to determine position of each domain in domainList |
---|
| 155 | int domIndex = 0, axisIndex = 0, scalarIndex = 0; |
---|
| 156 | idx = 0; |
---|
| 157 | |
---|
[861] | 158 | elementLocalIndex_.resize(numElement_); |
---|
| 159 | elementGlobalIndex_.resize(numElement_); |
---|
| 160 | elementIndexData_.resize(numElement_); |
---|
| 161 | elementZoomMask_.resize(numElement_); |
---|
| 162 | elementNLocal_.resize(numElement_); |
---|
| 163 | elementNGlobal_.resize(numElement_); |
---|
| 164 | elementNLocal_[0] = 1; |
---|
| 165 | elementNGlobal_[0] = 1; |
---|
| 166 | size_t localSize = 1, globalSize = 1; |
---|
| 167 | |
---|
[1158] | 168 | isDataDistributed_ = false; |
---|
[551] | 169 | // Update all the vectors above |
---|
[861] | 170 | for (idx = 0; idx < numElement_; ++idx) |
---|
[551] | 171 | { |
---|
[887] | 172 | int eleDim = axisDomainOrder(idx); |
---|
[861] | 173 | elementNLocal_[idx] = localSize; |
---|
| 174 | elementNGlobal_[idx] = globalSize; |
---|
[551] | 175 | |
---|
| 176 | // If this is a domain |
---|
[887] | 177 | if (2 == eleDim) |
---|
[551] | 178 | { |
---|
| 179 | // On the j axis |
---|
| 180 | nLocal_.at(indexMap_[idx]+1) = domList[domIndex]->nj.getValue(); |
---|
| 181 | nGlob_.at(indexMap_[idx]+1) = domList[domIndex]->nj_glo.getValue(); |
---|
| 182 | nBeginLocal_.at(indexMap_[idx]+1) = 0; |
---|
| 183 | nBeginGlobal_.at(indexMap_[idx]+1) = domList[domIndex]->jbegin; |
---|
[1129] | 184 | nZoomBegin_.at((indexMap_[idx]+1)) = 0; //domList[domIndex]->global_zoom_jbegin; |
---|
| 185 | nZoomEnd_.at((indexMap_[idx]+1)) = domList[domIndex]->nj_glo.getValue()- 1; //domList[domIndex]->global_zoom_jbegin + domList[domIndex]->global_zoom_nj-1; |
---|
[551] | 186 | |
---|
[890] | 187 | dataBegin_.at(indexMap_[idx]+1) = domList[domIndex]->data_jbegin.getValue(); |
---|
[887] | 188 | dataIndex_.at(indexMap_[idx]+1).reference(domList[domIndex]->data_j_index); |
---|
| 189 | infoIndex_.at(indexMap_[idx]+1).reference(domList[domIndex]->j_index); |
---|
[551] | 190 | |
---|
| 191 | // On the i axis |
---|
| 192 | nLocal_.at(indexMap_[idx]) = domList[domIndex]->ni.getValue(); |
---|
| 193 | nGlob_.at(indexMap_[idx]) = domList[domIndex]->ni_glo.getValue(); |
---|
| 194 | nBeginLocal_.at(indexMap_[idx]) = 0; |
---|
| 195 | nBeginGlobal_.at(indexMap_[idx]) = domList[domIndex]->ibegin; |
---|
[1129] | 196 | nZoomBegin_.at((indexMap_[idx])) = 0; // domList[domIndex]->global_zoom_ibegin; |
---|
| 197 | nZoomEnd_.at((indexMap_[idx])) = domList[domIndex]->ni_glo.getValue() -1; //domList[domIndex]->global_zoom_ibegin + domList[domIndex]->global_zoom_ni-1; |
---|
[551] | 198 | |
---|
| 199 | dataBegin_.at(indexMap_[idx]) = domList[domIndex]->data_ibegin.getValue(); |
---|
[887] | 200 | dataIndex_.at(indexMap_[idx]).reference(domList[domIndex]->data_i_index); |
---|
| 201 | infoIndex_.at(indexMap_[idx]).reference(domList[domIndex]->i_index); |
---|
[551] | 202 | |
---|
[660] | 203 | dataNIndex_.at(idx) = domList[domIndex]->data_i_index.numElements(); |
---|
[551] | 204 | dataDims_.at(idx) = domList[domIndex]->data_dim.getValue(); |
---|
[594] | 205 | |
---|
| 206 | isDataDistributed_ |= domList[domIndex]->isDistributed(); |
---|
| 207 | |
---|
[861] | 208 | localSize *= nLocal_.at(indexMap_[idx]+1)* nLocal_.at(indexMap_[idx]); |
---|
| 209 | globalSize *= nGlob_.at(indexMap_[idx]+1)* nGlob_.at(indexMap_[idx]); |
---|
[551] | 210 | ++domIndex; |
---|
| 211 | } |
---|
[887] | 212 | else if (1 == eleDim)// So it's an axis |
---|
[551] | 213 | { |
---|
[666] | 214 | nLocal_.at(indexMap_[idx]) = axisList[axisIndex]->n.getValue(); |
---|
| 215 | nGlob_.at(indexMap_[idx]) = axisList[axisIndex]->n_glo.getValue(); |
---|
[553] | 216 | nBeginLocal_.at(indexMap_[idx]) = 0; |
---|
[666] | 217 | nBeginGlobal_.at(indexMap_[idx]) = axisList[axisIndex]->begin.getValue(); |
---|
[1129] | 218 | nZoomBegin_.at((indexMap_[idx])) = 0; //axisList[axisIndex]->global_zoom_begin; |
---|
| 219 | nZoomEnd_.at((indexMap_[idx])) = axisList[axisIndex]->n_glo.getValue() - 1; //axisList[axisIndex]->global_zoom_begin + axisList[axisIndex]->global_zoom_n-1; |
---|
[551] | 220 | |
---|
| 221 | dataBegin_.at(indexMap_[idx]) = axisList[axisIndex]->data_begin.getValue(); |
---|
[887] | 222 | dataIndex_.at(indexMap_[idx]).reference(axisList[axisIndex]->data_index); |
---|
| 223 | infoIndex_.at(indexMap_[idx]).reference(axisList[axisIndex]->index); |
---|
[551] | 224 | dataNIndex_.at(idx) = axisList[axisIndex]->data_index.numElements(); |
---|
| 225 | dataDims_.at(idx) = 1; |
---|
[594] | 226 | |
---|
| 227 | isDataDistributed_ |= axisList[axisIndex]->isDistributed(); |
---|
| 228 | |
---|
[861] | 229 | localSize *= nLocal_.at(indexMap_[idx]); |
---|
| 230 | globalSize *= nGlob_.at(indexMap_[idx]); |
---|
| 231 | |
---|
[551] | 232 | ++axisIndex; |
---|
| 233 | } |
---|
[887] | 234 | else // scalar |
---|
| 235 | { |
---|
| 236 | nLocal_.at(indexMap_[idx]) = 1; |
---|
| 237 | nGlob_.at(indexMap_[idx]) = 1; |
---|
| 238 | nBeginLocal_.at(indexMap_[idx]) = 0; |
---|
| 239 | nBeginGlobal_.at(indexMap_[idx]) = 1; |
---|
| 240 | nZoomBegin_.at((indexMap_[idx])) = 0; |
---|
| 241 | nZoomEnd_.at((indexMap_[idx])) = 0; |
---|
| 242 | |
---|
| 243 | dataBegin_.at(indexMap_[idx]) = 0; |
---|
| 244 | dataIndex_.at(indexMap_[idx]).resize(1); dataIndex_.at(indexMap_[idx])(0) = 0; |
---|
| 245 | infoIndex_.at(indexMap_[idx]).resize(1); infoIndex_.at(indexMap_[idx])(0) = 0; |
---|
| 246 | dataNIndex_.at(idx) = 1; |
---|
| 247 | dataDims_.at(idx) = 1; |
---|
| 248 | |
---|
| 249 | isDataDistributed_ |= false; |
---|
| 250 | |
---|
| 251 | localSize *= nLocal_.at(indexMap_[idx]); |
---|
| 252 | globalSize *= nGlob_.at(indexMap_[idx]); |
---|
| 253 | |
---|
| 254 | ++scalarIndex; |
---|
| 255 | } |
---|
[551] | 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | /*! |
---|
| 260 | Create local index of domain(s). |
---|
| 261 | A domain can have data index which even contains the "ghost" points. Very often, these |
---|
| 262 | data surround the true data. In order to send correct data to server, |
---|
| 263 | a client need to know index of the true data. |
---|
| 264 | */ |
---|
| 265 | void CDistributionClient::createLocalDomainDataIndex() |
---|
| 266 | { |
---|
| 267 | int idxDomain = 0; |
---|
| 268 | for (int i = 0; i < axisDomainOrder_.numElements(); ++i) |
---|
| 269 | { |
---|
[887] | 270 | if (2 == axisDomainOrder_(i)) |
---|
[551] | 271 | { |
---|
[861] | 272 | elementIndexData_[i].resize(dataNIndex_[i]); |
---|
| 273 | elementIndexData_[i] = false; |
---|
| 274 | int iIdx, jIdx = 0, count = 0, localIndex; |
---|
[551] | 275 | for (int j = 0; j < dataNIndex_[i]; ++j) |
---|
| 276 | { |
---|
[887] | 277 | iIdx = getDomainIndex((dataIndex_[indexMap_[i]])(j), (dataIndex_[indexMap_[i]+1])(j), |
---|
[551] | 278 | dataBegin_[indexMap_[i]], dataBegin_[indexMap_[i]+1], |
---|
| 279 | dataDims_[i], nLocal_[indexMap_[i]], jIdx); |
---|
| 280 | |
---|
| 281 | if ((iIdx >= nBeginLocal_[indexMap_[i]]) && (iIdx < nLocal_[indexMap_[i]]) && |
---|
| 282 | (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1]) && |
---|
[664] | 283 | (domainMasks_[idxDomain](iIdx + jIdx*nLocal_[indexMap_[i]]))) |
---|
[551] | 284 | { |
---|
[861] | 285 | ++count; |
---|
| 286 | elementIndexData_[i](j) = true; |
---|
[551] | 287 | } |
---|
| 288 | } |
---|
[861] | 289 | |
---|
| 290 | elementLocalIndex_[i].resize(count); |
---|
| 291 | elementGlobalIndex_[i].resize(count); |
---|
| 292 | elementZoomMask_[i].resize(count); |
---|
| 293 | elementZoomMask_[i] = false; |
---|
| 294 | count = 0; |
---|
| 295 | CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; |
---|
| 296 | CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; |
---|
| 297 | CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; |
---|
| 298 | CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; |
---|
| 299 | for (int j = 0; j < dataNIndex_[i]; ++j) |
---|
| 300 | { |
---|
| 301 | if (tmpIndexElementData(j)) |
---|
| 302 | { |
---|
[887] | 303 | iIdx = getDomainIndex((dataIndex_[indexMap_[i]])(j), (dataIndex_[indexMap_[i]+1])(j), |
---|
[861] | 304 | dataBegin_[indexMap_[i]], dataBegin_[indexMap_[i]+1], |
---|
| 305 | dataDims_[i], nLocal_[indexMap_[i]], jIdx); |
---|
| 306 | localIndex = tmpLocalElementIndex(count) = iIdx + jIdx * nLocal_[indexMap_[i]]; |
---|
[887] | 307 | tmpGlobalElementIndex(count) = (infoIndex_[indexMap_[i]])(localIndex) + ((infoIndex_[indexMap_[i]+1])(localIndex))*nGlob_[indexMap_[i]]; |
---|
| 308 | if ((((infoIndex_[indexMap_[i]])(localIndex)) <= nZoomEnd_[indexMap_[i]]) |
---|
| 309 | && (nZoomBegin_[indexMap_[i]] <= ((infoIndex_[indexMap_[i]])(localIndex))) |
---|
| 310 | && (((infoIndex_[indexMap_[i]+1])(localIndex)) <= nZoomEnd_[indexMap_[i]+1]) |
---|
| 311 | && (nZoomBegin_[indexMap_[i]+1] <= ((infoIndex_[indexMap_[i]+1])(localIndex)))) |
---|
[861] | 312 | { |
---|
| 313 | tmpZoomMaskElement(count) = true; |
---|
| 314 | } |
---|
| 315 | ++count; |
---|
| 316 | } |
---|
| 317 | } |
---|
[551] | 318 | ++idxDomain; |
---|
| 319 | } |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | |
---|
| 323 | /*! |
---|
| 324 | Create local index of axis. |
---|
| 325 | */ |
---|
| 326 | void CDistributionClient::createLocalAxisDataIndex() |
---|
| 327 | { |
---|
| 328 | int idxAxis = 0; |
---|
| 329 | for (int i = 0; i < axisDomainOrder_.numElements(); ++i) |
---|
| 330 | { |
---|
[887] | 331 | if (1 == axisDomainOrder_(i)) |
---|
[551] | 332 | { |
---|
[861] | 333 | elementIndexData_[i].resize(dataNIndex_[i]); |
---|
| 334 | elementIndexData_[i] = false; |
---|
| 335 | int iIdx = 0, count = 0, localIndex = 0; |
---|
[551] | 336 | for (int j = 0; j < dataNIndex_[i]; ++j) |
---|
| 337 | { |
---|
[887] | 338 | iIdx = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); |
---|
[551] | 339 | if ((iIdx >= nBeginLocal_[indexMap_[i]]) && |
---|
| 340 | (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx))) |
---|
| 341 | { |
---|
[861] | 342 | ++count; |
---|
| 343 | elementIndexData_[i](j) = true; |
---|
[551] | 344 | } |
---|
| 345 | } |
---|
| 346 | |
---|
[861] | 347 | elementLocalIndex_[i].resize(count); |
---|
| 348 | elementGlobalIndex_[i].resize(count); |
---|
| 349 | elementZoomMask_[i].resize(count); |
---|
| 350 | elementZoomMask_[i] = false; |
---|
| 351 | count = 0; |
---|
| 352 | CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; |
---|
| 353 | CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; |
---|
| 354 | CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; |
---|
| 355 | CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; |
---|
| 356 | for (int j = 0; j < dataNIndex_[i]; ++j) |
---|
[584] | 357 | { |
---|
[861] | 358 | if (tmpIndexElementData(j)) |
---|
[818] | 359 | { |
---|
[887] | 360 | iIdx = tmpLocalElementIndex(count) = getAxisIndex((dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); |
---|
| 361 | tmpGlobalElementIndex(count) = (infoIndex_[indexMap_[i]])(iIdx); |
---|
| 362 | if ((((infoIndex_[indexMap_[i]])(iIdx)) <= nZoomEnd_[indexMap_[i]]) |
---|
| 363 | && (nZoomBegin_[indexMap_[i]] <= ((infoIndex_[indexMap_[i]])(iIdx)))) |
---|
[818] | 364 | { |
---|
[861] | 365 | tmpZoomMaskElement(count) = true; |
---|
[818] | 366 | } |
---|
[861] | 367 | ++count; |
---|
[818] | 368 | } |
---|
[584] | 369 | } |
---|
[861] | 370 | ++idxAxis; |
---|
[584] | 371 | } |
---|
| 372 | } |
---|
| 373 | } |
---|
| 374 | |
---|
[551] | 375 | /*! |
---|
[887] | 376 | Create local index of scalar. |
---|
| 377 | */ |
---|
| 378 | void CDistributionClient::createLocalScalarDataIndex() |
---|
| 379 | { |
---|
| 380 | int idxAxis = 0; |
---|
| 381 | for (int i = 0; i < axisDomainOrder_.numElements(); ++i) |
---|
| 382 | { |
---|
| 383 | if (0 == axisDomainOrder_(i)) |
---|
| 384 | { |
---|
| 385 | elementIndexData_[i].resize(dataNIndex_[i]); |
---|
| 386 | elementIndexData_[i] = true; |
---|
| 387 | int count = 1; |
---|
| 388 | |
---|
| 389 | elementLocalIndex_[i].resize(count); |
---|
| 390 | elementLocalIndex_[i] = 0; |
---|
| 391 | elementGlobalIndex_[i].resize(count); |
---|
| 392 | elementGlobalIndex_[i] = 0; |
---|
| 393 | elementZoomMask_[i].resize(count); |
---|
| 394 | elementZoomMask_[i] = true; |
---|
| 395 | } |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | /*! |
---|
[551] | 400 | Create global index on client |
---|
| 401 | In order to do the mapping between client-server, each client creates its own |
---|
| 402 | global index of sending data. This global index is then used to calculate to which server |
---|
| 403 | the client needs to send it data as well as which part of data belongs to the server. |
---|
| 404 | So as to make clients and server coherent in order of index, global index is calculated by |
---|
| 405 | take into account of C-convention, the rightmost dimension varies faster. |
---|
| 406 | */ |
---|
[584] | 407 | void CDistributionClient::createGlobalIndexSendToServer() |
---|
[551] | 408 | { |
---|
[834] | 409 | if (isComputed_) return; |
---|
| 410 | isComputed_ = true; |
---|
[551] | 411 | createLocalDomainDataIndex(); |
---|
| 412 | createLocalAxisDataIndex(); |
---|
[888] | 413 | createLocalScalarDataIndex(); |
---|
[551] | 414 | |
---|
| 415 | int idxDomain = 0, idxAxis = 0; |
---|
| 416 | std::vector<int> eachElementSize(numElement_); |
---|
| 417 | |
---|
| 418 | // Precompute size of the loop |
---|
| 419 | for (int i = 0; i < numElement_; ++i) |
---|
| 420 | { |
---|
[861] | 421 | eachElementSize[i] = elementLocalIndex_[i].numElements(); |
---|
[551] | 422 | } |
---|
| 423 | |
---|
| 424 | // Compute size of the global index on client |
---|
[623] | 425 | std::vector<StdSize> idxLoop(numElement_,0); |
---|
[861] | 426 | std::vector<StdSize> currentIndex(numElement_,0); |
---|
| 427 | std::vector<StdSize> currentGlobalIndex(numElement_,0); |
---|
[551] | 428 | int innerLoopSize = eachElementSize[0]; |
---|
| 429 | size_t idx = 0, indexLocalDataOnClientCount = 0, indexSend2ServerCount = 0; |
---|
| 430 | size_t ssize = 1; |
---|
| 431 | for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; |
---|
| 432 | while (idx < ssize) |
---|
| 433 | { |
---|
| 434 | for (int i = 0; i < numElement_-1; ++i) |
---|
| 435 | { |
---|
| 436 | if (idxLoop[i] == eachElementSize[i]) |
---|
| 437 | { |
---|
| 438 | idxLoop[i] = 0; |
---|
| 439 | ++idxLoop[i+1]; |
---|
| 440 | } |
---|
| 441 | } |
---|
| 442 | |
---|
[553] | 443 | // Find out outer index |
---|
[567] | 444 | // Depending the inner-most element is axis or domain, |
---|
| 445 | // The outer loop index begins correspondingly at one (1) or zero (0) |
---|
[551] | 446 | for (int i = 1; i < numElement_; ++i) |
---|
| 447 | { |
---|
[861] | 448 | currentIndex[i] = elementLocalIndex_[i](idxLoop[i]); |
---|
[551] | 449 | } |
---|
| 450 | |
---|
| 451 | // Inner most index |
---|
| 452 | for (int i = 0; i < innerLoopSize; ++i) |
---|
| 453 | { |
---|
[861] | 454 | int gridMaskIndex = 0; |
---|
[864] | 455 | currentIndex[0] = elementLocalIndex_[0](i); |
---|
[861] | 456 | for (int k = 0; k < this->numElement_; ++k) |
---|
[551] | 457 | { |
---|
[861] | 458 | gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; |
---|
[551] | 459 | } |
---|
| 460 | |
---|
[818] | 461 | if (gridMask_(gridMaskIndex)) |
---|
[567] | 462 | { |
---|
[551] | 463 | ++indexLocalDataOnClientCount; |
---|
| 464 | bool isIndexOnServer = true; |
---|
[818] | 465 | |
---|
| 466 | for (int idxElement = 0; idxElement < this->numElement_; ++idxElement) |
---|
| 467 | { |
---|
[861] | 468 | isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](idxLoop[idxElement]); |
---|
[818] | 469 | } |
---|
[551] | 470 | if (isIndexOnServer) ++indexSend2ServerCount; |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | idxLoop[0] += innerLoopSize; |
---|
| 474 | idx += innerLoopSize; |
---|
| 475 | } |
---|
| 476 | |
---|
[553] | 477 | // Now allocate these arrays |
---|
[653] | 478 | localDataIndex_.resize(indexLocalDataOnClientCount); |
---|
| 479 | localMaskIndex_.resize(indexSend2ServerCount); |
---|
[1250] | 480 | localMaskedDataIndex_.resize(indexSend2ServerCount); |
---|
[1129] | 481 | globalDataIndex_.rehash(std::ceil(indexLocalDataOnClientCount/globalDataIndex_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); |
---|
[843] | 482 | globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); |
---|
[551] | 483 | |
---|
[553] | 484 | // We need to loop with data index |
---|
[551] | 485 | idxLoop.assign(numElement_,0); |
---|
| 486 | idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; |
---|
[567] | 487 | ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; |
---|
| 488 | innerLoopSize = dataNIndex_[0]; |
---|
| 489 | int countLocalData = 0; |
---|
[874] | 490 | std::vector<int> correctIndexOfElement(numElement_,0); |
---|
[623] | 491 | bool isOuterIndexCorrect = true; |
---|
[551] | 492 | while (idx < ssize) |
---|
| 493 | { |
---|
| 494 | for (int i = 0; i < numElement_-1; ++i) |
---|
| 495 | { |
---|
[553] | 496 | if (idxLoop[i] == dataNIndex_[i]) |
---|
[551] | 497 | { |
---|
| 498 | idxLoop[i] = 0; |
---|
[874] | 499 | correctIndexOfElement[i] = 0; |
---|
[551] | 500 | ++idxLoop[i+1]; |
---|
[874] | 501 | if (isOuterIndexCorrect) ++correctIndexOfElement[i+1]; |
---|
[551] | 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
[567] | 505 | // Depending the inner-most element axis or domain, |
---|
| 506 | // The outer loop index begins correspondingly at one (1) or zero (0) |
---|
[861] | 507 | bool isIndexElementDataCorrect = true; |
---|
[551] | 508 | for (int i = 1; i < numElement_; ++i) |
---|
| 509 | { |
---|
[861] | 510 | if (elementIndexData_[i](idxLoop[i])) |
---|
[551] | 511 | { |
---|
[874] | 512 | currentIndex[i] = elementLocalIndex_[i](correctIndexOfElement[i]); |
---|
| 513 | currentGlobalIndex[i] = elementGlobalIndex_[i](correctIndexOfElement[i]); |
---|
[861] | 514 | isIndexElementDataCorrect &= true; |
---|
[551] | 515 | } |
---|
[861] | 516 | else isIndexElementDataCorrect = false; |
---|
[551] | 517 | } |
---|
| 518 | |
---|
[861] | 519 | isOuterIndexCorrect = isIndexElementDataCorrect; |
---|
[623] | 520 | |
---|
[874] | 521 | if (isOuterIndexCorrect) |
---|
[551] | 522 | { |
---|
[874] | 523 | // Inner most index |
---|
| 524 | int correctIndexInnerElement = 0; |
---|
| 525 | for (int i = 0; i < innerLoopSize; ++i) |
---|
[861] | 526 | { |
---|
[874] | 527 | bool isCurrentIndexDataCorrect = isOuterIndexCorrect; |
---|
| 528 | if (elementIndexData_[0](i)) |
---|
[551] | 529 | { |
---|
[874] | 530 | currentIndex[0] = elementLocalIndex_[0](correctIndexInnerElement); |
---|
| 531 | currentGlobalIndex[0] = elementGlobalIndex_[0](correctIndexInnerElement); |
---|
| 532 | isCurrentIndexDataCorrect &= true; |
---|
| 533 | ++correctIndexInnerElement; |
---|
[553] | 534 | } |
---|
[874] | 535 | else isCurrentIndexDataCorrect = false; |
---|
[861] | 536 | |
---|
[874] | 537 | if (isCurrentIndexDataCorrect) |
---|
[553] | 538 | { |
---|
[874] | 539 | int gridMaskIndex = 0; |
---|
| 540 | for (int k = 0; k < this->numElement_; ++k) |
---|
[861] | 541 | { |
---|
[874] | 542 | gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; |
---|
[861] | 543 | } |
---|
| 544 | |
---|
[874] | 545 | if (gridMask_(gridMaskIndex)) |
---|
[861] | 546 | { |
---|
[1129] | 547 | size_t globalIndex = 0; |
---|
| 548 | for (int k = 0; k < numElement_; ++k) |
---|
| 549 | { |
---|
| 550 | globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; |
---|
| 551 | } |
---|
| 552 | globalDataIndex_[globalIndex] = indexLocalDataOnClientCount; |
---|
[874] | 553 | localDataIndex_[indexLocalDataOnClientCount] = countLocalData; |
---|
| 554 | bool isIndexOnServer = true; |
---|
| 555 | for (int idxElement = 0; idxElement < this->numElement_; ++idxElement) |
---|
[861] | 556 | { |
---|
[874] | 557 | isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](correctIndexOfElement[idxElement]); |
---|
[861] | 558 | } |
---|
[874] | 559 | |
---|
| 560 | if (isIndexOnServer) |
---|
| 561 | { |
---|
| 562 | globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; |
---|
| 563 | localMaskIndex_[indexSend2ServerCount] = gridMaskIndex; |
---|
[1250] | 564 | localMaskedDataIndex_[indexSend2ServerCount] = indexLocalDataOnClientCount; |
---|
[874] | 565 | ++indexSend2ServerCount; |
---|
| 566 | } |
---|
| 567 | ++indexLocalDataOnClientCount; |
---|
[861] | 568 | } |
---|
[553] | 569 | } |
---|
[874] | 570 | ++countLocalData; |
---|
| 571 | correctIndexOfElement[0] = correctIndexInnerElement;; |
---|
[551] | 572 | } |
---|
[861] | 573 | } |
---|
| 574 | idxLoop[0] += innerLoopSize; |
---|
| 575 | idx += innerLoopSize; |
---|
| 576 | } |
---|
| 577 | } |
---|
[551] | 578 | |
---|
[861] | 579 | void CDistributionClient::createGlobalIndex() |
---|
| 580 | { |
---|
[551] | 581 | } |
---|
| 582 | |
---|
| 583 | /*! |
---|
| 584 | Retrieve index i and index j of a domain from its data index |
---|
| 585 | Data contains not only true data, which are sent to servers, but also ghost data, which |
---|
| 586 | very often play a role of border of each local data, so does data index. Because data of a domain |
---|
| 587 | can be one dimension, or two dimensions, there is a need to convert data index to domain index |
---|
| 588 | \param [in] dataIIndex index of i data |
---|
| 589 | \param [in] dataJIndex index of j data |
---|
| 590 | \param [in] dataIBegin index begin of i data |
---|
| 591 | \param [in] dataJBegin index begin of j data |
---|
| 592 | \param [in] dataDim dimension of data (1 or 2) |
---|
| 593 | \param [in] ni local size ni of domain |
---|
| 594 | \param [out] j j index of domain |
---|
| 595 | \return i index of domain |
---|
| 596 | */ |
---|
| 597 | int CDistributionClient::getDomainIndex(const int& dataIIndex, const int& dataJIndex, |
---|
| 598 | const int& dataIBegin, const int& dataJBegin, |
---|
| 599 | const int& dataDim, const int& ni, int& j) |
---|
| 600 | { |
---|
| 601 | int tempI = dataIIndex + dataIBegin, |
---|
[660] | 602 | tempJ = (dataJIndex + dataJBegin); |
---|
| 603 | int i = (dataDim == 1) ? (tempI) % ni |
---|
| 604 | : (tempI) ; |
---|
| 605 | j = (dataDim == 1) ? (tempI) / ni |
---|
| 606 | : (tempJ) ; |
---|
[551] | 607 | |
---|
| 608 | return i; |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | /*! |
---|
| 612 | Retrieve index of an axis from its data index |
---|
| 613 | \param [in] dataIndex index of data |
---|
| 614 | \param [in] dataBegin index begin of data |
---|
| 615 | \param [in] ni local size of axis |
---|
| 616 | \return index of domain |
---|
| 617 | */ |
---|
| 618 | int CDistributionClient::getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni) |
---|
| 619 | { |
---|
| 620 | int tempI = dataIndex + dataBegin; |
---|
[666] | 621 | return ((tempI)%ni); |
---|
[551] | 622 | } |
---|
| 623 | |
---|
[831] | 624 | /*! |
---|
| 625 | Return global local data mapping of client |
---|
| 626 | */ |
---|
[861] | 627 | CDistributionClient::GlobalLocalDataMap& CDistributionClient::getGlobalLocalDataSendToServer() |
---|
[584] | 628 | { |
---|
[834] | 629 | if (!isComputed_) createGlobalIndexSendToServer(); |
---|
[831] | 630 | return globalLocalDataSendToServerMap_; |
---|
[584] | 631 | } |
---|
| 632 | |
---|
[1129] | 633 | CDistributionClient::GlobalLocalDataMap& CDistributionClient::getGlobalDataIndexOnClient() |
---|
| 634 | { |
---|
| 635 | if (!isComputed_) createGlobalIndexSendToServer(); |
---|
| 636 | return globalDataIndex_; |
---|
| 637 | } |
---|
| 638 | |
---|
[551] | 639 | /*! |
---|
| 640 | Return local data index of client |
---|
| 641 | */ |
---|
[834] | 642 | const std::vector<int>& CDistributionClient::getLocalDataIndexOnClient() |
---|
[551] | 643 | { |
---|
[834] | 644 | if (!isComputed_) createGlobalIndexSendToServer(); |
---|
[653] | 645 | return localDataIndex_; |
---|
[551] | 646 | } |
---|
| 647 | |
---|
[569] | 648 | /*! |
---|
[623] | 649 | Return local mask index of client |
---|
| 650 | */ |
---|
[834] | 651 | const std::vector<int>& CDistributionClient::getLocalMaskIndexOnClient() |
---|
[623] | 652 | { |
---|
[834] | 653 | if (!isComputed_) createGlobalIndexSendToServer(); |
---|
[653] | 654 | return localMaskIndex_; |
---|
[623] | 655 | } |
---|
| 656 | |
---|
[1250] | 657 | /*! |
---|
| 658 | Return local mask index of client |
---|
| 659 | */ |
---|
| 660 | const std::vector<int>& CDistributionClient::getLocalMaskedDataIndexOnClient() |
---|
| 661 | { |
---|
| 662 | if (!isComputed_) createGlobalIndexSendToServer(); |
---|
| 663 | return localMaskedDataIndex_; |
---|
| 664 | } |
---|
| 665 | |
---|
[551] | 666 | } // namespace xios |
---|