Changeset 861
 Timestamp:
 06/09/16 11:32:11 (7 years ago)
 Location:
 XIOS/trunk/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

XIOS/trunk/src/distribution_client.cpp
r843 r861 16 16 , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_() 17 17 , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() 18 , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_()18 , gridMask_(), indexMap_() 19 19 , isDataDistributed_(true), axisNum_(0), domainNum_(0) 20 20 , localDataIndex_(), localMaskIndex_() 21 21 , globalLocalDataSendToServerMap_() 22 22 , infoIndex_(), isComputed_(false) 23 , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_() 24 , elementZoomMask_(), elementNLocal_(), elementNGlobal_() 23 25 { 24 26 } … … 29 31 , nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_() 30 32 , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() 31 , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_()33 , gridMask_(), indexMap_() 32 34 , isDataDistributed_(true), axisNum_(0), domainNum_(0) 33 35 , localDataIndex_(), localMaskIndex_() 34 36 , globalLocalDataSendToServerMap_() 35 37 , infoIndex_(), isComputed_(false) 38 , elementLocalIndex_(), elementGlobalIndex_(), elementIndexData_() 39 , elementZoomMask_(), elementNLocal_(), elementNGlobal_() 36 40 { 37 41 readDistributionInfo(grid); … … 154 158 idx = 0; 155 159 160 elementLocalIndex_.resize(numElement_); 161 elementGlobalIndex_.resize(numElement_); 162 elementIndexData_.resize(numElement_); 163 elementZoomMask_.resize(numElement_); 164 elementNLocal_.resize(numElement_); 165 elementNGlobal_.resize(numElement_); 166 elementNLocal_[0] = 1; 167 elementNGlobal_[0] = 1; 168 size_t localSize = 1, globalSize = 1; 169 156 170 isDataDistributed_ = false; 157 171 // Update all the vectors above 158 while (idx < numElement_)172 for (idx = 0; idx < numElement_; ++idx) 159 173 { 160 174 bool isDomain = axisDomainOrder(idx); 175 elementNLocal_[idx] = localSize; 176 elementNGlobal_[idx] = globalSize; 161 177 162 178 // If this is a domain … … 192 208 isDataDistributed_ = domList[domIndex]>isDistributed(); 193 209 210 localSize *= nLocal_.at(indexMap_[idx]+1)* nLocal_.at(indexMap_[idx]); 211 globalSize *= nGlob_.at(indexMap_[idx]+1)* nGlob_.at(indexMap_[idx]); 194 212 ++domIndex; 195 213 } … … 211 229 isDataDistributed_ = axisList[axisIndex]>isDistributed(); 212 230 231 localSize *= nLocal_.at(indexMap_[idx]); 232 globalSize *= nGlob_.at(indexMap_[idx]); 233 213 234 ++axisIndex; 214 235 } 215 ++idx;216 236 } 217 237 } … … 225 245 void CDistributionClient::createLocalDomainDataIndex() 226 246 { 227 int numDomain = 0;228 for (int i = 0; i < axisDomainOrder_.numElements(); ++i)229 if (axisDomainOrder_(i)) ++numDomain;230 231 localDomainIndex_.resize(numDomain*2);232 indexDomainData_.resize(numDomain);233 234 247 int idxDomain = 0; 235 248 for (int i = 0; i < axisDomainOrder_.numElements(); ++i) … … 237 250 if (axisDomainOrder_(i)) 238 251 { 239 int iIdx, jIdx = 0, count = 0; 240 indexDomainData_[idxDomain].resize(dataNIndex_[i], false); 252 elementIndexData_[i].resize(dataNIndex_[i]); 253 elementIndexData_[i] = false; 254 int iIdx, jIdx = 0, count = 0, localIndex; 241 255 for (int j = 0; j < dataNIndex_[i]; ++j) 242 256 { … … 249 263 (domainMasks_[idxDomain](iIdx + jIdx*nLocal_[indexMap_[i]]))) 250 264 { 251 (localDomainIndex_[idxDomain]).push_back(iIdx); 252 (localDomainIndex_[idxDomain*2+1]).push_back(jIdx); 253 indexDomainData_[idxDomain][j] = true; 265 ++count; 266 elementIndexData_[i](j) = true; 267 } 268 } 269 270 elementLocalIndex_[i].resize(count); 271 elementGlobalIndex_[i].resize(count); 272 elementZoomMask_[i].resize(count); 273 elementZoomMask_[i] = false; 274 count = 0; 275 CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 276 CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; 277 CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 278 CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; 279 for (int j = 0; j < dataNIndex_[i]; ++j) 280 { 281 if (tmpIndexElementData(j)) 282 { 283 iIdx = getDomainIndex((*dataIndex_[indexMap_[i]])(j), (*dataIndex_[indexMap_[i]+1])(j), 284 dataBegin_[indexMap_[i]], dataBegin_[indexMap_[i]+1], 285 dataDims_[i], nLocal_[indexMap_[i]], jIdx); 286 localIndex = tmpLocalElementIndex(count) = iIdx + jIdx * nLocal_[indexMap_[i]]; 287 tmpGlobalElementIndex(count) = (*infoIndex_[indexMap_[i]])(localIndex) + ((*infoIndex_[indexMap_[i]+1])(localIndex))*nGlob_[indexMap_[i]]; 288 if ((((*infoIndex_[indexMap_[i]])(localIndex)) <= nZoomEnd_[indexMap_[i]]) 289 && (nZoomBegin_[indexMap_[i]] <= ((*infoIndex_[indexMap_[i]])(localIndex))) 290 && (((*infoIndex_[indexMap_[i]+1])(localIndex)) <= nZoomEnd_[indexMap_[i]+1]) 291 && (nZoomBegin_[indexMap_[i]+1] <= ((*infoIndex_[indexMap_[i]+1])(localIndex)))) 292 { 293 tmpZoomMaskElement(count) = true; 294 } 295 ++count; 254 296 } 255 297 } … … 264 306 void CDistributionClient::createLocalAxisDataIndex() 265 307 { 266 int numAxis = 0;267 for (int i = 0; i < axisDomainOrder_.numElements(); ++i)268 if (!axisDomainOrder_(i)) ++numAxis;269 270 localAxisIndex_.resize(numAxis);271 indexAxisData_.resize(numAxis);272 273 308 int idxAxis = 0; 274 309 for (int i = 0; i < axisDomainOrder_.numElements(); ++i) … … 276 311 if (!axisDomainOrder_(i)) 277 312 { 278 int iIdx = 0; 279 indexAxisData_[idxAxis].resize(dataNIndex_[i], false); 313 elementIndexData_[i].resize(dataNIndex_[i]); 314 elementIndexData_[i] = false; 315 int iIdx = 0, count = 0, localIndex = 0; 280 316 for (int j = 0; j < dataNIndex_[i]; ++j) 281 317 { … … 284 320 (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx))) 285 321 { 286 localAxisIndex_[idxAxis].push_back(iIdx);287 indexAxisData_[idxAxis][j]= true;322 ++count; 323 elementIndexData_[i](j) = true; 288 324 } 289 325 } 326 327 elementLocalIndex_[i].resize(count); 328 elementGlobalIndex_[i].resize(count); 329 elementZoomMask_[i].resize(count); 330 elementZoomMask_[i] = false; 331 count = 0; 332 CArray<bool,1>& tmpIndexElementData = elementIndexData_[i]; 333 CArray<bool,1>& tmpZoomMaskElement = elementZoomMask_[i]; 334 CArray<int,1>& tmpLocalElementIndex = elementLocalIndex_[i]; 335 CArray<size_t,1>& tmpGlobalElementIndex = elementGlobalIndex_[i]; 336 for (int j = 0; j < dataNIndex_[i]; ++j) 337 { 338 if (tmpIndexElementData(j)) 339 { 340 iIdx = tmpLocalElementIndex(count) = getAxisIndex((*dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 341 tmpGlobalElementIndex(count) = (*infoIndex_[indexMap_[i]])(iIdx); 342 if ((((*infoIndex_[indexMap_[i]])(iIdx)) <= nZoomEnd_[indexMap_[i]]) 343 && (nZoomBegin_[indexMap_[i]] <= ((*infoIndex_[indexMap_[i]])(iIdx)))) 344 { 345 tmpZoomMaskElement(count) = true; 346 } 347 ++count; 348 } 349 } 290 350 ++idxAxis; 291 351 } 292 352 } 293 353 } 354 355 /*! 356 Create global index on client 357 In order to do the mapping between clientserver, each client creates its own 358 global index of sending data. This global index is then used to calculate to which server 359 the client needs to send it data as well as which part of data belongs to the server. 360 So as to make clients and server coherent in order of index, global index is calculated by 361 take into account of Cconvention, the rightmost dimension varies faster. 362 */ 363 void CDistributionClient::createGlobalIndexSendToServer() 364 { 365 if (isComputed_) return; 366 isComputed_ = true; 367 createLocalDomainDataIndex(); 368 createLocalAxisDataIndex(); 369 370 int idxDomain = 0, idxAxis = 0; 371 std::vector<int> eachElementSize(numElement_); 372 373 // Precompute size of the loop 374 for (int i = 0; i < numElement_; ++i) 375 { 376 eachElementSize[i] = elementLocalIndex_[i].numElements(); 377 } 378 379 // Compute size of the global index on client 380 std::vector<StdSize> idxLoop(numElement_,0); 381 std::vector<StdSize> currentIndex(numElement_,0); 382 std::vector<StdSize> currentGlobalIndex(numElement_,0); 383 int innerLoopSize = eachElementSize[0]; 384 size_t idx = 0, indexLocalDataOnClientCount = 0, indexSend2ServerCount = 0; 385 size_t ssize = 1; 386 for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; 387 while (idx < ssize) 388 { 389 for (int i = 0; i < numElement_1; ++i) 390 { 391 if (idxLoop[i] == eachElementSize[i]) 392 { 393 idxLoop[i] = 0; 394 ++idxLoop[i+1]; 395 } 396 } 397 398 // Find out outer index 399 // Depending the innermost element is axis or domain, 400 // The outer loop index begins correspondingly at one (1) or zero (0) 401 for (int i = 1; i < numElement_; ++i) 402 { 403 currentIndex[i] = elementLocalIndex_[i](idxLoop[i]); 404 } 405 406 // Inner most index 407 for (int i = 0; i < innerLoopSize; ++i) 408 { 409 int gridMaskIndex = 0; 410 for (int k = 0; k < this>numElement_; ++k) 411 { 412 gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 413 } 414 415 if (gridMask_(gridMaskIndex)) 416 { 417 ++indexLocalDataOnClientCount; 418 bool isIndexOnServer = true; 419 420 for (int idxElement = 0; idxElement < this>numElement_; ++idxElement) 421 { 422 isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](idxLoop[idxElement]); 423 } 424 if (isIndexOnServer) ++indexSend2ServerCount; 425 } 426 } 427 idxLoop[0] += innerLoopSize; 428 idx += innerLoopSize; 429 } 430 431 // Now allocate these arrays 432 localDataIndex_.resize(indexLocalDataOnClientCount); 433 localMaskIndex_.resize(indexSend2ServerCount); 434 globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); 435 436 // We need to loop with data index 437 idxLoop.assign(numElement_,0); 438 idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; 439 ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 440 innerLoopSize = dataNIndex_[0]; 441 int countLocalData = 0; 442 std::vector<int> correctOuterIndex(numElement_,0); 443 bool isOuterIndexCorrect = true; 444 while (idx < ssize) 445 { 446 for (int i = 0; i < numElement_1; ++i) 447 { 448 if (idxLoop[i] == dataNIndex_[i]) 449 { 450 idxLoop[i] = 0; 451 correctOuterIndex[i] = 0; 452 ++idxLoop[i+1]; 453 if (isOuterIndexCorrect) ++correctOuterIndex[i+1]; 454 } 455 } 456 457 // Depending the innermost element axis or domain, 458 // The outer loop index begins correspondingly at one (1) or zero (0) 459 bool isIndexElementDataCorrect = true; 460 for (int i = 1; i < numElement_; ++i) 461 { 462 if (elementIndexData_[i](idxLoop[i])) 463 { 464 currentIndex[i] = elementLocalIndex_[i](correctOuterIndex[i]); 465 currentGlobalIndex[i] = elementGlobalIndex_[i](correctOuterIndex[i]); 466 isIndexElementDataCorrect &= true; 467 } 468 else isIndexElementDataCorrect = false; 469 } 470 471 isOuterIndexCorrect = isIndexElementDataCorrect; 472 473 // Inner most index 474 int correctIndexElement = 0; 475 for (int i = 0; i < innerLoopSize; ++i) 476 { 477 bool isCurrentIndexDataCorrect = isOuterIndexCorrect; 478 if (elementIndexData_[0](i)) 479 { 480 currentIndex[0] = elementLocalIndex_[0](correctIndexElement); 481 currentGlobalIndex[0] = elementGlobalIndex_[0](correctIndexElement); 482 isCurrentIndexDataCorrect &= true; 483 ++correctIndexElement; 484 } 485 else isCurrentIndexDataCorrect = false; 486 487 if (isCurrentIndexDataCorrect) 488 { 489 int gridMaskIndex = 0; //currentIndex[0]; 490 for (int k = 0; k < this>numElement_; ++k) 491 { 492 gridMaskIndex += (currentIndex[k])*elementNLocal_[k]; 493 } 494 495 if (gridMask_(gridMaskIndex)) 496 { 497 localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 498 bool isIndexOnServer = true; 499 for (int idxElement = 0; idxElement < this>numElement_; ++idxElement) 500 { 501 isIndexOnServer = isIndexOnServer && elementZoomMask_[idxElement](idxLoop[idxElement]); 502 } 503 504 if (isIndexOnServer) 505 { 506 size_t globalIndex = 0; //currentGlobalIndex[0]; 507 for (int k = 0; k < numElement_; ++k) 508 { 509 globalIndex += (currentGlobalIndex[k])*elementNGlobal_[k]; 510 } 511 globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; 512 localMaskIndex_[indexSend2ServerCount] = gridMaskIndex; 513 ++indexSend2ServerCount; 514 } 515 ++indexLocalDataOnClientCount; 516 } 517 } 518 ++countLocalData; 519 } 520 idxLoop[0] += innerLoopSize; 521 idx += innerLoopSize; 522 } 523 } 524 525 ///*! 526 // Create local index of domain(s). 527 // A domain can have data index which even contains the "ghost" points. Very often, these 528 //data surround the true data. In order to send correct data to server, 529 //a client need to know index of the true data. 530 //*/ 531 //void CDistributionClient::createLocalDomainDataIndex() 532 //{ 533 // int numDomain = 0; 534 // for (int i = 0; i < axisDomainOrder_.numElements(); ++i) 535 // if (axisDomainOrder_(i)) ++numDomain; 536 // 537 // localDomainIndex_.resize(numDomain*2); 538 // indexDomainData_.resize(numDomain); 539 // 540 // int idxDomain = 0; 541 // for (int i = 0; i < axisDomainOrder_.numElements(); ++i) 542 // { 543 // if (axisDomainOrder_(i)) 544 // { 545 // int iIdx, jIdx = 0, count = 0; 546 // indexDomainData_[idxDomain].resize(dataNIndex_[i], false); 547 // for (int j = 0; j < dataNIndex_[i]; ++j) 548 // { 549 // iIdx = getDomainIndex((*dataIndex_[indexMap_[i]])(j), (*dataIndex_[indexMap_[i]+1])(j), 550 // dataBegin_[indexMap_[i]], dataBegin_[indexMap_[i]+1], 551 // dataDims_[i], nLocal_[indexMap_[i]], jIdx); 552 // 553 // if ((iIdx >= nBeginLocal_[indexMap_[i]]) && (iIdx < nLocal_[indexMap_[i]]) && 554 // (jIdx >= nBeginLocal_[indexMap_[i]+1]) && (jIdx < nLocal_[indexMap_[i]+1]) && 555 // (domainMasks_[idxDomain](iIdx + jIdx*nLocal_[indexMap_[i]]))) 556 // { 557 // (localDomainIndex_[idxDomain]).push_back(iIdx); 558 // (localDomainIndex_[idxDomain*2+1]).push_back(jIdx); 559 // indexDomainData_[idxDomain][j] = true; 560 // } 561 // } 562 // ++idxDomain; 563 // } 564 // } 565 //} 566 567 ///*! 568 // Create local index of axis. 569 //*/ 570 //void CDistributionClient::createLocalAxisDataIndex() 571 //{ 572 // int numAxis = 0; 573 // for (int i = 0; i < axisDomainOrder_.numElements(); ++i) 574 // if (!axisDomainOrder_(i)) ++numAxis; 575 // 576 // localAxisIndex_.resize(numAxis); 577 // indexAxisData_.resize(numAxis); 578 // 579 // int idxAxis = 0; 580 // for (int i = 0; i < axisDomainOrder_.numElements(); ++i) 581 // { 582 // if (!axisDomainOrder_(i)) 583 // { 584 // int iIdx = 0; 585 // indexAxisData_[idxAxis].resize(dataNIndex_[i], false); 586 // for (int j = 0; j < dataNIndex_[i]; ++j) 587 // { 588 // iIdx = getAxisIndex((*dataIndex_[indexMap_[i]])(j), dataBegin_[indexMap_[i]], nLocal_[indexMap_[i]]); 589 // if ((iIdx >= nBeginLocal_[indexMap_[i]]) && 590 // (iIdx < nLocal_[indexMap_[i]]) && (axisMasks_[idxAxis](iIdx))) 591 // { 592 // localAxisIndex_[idxAxis].push_back(iIdx); 593 // indexAxisData_[idxAxis][j] = true; 594 // } 595 // } 596 // ++idxAxis; 597 // } 598 // } 599 //} 294 600 295 601 void CDistributionClient::createGlobalIndex() … … 347 653 348 654 349 / *!350 Create global index on client351 In order to do the mapping between clientserver, each client creates its own352 global index of sending data. This global index is then used to calculate to which server353 the client needs to send it data as well as which part of data belongs to the server.354 So as to make clients and server coherent in order of index, global index is calculated by355 take into account of Cconvention, the rightmost dimension varies faster.356 */357 void CDistributionClient::createGlobalIndexSendToServer()358 {359 if (isComputed_) return;360 isComputed_ = true;361 createLocalDomainDataIndex();362 createLocalAxisDataIndex();363 364 int idxDomain = 0, idxAxis = 0;365 std::vector<int> eachElementSize(numElement_);366 367 // Precompute size of the loop368 for (int i = 0; i < numElement_; ++i)369 {370 if(axisDomainOrder_(i))371 {372 eachElementSize[i] = localDomainIndex_[idxDomain].size();373 idxDomain += 2;374 }375 else376 {377 eachElementSize[i] = localAxisIndex_[idxAxis].size();378 ++idxAxis;379 }380 }381 382 // Compute size of the global index on client383 std::vector<StdSize> idxLoop(numElement_,0);384 std::vector<StdSize> currentIndex(this>dims_,0);385 int innerLoopSize = eachElementSize[0];386 size_t idx = 0, indexLocalDataOnClientCount = 0, indexSend2ServerCount = 0;387 size_t ssize = 1;388 for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i];389 while (idx < ssize)390 {391 for (int i = 0; i < numElement_1; ++i)392 {393 if (idxLoop[i] == eachElementSize[i])394 {395 idxLoop[i] = 0;396 ++idxLoop[i+1];397 }398 }399 400 // Find out outer index401 // Depending the innermost element is axis or domain,402 // The outer loop index begins correspondingly at one (1) or zero (0)403 idxDomain = idxAxis = 0;404 if (axisDomainOrder_(0)) ++idxDomain;405 else ++idxAxis;406 for (int i = 1; i < numElement_; ++i)407 {408 if (axisDomainOrder_(i))409 {410 currentIndex[indexMap_[i]] = localDomainIndex_[idxDomain][idxLoop[i]];411 currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain+1][idxLoop[i]];412 idxDomain += 2;413 }414 else415 {416 currentIndex[indexMap_[i]] = localAxisIndex_[idxAxis][idxLoop[i]];417 ++idxAxis;418 }419 }420 421 // Inner most index422 idxDomain = idxAxis = 0;423 for (int i = 0; i < innerLoopSize; ++i)424 {425 if (axisDomainOrder_(0))426 {427 currentIndex[0] = localDomainIndex_[idxDomain][i];428 currentIndex[1] = localDomainIndex_[idxDomain+1][i];429 }430 else currentIndex[0] = localAxisIndex_[idxAxis][i];431 432 StdSize gridMaskIndex = currentIndex[0];433 int mulDimMask = 1;434 for (int k = 1; k < this>dims_; ++k)435 {436 mulDimMask *= nLocal_[k1];437 gridMaskIndex += (currentIndex[k])*mulDimMask;438 }439 440 if (gridMask_(gridMaskIndex))441 {442 ++indexLocalDataOnClientCount;443 bool isIndexOnServer = true;444 445 for (int idxElement = 0; idxElement < this>numElement_; ++idxElement)446 {447 int actualIdx = 0;448 if (axisDomainOrder_(idxElement))449 {450 actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]];451 isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]])452 && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(actualIdx)))453 && (((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]+1])454 && (nZoomBegin_[indexMap_[idxElement]+1] <= ((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)));455 }456 else457 {458 isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])) <= nZoomEnd_[indexMap_[idxElement]])459 && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])));460 }461 }462 if (isIndexOnServer) ++indexSend2ServerCount;463 }464 465 }466 idxLoop[0] += innerLoopSize;467 idx += innerLoopSize;468 }469 470 // Now allocate these arrays471 localDataIndex_.resize(indexLocalDataOnClientCount);472 localMaskIndex_.resize(indexSend2ServerCount);473 globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount);474 475 // We need to loop with data index476 idxLoop.assign(numElement_,0);477 idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0;478 ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i];479 innerLoopSize = dataNIndex_[0];480 int countLocalData = 0;481 std::vector<int> correctOuterIndex(numElement_,0);482 bool isOuterIndexCorrect = true;483 while (idx < ssize)484 {485 for (int i = 0; i < numElement_1; ++i)486 {487 if (idxLoop[i] == dataNIndex_[i])488 {489 idxLoop[i] = 0;490 correctOuterIndex[i] = 0;491 ++idxLoop[i+1];492 if (isOuterIndexCorrect) ++correctOuterIndex[i+1];493 }494 }495 496 // Depending the innermost element axis or domain,497 // The outer loop index begins correspondingly at one (1) or zero (0)498 idxDomain = idxAxis = 0;499 if (axisDomainOrder_(0)) ++idxDomain;500 else ++idxAxis;501 bool isIndexDomainDataCorrect = true;502 bool isIndexAxisDataCorrect = true;503 504 for (int i = 1; i < numElement_; ++i)505 {506 if (axisDomainOrder_(i))507 {508 if (indexDomainData_[idxDomain][idxLoop[i]])509 {510 currentIndex[indexMap_[i]] = localDomainIndex_[idxDomain][correctOuterIndex[i]];511 currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][correctOuterIndex[i]];512 isIndexDomainDataCorrect &= true;513 }514 else isIndexDomainDataCorrect = false;515 ++idxDomain;516 }517 else518 {519 if (indexAxisData_[idxAxis][idxLoop[i]])520 {521 currentIndex[indexMap_[i]] = localAxisIndex_[idxAxis][correctOuterIndex[i]];522 isIndexAxisDataCorrect &= true;523 }524 else isIndexAxisDataCorrect = false;525 ++idxAxis;526 }527 }528 529 isOuterIndexCorrect = (isIndexAxisDataCorrect) && (isIndexDomainDataCorrect);530 531 // Inner most index532 idxDomain = idxAxis = 0;533 int correctIndexDomain = 0, correctIndexAxis = 0;534 for (int i = 0; i < innerLoopSize; ++i)535 {536 bool isCurrentIndexDomainDataCorrect = isIndexDomainDataCorrect;537 bool isCurrentIndexAxisDataCorrect = isIndexAxisDataCorrect;538 539 if (axisDomainOrder_(0))540 {541 if (indexDomainData_[idxDomain][i])542 {543 currentIndex[0] = localDomainIndex_[idxDomain][correctIndexDomain];544 currentIndex[1] = localDomainIndex_[idxDomain+1][correctIndexDomain];545 isCurrentIndexDomainDataCorrect &= true;546 ++correctIndexDomain;547 }548 else isCurrentIndexDomainDataCorrect = false;549 }550 else551 {552 if (indexAxisData_[idxAxis][i])553 {554 currentIndex[0] = localAxisIndex_[idxAxis][correctIndexAxis];555 isCurrentIndexAxisDataCorrect &= true;556 ++correctIndexAxis;557 }558 else isCurrentIndexAxisDataCorrect = false;559 }560 561 int gridMaskIndex = currentIndex[0];562 int mulDimMask = 1;563 for (int k = 1; k < this>dims_; ++k)564 {565 mulDimMask *= nLocal_[k1];566 gridMaskIndex += (currentIndex[k])*mulDimMask;567 }568 569 if (isCurrentIndexDomainDataCorrect &&570 isCurrentIndexAxisDataCorrect &&571 gridMask_(gridMaskIndex))572 {573 localDataIndex_[indexLocalDataOnClientCount] = countLocalData;574 bool isIndexOnServer = true;575 for (int idxElement = 0; idxElement < this>numElement_; ++idxElement)576 {577 int actualIdx = 0;578 if (axisDomainOrder_(idxElement))579 {580 actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]];581 isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]])582 && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(actualIdx)))583 && (((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]+1])584 && (nZoomBegin_[indexMap_[idxElement]+1] <= ((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)));585 }586 else587 {588 isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])) <= nZoomEnd_[indexMap_[idxElement]])589 && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])));590 }591 }592 593 if (isIndexOnServer)594 {595 int actualIdx = (axisDomainOrder_(0)) ? currentIndex[0]+currentIndex[1]*nLocal_[0]596 : currentIndex[0];597 size_t globalIndex = (*infoIndex_[0])(actualIdx); //idxLoop[0] + nBeginGlobal_[0];598 size_t mulDim = 1;599 for (int idxElement = 0; idxElement < this>numElement_; ++idxElement)600 {601 if (axisDomainOrder_(idxElement))602 {603 actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]];604 int jb = (0 == idxElement) ? 1 : 0;605 for (int j = jb; j <= 1; ++j)606 {607 mulDim *= nGlob_[indexMap_[idxElement]+j1];608 globalIndex += ((*infoIndex_[indexMap_[idxElement]+j])(actualIdx))*mulDim;609 }610 }611 else612 {613 if (0 != idxElement)614 {615 mulDim *= nGlob_[indexMap_[idxElement]1];616 globalIndex += ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]]))*mulDim;617 }618 }619 }620 globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount;621 localMaskIndex_[indexSend2ServerCount] = gridMaskIndex;622 ++indexSend2ServerCount;623 }624 ++indexLocalDataOnClientCount;625 }626 ++countLocalData;627 }628 idxLoop[0] += innerLoopSize;629 idx += innerLoopSize;630 }631 }655 ///*! 656 // Create global index on client 657 // In order to do the mapping between clientserver, each client creates its own 658 //global index of sending data. This global index is then used to calculate to which server 659 //the client needs to send it data as well as which part of data belongs to the server. 660 //So as to make clients and server coherent in order of index, global index is calculated by 661 //take into account of Cconvention, the rightmost dimension varies faster. 662 //*/ 663 //void CDistributionClient::createGlobalIndexSendToServer() 664 //{ 665 // if (isComputed_) return; 666 // isComputed_ = true; 667 // createLocalDomainDataIndex(); 668 // createLocalAxisDataIndex(); 669 // 670 // int idxDomain = 0, idxAxis = 0; 671 // std::vector<int> eachElementSize(numElement_); 672 // 673 // // Precompute size of the loop 674 // for (int i = 0; i < numElement_; ++i) 675 // { 676 // if(axisDomainOrder_(i)) 677 // { 678 // eachElementSize[i] = localDomainIndex_[idxDomain].size(); 679 // idxDomain += 2; 680 // } 681 // else 682 // { 683 // eachElementSize[i] = localAxisIndex_[idxAxis].size(); 684 // ++idxAxis; 685 // } 686 // } 687 // 688 // // Compute size of the global index on client 689 // std::vector<StdSize> idxLoop(numElement_,0); 690 // std::vector<StdSize> currentIndex(this>dims_,0); 691 // int innerLoopSize = eachElementSize[0]; 692 // size_t idx = 0, indexLocalDataOnClientCount = 0, indexSend2ServerCount = 0; 693 // size_t ssize = 1; 694 // for (int i = 0; i < numElement_; ++i) ssize *= eachElementSize[i]; 695 // while (idx < ssize) 696 // { 697 // for (int i = 0; i < numElement_1; ++i) 698 // { 699 // if (idxLoop[i] == eachElementSize[i]) 700 // { 701 // idxLoop[i] = 0; 702 // ++idxLoop[i+1]; 703 // } 704 // } 705 // 706 // // Find out outer index 707 // // Depending the innermost element is axis or domain, 708 // // The outer loop index begins correspondingly at one (1) or zero (0) 709 // idxDomain = idxAxis = 0; 710 // if (axisDomainOrder_(0)) ++idxDomain; 711 // else ++idxAxis; 712 // for (int i = 1; i < numElement_; ++i) 713 // { 714 // if (axisDomainOrder_(i)) 715 // { 716 // currentIndex[indexMap_[i]] = localDomainIndex_[idxDomain][idxLoop[i]]; 717 // currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain+1][idxLoop[i]]; 718 // idxDomain += 2; 719 // } 720 // else 721 // { 722 // currentIndex[indexMap_[i]] = localAxisIndex_[idxAxis][idxLoop[i]]; 723 // ++idxAxis; 724 // } 725 // } 726 // 727 // // Inner most index 728 // idxDomain = idxAxis = 0; 729 // for (int i = 0; i < innerLoopSize; ++i) 730 // { 731 // if (axisDomainOrder_(0)) 732 // { 733 // currentIndex[0] = localDomainIndex_[idxDomain][i]; 734 // currentIndex[1] = localDomainIndex_[idxDomain+1][i]; 735 // } 736 // else currentIndex[0] = localAxisIndex_[idxAxis][i]; 737 // 738 // StdSize gridMaskIndex = currentIndex[0]; 739 // int mulDimMask = 1; 740 // for (int k = 1; k < this>dims_; ++k) 741 // { 742 // mulDimMask *= nLocal_[k1]; 743 // gridMaskIndex += (currentIndex[k])*mulDimMask; 744 // } 745 // 746 // if (gridMask_(gridMaskIndex)) 747 // { 748 // ++indexLocalDataOnClientCount; 749 // bool isIndexOnServer = true; 750 // 751 // for (int idxElement = 0; idxElement < this>numElement_; ++idxElement) 752 // { 753 // int actualIdx = 0; 754 // if (axisDomainOrder_(idxElement)) 755 // { 756 // actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]]; 757 // isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]]) 758 // && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(actualIdx))) 759 // && (((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]+1]) 760 // && (nZoomBegin_[indexMap_[idxElement]+1] <= ((*infoIndex_[indexMap_[idxElement]+1])(actualIdx))); 761 // } 762 // else 763 // { 764 // isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])) <= nZoomEnd_[indexMap_[idxElement]]) 765 // && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]]))); 766 // } 767 // } 768 // if (isIndexOnServer) ++indexSend2ServerCount; 769 // } 770 // 771 // } 772 // idxLoop[0] += innerLoopSize; 773 // idx += innerLoopSize; 774 // } 775 // 776 // // Now allocate these arrays 777 // localDataIndex_.resize(indexLocalDataOnClientCount); 778 // localMaskIndex_.resize(indexSend2ServerCount); 779 // globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); 780 // 781 // // We need to loop with data index 782 // idxLoop.assign(numElement_,0); 783 // idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; 784 // ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 785 // innerLoopSize = dataNIndex_[0]; 786 // int countLocalData = 0; 787 // std::vector<int> correctOuterIndex(numElement_,0); 788 // bool isOuterIndexCorrect = true; 789 // while (idx < ssize) 790 // { 791 // for (int i = 0; i < numElement_1; ++i) 792 // { 793 // if (idxLoop[i] == dataNIndex_[i]) 794 // { 795 // idxLoop[i] = 0; 796 // correctOuterIndex[i] = 0; 797 // ++idxLoop[i+1]; 798 // if (isOuterIndexCorrect) ++correctOuterIndex[i+1]; 799 // } 800 // } 801 // 802 // // Depending the innermost element axis or domain, 803 // // The outer loop index begins correspondingly at one (1) or zero (0) 804 // idxDomain = idxAxis = 0; 805 // if (axisDomainOrder_(0)) ++idxDomain; 806 // else ++idxAxis; 807 // bool isIndexDomainDataCorrect = true; 808 // bool isIndexAxisDataCorrect = true; 809 // 810 // for (int i = 1; i < numElement_; ++i) 811 // { 812 // if (axisDomainOrder_(i)) 813 // { 814 // if (indexDomainData_[idxDomain][idxLoop[i]]) 815 // { 816 // currentIndex[indexMap_[i]] = localDomainIndex_[idxDomain][correctOuterIndex[i]]; 817 // currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][correctOuterIndex[i]]; 818 // isIndexDomainDataCorrect &= true; 819 // } 820 // else isIndexDomainDataCorrect = false; 821 // ++idxDomain; 822 // } 823 // else 824 // { 825 // if (indexAxisData_[idxAxis][idxLoop[i]]) 826 // { 827 // currentIndex[indexMap_[i]] = localAxisIndex_[idxAxis][correctOuterIndex[i]]; 828 // isIndexAxisDataCorrect &= true; 829 // } 830 // else isIndexAxisDataCorrect = false; 831 // ++idxAxis; 832 // } 833 // } 834 // 835 // isOuterIndexCorrect = (isIndexAxisDataCorrect) && (isIndexDomainDataCorrect); 836 // 837 // // Inner most index 838 // idxDomain = idxAxis = 0; 839 // int correctIndexDomain = 0, correctIndexAxis = 0; 840 // for (int i = 0; i < innerLoopSize; ++i) 841 // { 842 // bool isCurrentIndexDomainDataCorrect = isIndexDomainDataCorrect; 843 // bool isCurrentIndexAxisDataCorrect = isIndexAxisDataCorrect; 844 // 845 // if (axisDomainOrder_(0)) 846 // { 847 // if (indexDomainData_[idxDomain][i]) 848 // { 849 // currentIndex[0] = localDomainIndex_[idxDomain][correctIndexDomain]; 850 // currentIndex[1] = localDomainIndex_[idxDomain+1][correctIndexDomain]; 851 // isCurrentIndexDomainDataCorrect &= true; 852 // ++correctIndexDomain; 853 // } 854 // else isCurrentIndexDomainDataCorrect = false; 855 // } 856 // else 857 // { 858 // if (indexAxisData_[idxAxis][i]) 859 // { 860 // currentIndex[0] = localAxisIndex_[idxAxis][correctIndexAxis]; 861 // isCurrentIndexAxisDataCorrect &= true; 862 // ++correctIndexAxis; 863 // } 864 // else isCurrentIndexAxisDataCorrect = false; 865 // } 866 // 867 // int gridMaskIndex = currentIndex[0]; 868 // int mulDimMask = 1; 869 // for (int k = 1; k < this>dims_; ++k) 870 // { 871 // mulDimMask *= nLocal_[k1]; 872 // gridMaskIndex += (currentIndex[k])*mulDimMask; 873 // } 874 // 875 // if (isCurrentIndexDomainDataCorrect && 876 // isCurrentIndexAxisDataCorrect && 877 // gridMask_(gridMaskIndex)) 878 // { 879 // localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 880 // bool isIndexOnServer = true; 881 // for (int idxElement = 0; idxElement < this>numElement_; ++idxElement) 882 // { 883 // int actualIdx = 0; 884 // if (axisDomainOrder_(idxElement)) 885 // { 886 // actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]]; 887 // isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]]) 888 // && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(actualIdx))) 889 // && (((*infoIndex_[indexMap_[idxElement]+1])(actualIdx)) <= nZoomEnd_[indexMap_[idxElement]+1]) 890 // && (nZoomBegin_[indexMap_[idxElement]+1] <= ((*infoIndex_[indexMap_[idxElement]+1])(actualIdx))); 891 // } 892 // else 893 // { 894 // isIndexOnServer = isIndexOnServer && (((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]])) <= nZoomEnd_[indexMap_[idxElement]]) 895 // && (nZoomBegin_[indexMap_[idxElement]] <= ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]]))); 896 // } 897 // } 898 // 899 // if (isIndexOnServer) 900 // { 901 // int actualIdx = (axisDomainOrder_(0)) ? currentIndex[0]+currentIndex[1]*nLocal_[0] 902 // : currentIndex[0]; 903 // size_t globalIndex = (*infoIndex_[0])(actualIdx); //idxLoop[0] + nBeginGlobal_[0]; 904 // size_t mulDim = 1; 905 // for (int idxElement = 0; idxElement < this>numElement_; ++idxElement) 906 // { 907 // if (axisDomainOrder_(idxElement)) 908 // { 909 // actualIdx = currentIndex[indexMap_[idxElement]]+currentIndex[indexMap_[idxElement]+1]*nLocal_[indexMap_[idxElement]]; 910 // int jb = (0 == idxElement) ? 1 : 0; 911 // for (int j = jb; j <= 1; ++j) 912 // { 913 // mulDim *= nGlob_[indexMap_[idxElement]+j1]; 914 // globalIndex += ((*infoIndex_[indexMap_[idxElement]+j])(actualIdx))*mulDim; 915 // } 916 // } 917 // else 918 // { 919 // if (0 != idxElement) 920 // { 921 // mulDim *= nGlob_[indexMap_[idxElement]1]; 922 // globalIndex += ((*infoIndex_[indexMap_[idxElement]])(currentIndex[indexMap_[idxElement]]))*mulDim; 923 // } 924 // } 925 // } 926 // globalLocalDataSendToServerMap_[globalIndex] = indexLocalDataOnClientCount; 927 // localMaskIndex_[indexSend2ServerCount] = gridMaskIndex; 928 // ++indexSend2ServerCount; 929 // } 930 // ++indexLocalDataOnClientCount; 931 // } 932 // ++countLocalData; 933 // } 934 // idxLoop[0] += innerLoopSize; 935 // idx += innerLoopSize; 936 // } 937 //} 632 938 633 939 /*! … … 675 981 Return global local data mapping of client 676 982 */ 677 constCDistributionClient::GlobalLocalDataMap& CDistributionClient::getGlobalLocalDataSendToServer()983 CDistributionClient::GlobalLocalDataMap& CDistributionClient::getGlobalLocalDataSendToServer() 678 984 { 679 985 if (!isComputed_) createGlobalIndexSendToServer(); 
XIOS/trunk/src/distribution_client.hpp
r843 r861 43 43 44 44 virtual const std::vector<int>& getLocalDataIndexOnClient(); 45 constGlobalLocalDataMap& getGlobalLocalDataSendToServer();45 GlobalLocalDataMap& getGlobalLocalDataSendToServer(); 46 46 const std::vector<int>& getLocalMaskIndexOnClient(); 47 47 … … 101 101 std::vector<CArray<bool,1> > axisMasks_; //!< Axis mask 102 102 103 std::vector<std::vector<int> > localDomainIndex_;104 std::vector<std::vector<int> > localAxisIndex_;105 103 std::vector<int> indexMap_; //!< Mapping element index to dimension index 106 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_; 104 std::vector<CArray<int,1> > elementLocalIndex_; //!< Local index of each element 105 std::vector<CArray<size_t,1> > elementGlobalIndex_; //!< Global index of each element 106 std::vector<CArray<bool,1> > elementIndexData_; //!< // The correct index of a domain has true value, the ghost one has false value 107 std::vector<CArray<bool,1> > elementZoomMask_; //!< Only zoomed region are true 108 std::vector<size_t> elementNLocal_; 109 std::vector<size_t> elementNGlobal_; 110 110 111 111 //!< (Only for grid with one axis or scalar)Flag to determine whether data is distributed or not
Note: See TracChangeset
for help on using the changeset viewer.