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