Changeset 829 for XIOS/trunk/src/transformation/grid_transformation.cpp
- Timestamp:
- 03/23/16 16:11:01 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/transformation/grid_transformation.cpp
r827 r829 19 19 #include "distribution_client.hpp" 20 20 #include "mpi_tag.hpp" 21 #include <boost/unordered_map.hpp> 21 22 22 23 namespace xios { … … 359 360 if (nbAlgos_ < 1) return; 360 361 if (!auxInputs_.empty() && !dynamicalTransformation_) { dynamicalTransformation_ = true; return; } 361 if (dynamicalTransformation_) GlobalIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map362 if (dynamicalTransformation_) DestinationIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map 362 363 363 364 CContext* context = CContext::getCurrent(); … … 374 375 ETranformationType transType = (it->second).first; 375 376 int transformationOrder = (it->second).second; 376 std::map<size_t, std::vector<std::pair<size_t,double> > >globaIndexWeightFromDestToSource;377 DestinationIndexMap globaIndexWeightFromDestToSource; 377 378 378 379 // First of all, select an algorithm … … 392 393 CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 393 394 const std::vector<size_t>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 395 const std::vector<int>& localIndexGridDestSendToServer = distributionClientDest.getLocalDataIndexSendToServer(); 394 396 395 397 // ComputeTransformation of global index of each element … … 401 403 gridSrcDimensionSize, 402 404 globalIndexGridDestSendToServer, 405 localIndexGridDestSendToServer, 403 406 globaIndexWeightFromDestToSource); 404 407 … … 446 449 iteArr = globalIndexOnClientDest.end(); 447 450 448 GlobalIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end();451 DestinationIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end(); 449 452 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 450 453 int maskIndexNum = 0; … … 453 456 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 454 457 { 455 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];458 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 456 459 for (int idx = 0; idx < vecIndex.size(); ++idx) 457 460 { 458 if (sfmax == vecIndex[idx].first)461 if (sfmax == (vecIndex[idx].second).first) 459 462 { 460 463 ++maskIndexNum; … … 471 474 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 472 475 { 473 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];476 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 474 477 for (int idx = 0; idx < vecIndex.size(); ++idx) 475 478 { 476 if (sfmax == vecIndex[idx].first)479 if (sfmax == (vecIndex[idx].second).first) 477 480 { 478 481 int localIdx = std::distance(itbArr, itArr); … … 493 496 the final grid destination 494 497 */ 495 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource)498 void CGridTransformation::computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource) 496 499 { 497 500 CContext* context = CContext::getCurrent(); … … 509 512 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 510 513 511 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();512 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();514 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 515 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 513 516 514 517 // Sending global index of original grid source 515 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend,516 iteSend = globalIndexToSend.end();518 CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend, 519 iteSend = globalIndexToSend.end(); 517 520 int sendBuffSize = 0; 518 521 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 526 529 for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax(); 527 530 528 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGrid , requestsWeightGrid;529 GlobalIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end();531 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGridGlobalIndex, requestsOriginalGridLocalIndex, requestsWeightGrid; 532 DestinationIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end(); 530 533 531 534 // Only send global index of original source corresponding to non-masked index … … 536 539 { 537 540 int destRank = itSend->first; 538 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;541 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 539 542 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 540 543 size_t countBlock = 0; 541 544 for (int idx = 0; idx < countSize; ++idx) 542 545 { 543 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;544 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) // searchCurrentSrc.search(itbIndex, iteIndex, globalIndexOfCurrentGridSourceToSend[idx], itIndex))546 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 547 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 545 548 { 546 549 globalIndexOriginalSrcSendBuffSize += currentGridIndexToOriginalGridIndex_[index].size() + 1; // 1 for number of elements in this block … … 555 558 } 556 559 557 Scalar* sendOriginal IndexBuff, *currentOriginalIndexSendBuff;558 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginal IndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize];560 Scalar* sendOriginalGlobalIndexBuff, *currentOriginalGlobalIndexSendBuff; 561 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize]; 559 562 double* sendOriginalWeightBuff, *currentOriginalWeightSendBuff; 560 563 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalWeightBuff = new double [globalIndexOriginalSrcSendBuffSize]; … … 564 567 { 565 568 int destRank = itSend->first; 566 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;569 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 567 570 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 568 571 int increaseStep = 0; 569 572 for (int idx = 0; idx < countSize; ++idx) 570 573 { 571 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;574 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 572 575 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 573 576 { 574 577 size_t vectorSize = currentGridIndexToOriginalGridIndex_[index].size(); 575 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = vectorSize;578 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = vectorSize; 576 579 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (double)vectorSize; 577 const std::vector<std::pair< size_t,double> >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index];580 const std::vector<std::pair<int, std::pair<size_t,double> > >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index]; 578 581 for (size_t i = 0; i < vectorSize; ++i) 579 582 { 580 583 ++increaseStep; 581 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].first;582 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].second;584 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).first; 585 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).second; 583 586 } 584 587 ++increaseStep; … … 586 589 } 587 590 588 currentOriginal IndexSendBuff = sendOriginalIndexBuff + currentBuffPosition;591 currentOriginalGlobalIndexSendBuff = sendOriginalGlobalIndexBuff + currentBuffPosition; 589 592 currentOriginalWeightSendBuff = sendOriginalWeightBuff + currentBuffPosition; 590 593 if (0 != increaseStep) 591 594 { 592 MPI_Isend(currentOriginalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &requestsOriginalGrid[destRank]); 593 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 595 MPI_Isend(currentOriginalGlobalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, 596 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &requestsOriginalGridGlobalIndex[destRank]); 597 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, 598 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 594 599 } 595 600 currentBuffPosition += increaseStep; … … 598 603 599 604 // Receiving global index of grid source sending from current grid source 600 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,601 605 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 606 iteRecv = globalIndexToReceive.end(); 602 607 int recvBuffSize = 0; 603 608 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); … … 623 628 } 624 629 625 Scalar* recvOriginal IndexBuff, *currentOriginalIndexRecvBuff;626 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginal IndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize];630 Scalar* recvOriginalGlobalIndexBuff, *currentOriginalGlobalIndexRecvBuff; 631 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize]; 627 632 double* recvOriginalWeightBuff, *currentOriginalWeightRecvBuff; 628 633 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalWeightBuff = new double [globalIndexOriginalSrcRecvBuffSize]; … … 633 638 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 634 639 { 635 MPI_Status status Index, statusWeight;640 MPI_Status statusGlobalIndex, statusLocalIndex, statusWeight; 636 641 int srcRank = itRecv->first; 637 642 countBlock = countBlockMap[srcRank]; 638 currentOriginal IndexRecvBuff = recvOriginalIndexBuff + currentBuffPosition;643 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff + currentBuffPosition; 639 644 currentOriginalWeightRecvBuff = recvOriginalWeightBuff + currentBuffPosition; 640 645 if (0 != countBlock) 641 646 { 642 MPI_Recv(currentOriginal IndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &statusIndex);647 MPI_Recv(currentOriginalGlobalIndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &statusGlobalIndex); 643 648 MPI_Recv(currentOriginalWeightRecvBuff, countBlock, MPI_DOUBLE, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &statusWeight); 644 649 } … … 649 654 // The way to process masked index needs discussing 650 655 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 651 GlobalIndexMap currentToOriginalTmp;656 DestinationIndexMap currentToOriginalTmp; 652 657 653 658 currentRecvBuffPosition = 0; 654 659 currentRecvBuff = recvBuff; 655 currentOriginal IndexRecvBuff = recvOriginalIndexBuff;660 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff; 656 661 currentOriginalWeightRecvBuff = recvOriginalWeightBuff; 657 662 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) … … 669 674 if (0 != countBlockRank) 670 675 { 671 countBlock = *(currentOriginal IndexRecvBuff+currentRecvBuffPosition);676 countBlock = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition); 672 677 for (int i = 0; i < ssize; ++i) 673 678 { 674 679 for (int j = 0; j < countBlock; ++j) 675 680 { 676 size_t globalOriginalIndex = *(currentOriginalIndexRecvBuff+currentRecvBuffPosition+j+1); 677 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second; 678 currentToOriginalTmp[(itRecv->second)[idx][i].first].push_back(make_pair(globalOriginalIndex,weightGlobal)); 681 size_t globalOriginalIndex = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition+j+1); 682 int currentGridLocalIndex = (itRecv->second)[idx][i].first; 683 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second.second; 684 currentToOriginalTmp[(itRecv->second)[idx][i].second.first].push_back(make_pair(currentGridLocalIndex,make_pair(globalOriginalIndex,weightGlobal))); 679 685 } 680 686 } … … 697 703 for (itRequest = requestsCurrentGrid.begin(); itRequest != requestsCurrentGrid.end(); ++itRequest) 698 704 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 699 for (itRequest = requestsOriginalGrid .begin(); itRequest != requestsOriginalGrid.end(); ++itRequest)705 for (itRequest = requestsOriginalGridGlobalIndex.begin(); itRequest != requestsOriginalGridGlobalIndex.end(); ++itRequest) 700 706 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 701 707 for (itRequest = requestsWeightGrid.begin(); itRequest != requestsWeightGrid.end(); ++itRequest) … … 704 710 if (0 != sendBuffSize) delete [] sendBuff; 705 711 if (0 != recvBuffSize) delete [] recvBuff; 706 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginal IndexBuff;712 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalGlobalIndexBuff; 707 713 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalWeightBuff; 708 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginal IndexBuff;714 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalGlobalIndexBuff; 709 715 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalWeightBuff; 710 716 } … … 724 730 transformationMap.computeTransformationMapping(currentGridIndexToOriginalGridIndex_); 725 731 726 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();727 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();728 729 CDistributionClient distributionClientDest(client->clientRank, gridDestination_);730 CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_);731 732 const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer();733 const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer();734 735 std::vector<size_t>::const_iterator itbArr, itArr, iteArr;736 std::vector<int>::const_iterator itIndex, itbIndex, iteIndex;737 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv;738 739 std::vector<int> permutIndex;740 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch;741 742 // Find out local index on grid destination (received)743 XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex);744 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex);745 itbIndex = permutIndex.begin();746 iteIndex = permutIndex.end();747 BinarySearch searchClientDest(globalIndexOnClientDest);732 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 733 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 734 735 // CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 736 // CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 737 // 738 // const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 739 // const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 740 741 // std::vector<size_t>::const_iterator itbArr, itArr, iteArr; 742 // std::vector<int>::const_iterator itIndex, itbIndex, iteIndex; 743 CTransformationMapping::ReceivedIndexMap::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 744 745 // std::vector<int> permutIndex; 746 // typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 747 // 748 // // Find out local index on grid destination (received) 749 // XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex); 750 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex); 751 // itbIndex = permutIndex.begin(); 752 // iteIndex = permutIndex.end(); 753 // BinarySearch searchClientDest(globalIndexOnClientDest); 748 754 itbMapRecv = globalIndexToReceive.begin(); 749 755 iteMapRecv = globalIndexToReceive.end(); … … 756 762 { 757 763 int vecSize = ((itMapRecv->second)[i]).size(); 758 std::vector<std::pair<int,double> > tmpVec;764 // std::vector<std::pair<int,double> > tmpVec; 759 765 for (int idx = 0; idx < vecSize; ++idx) 760 766 { 761 size_t globalIndex = (itMapRecv->second)[i][idx].first; 762 double weight = (itMapRecv->second)[i][idx].second; 763 if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 764 { 765 tmpVec.push_back(make_pair(*itIndex, weight)); 766 } 767 const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx]; 768 localIndexToReceiveOnGridDest_[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second)); 769 // size_t globalIndex = (itMapRecv->second)[i][idx].first; 770 // double weight = (itMapRecv->second)[i][idx].second; 771 // if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 772 // { 773 // tmpVec.push_back(make_pair(*itIndex, weight)); 774 // } 767 775 } 768 localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec;776 // localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec; 769 777 } 770 778 } 771 779 772 780 // Find out local index on grid source (to send) 773 std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap;774 XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex);775 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex);776 itbIndex = permutIndex.begin();777 iteIndex = permutIndex.end();778 BinarySearch searchClientSrc(globalIndexOnClientSrc);781 CTransformationMapping::SentIndexMap::const_iterator itbMap, itMap, iteMap; 782 // XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex); 783 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex); 784 // itbIndex = permutIndex.begin(); 785 // iteIndex = permutIndex.end(); 786 // BinarySearch searchClientSrc(globalIndexOnClientSrc); 779 787 itbMap = globalIndexToSend.begin(); 780 788 iteMap = globalIndexToSend.end(); … … 786 794 for (int idx = 0; idx < vecSize; ++idx) 787 795 { 788 if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex))789 {790 localIndexToSendFromGridSource_[destRank](idx) = *itIndex;791 }796 // if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex)) 797 // { 798 localIndexToSendFromGridSource_[destRank](idx) = itMap->second[idx].first; //*itIndex; 799 // } 792 800 } 793 801 }
Note: See TracChangeset
for help on using the changeset viewer.