Changeset 668
- Timestamp:
- 08/24/15 14:53:36 (9 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/distribution_client.cpp
r666 r668 18 18 , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 19 19 , isDataDistributed_(true), axisNum_(0), domainNum_(0), nIndexDomain_(), nIndexAxis_() 20 , globalDataSendToServer_(), localDataIndexSendToServer_(), localDataIndex_(), localMaskIndex_() 20 21 { 21 22 } … … 28 29 , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 29 30 , isDataDistributed_(true), axisNum_(0), domainNum_(0), nIndexDomain_(), nIndexAxis_() 31 , globalDataSendToServer_(), localDataIndexSendToServer_(), localDataIndex_(), localMaskIndex_() 30 32 { 31 33 readDistributionInfo(grid); … … 568 570 gridMask_(gridMaskIndex)) 569 571 { 570 localDataIndex_ (indexLocalDataOnClientCount)= countLocalData;572 localDataIndex_[indexLocalDataOnClientCount] = countLocalData; 571 573 572 574 bool isIndexOnServer = true; … … 584 586 globalIndex += (currentIndex[k] + nBeginGlobal_[k])*mulDim; 585 587 } 586 globalDataSendToServer_ (indexSend2ServerCount)= globalIndex;587 localDataIndexSendToServer_ (indexSend2ServerCount)= indexLocalDataOnClientCount;588 localMaskIndex_ (indexSend2ServerCount)= gridMaskIndex;588 globalDataSendToServer_[indexSend2ServerCount] = globalIndex; 589 localDataIndexSendToServer_[indexSend2ServerCount] = indexLocalDataOnClientCount; 590 localMaskIndex_[indexSend2ServerCount] = gridMaskIndex; 589 591 ++indexSend2ServerCount; 590 592 } … … 639 641 } 640 642 641 const CArray<size_t,1>& CDistributionClient::getGlobalDataIndexSendToServer() const643 const std::vector<size_t>& CDistributionClient::getGlobalDataIndexSendToServer() const 642 644 { 643 645 return globalDataSendToServer_; … … 647 649 Return local data index of client 648 650 */ 649 const CArray<int,1>& CDistributionClient::getLocalDataIndexOnClient() const651 const std::vector<int>& CDistributionClient::getLocalDataIndexOnClient() const 650 652 { 651 653 return localDataIndex_; … … 655 657 Return local mask index of client 656 658 */ 657 const CArray<int,1>& CDistributionClient::getLocalMaskIndexOnClient() const659 const std::vector<int>& CDistributionClient::getLocalMaskIndexOnClient() const 658 660 { 659 661 return localMaskIndex_; … … 663 665 Return local data index on client which are sent to servers 664 666 */ 665 const CArray<int,1>& CDistributionClient::getLocalDataIndexSendToServer() const667 const std::vector<int>& CDistributionClient::getLocalDataIndexSendToServer() const 666 668 { 667 669 return localDataIndexSendToServer_; -
XIOS/trunk/src/distribution_client.hpp
r664 r668 36 36 virtual ~CDistributionClient(); 37 37 38 virtual const CArray<int,1>& getLocalDataIndexOnClient() const;39 virtual const CArray<int,1>& getLocalDataIndexSendToServer() const;40 const CArray<size_t,1>& getGlobalDataIndexSendToServer() const;41 const CArray<int,1>& getLocalMaskIndexOnClient() const;38 virtual const std::vector<int>& getLocalDataIndexOnClient() const; 39 virtual const std::vector<int>& getLocalDataIndexSendToServer() const; 40 const std::vector<size_t>& getGlobalDataIndexSendToServer() const; 41 const std::vector<int>& getLocalMaskIndexOnClient() const; 42 42 43 43 std::vector<int> getNGlob() { return nGlob_; } … … 72 72 private: 73 73 //!< LocalData index on client 74 CArray<size_t,1> globalDataSendToServer_;75 CArray<int,1> localDataIndex_;76 CArray<int,1> localDataIndexSendToServer_;77 CArray<int,1> localMaskIndex_;74 std::vector<size_t> globalDataSendToServer_; 75 std::vector<int> localDataIndex_; 76 std::vector<int> localDataIndexSendToServer_; 77 std::vector<int> localMaskIndex_; 78 78 79 79 private: -
XIOS/trunk/src/distribution_server.cpp
r653 r668 8 8 */ 9 9 #include "distribution_server.hpp" 10 #include "utils.hpp" 10 11 11 12 namespace xios { … … 91 92 CArray<size_t,1> CDistributionServer::computeLocalIndex(const CArray<size_t,1>& globalIndex) 92 93 { 93 CArray<size_t,1>::const_iterator itBegin = this->globalIndex_.begin(),94 itEnd = this->globalIndex_.end(), it;94 int ssize = globalIndex.numElements(); 95 int nbGlobalIndex = this->globalIndex_.numElements(); 95 96 96 int ssize = globalIndex.numElements(), idx = 0; 97 std::vector<int>::iterator it; 98 std::vector<int> permutIndex(nbGlobalIndex); 99 XIOSAlgorithms::fillInIndex(nbGlobalIndex, permutIndex); 100 XIOSAlgorithms::sortWithIndex<size_t, CArrayStorage>(this->globalIndex_, permutIndex); 101 typedef XIOSBinarySearchWithIndex<size_t, CArrayStorage> BinarySearch; 102 BinarySearch binarySearch(this->globalIndex_); 103 97 104 CArray<size_t,1> localIndex(ssize); 98 i t = itBegin;105 int idx = 0; 99 106 for (int i = 0; i < ssize; ++i) 100 107 { 101 it = std::find(itBegin, itEnd, globalIndex(i)); 102 // it = std::lower_bound(it, itEnd, globalIndex(i)); 103 if (itEnd != it) 108 if (binarySearch.search(permutIndex.begin(), permutIndex.end(), globalIndex(i), it)) 104 109 { 105 localIndex(idx) = std::distance(itBegin, it);110 localIndex(idx) = *it; 106 111 ++idx; 107 112 } … … 117 122 void CDistributionServer::computeLocalIndex(CArray<size_t,1>& globalIndex) 118 123 { 119 CArray<size_t,1>::const_iterator itBegin = this->globalIndex_.begin(),120 itEnd = this->globalIndex_.end(), it;124 int ssize = globalIndex.numElements(); 125 int nbGlobalIndex = this->globalIndex_.numElements(); 121 126 122 int ssize = globalIndex.numElements(), idx = 0; 127 std::vector<int>::iterator it; 128 std::vector<int> permutIndex(nbGlobalIndex); 129 XIOSAlgorithms::fillInIndex(nbGlobalIndex, permutIndex); 130 XIOSAlgorithms::sortWithIndex<size_t, CArrayStorage>(this->globalIndex_, permutIndex); 131 typedef XIOSBinarySearchWithIndex<size_t, CArrayStorage> BinarySearch; 132 BinarySearch binarySearch(this->globalIndex_); 133 123 134 CArray<size_t,1> localIndex(ssize); 124 i t = itBegin;135 int idx = 0; 125 136 for (int i = 0; i < ssize; ++i) 126 137 { 127 it = std::find(itBegin, itEnd, globalIndex(i)); 128 // it = std::lower_bound(it, itEnd, globalIndex(i)); 129 if (itEnd != it) 138 if (binarySearch.search(permutIndex.begin(), permutIndex.end(), globalIndex(i), it)) 130 139 { 131 localIndex(idx) = std::distance(itBegin, it);140 localIndex(idx) = *it; 132 141 ++idx; 133 142 } -
XIOS/trunk/src/node/domain.cpp
r667 r668 832 832 std::map<int, std::vector<size_t> >::const_iterator it = globalIndexDomainOnServer.begin(), 833 833 ite = globalIndexDomainOnServer.end(); 834 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 835 std::vector<int>::iterator itVec; 836 834 837 indSrv_.clear(); 835 838 for (; it != ite; ++it) 836 839 { 837 840 int rank = it->first; 838 std::vector<size_t>::const_iterator itbVec = (it->second).begin(), 839 iteVec = (it->second).end(); 841 int indexSize = it->second.size(); 842 std::vector<int> permutIndex(indexSize); 843 XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 844 XIOSAlgorithms::sortWithIndex<size_t>(it->second, permutIndex); 845 BinarySearch binSearch(it->second); 840 846 int nb = globalIndexDomainZoom.numElements(); 841 847 for (int i = 0; i < nb; ++i) 842 848 { 843 if ( iteVec != std::find(itbVec, iteVec, globalIndexDomainZoom(i)))849 if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexDomainZoom(i), itVec)) 844 850 { 845 851 indSrv_[rank].push_back(localIndexDomainZoom(i)); -
XIOS/trunk/src/node/grid.cpp
r666 r668 317 317 clientDistribution_ = new CDistributionClient(client->clientRank, this); 318 318 // Get local data index on client 319 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 320 storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 319 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 320 int nbStoreIndex = storeIndex_client.numElements(); 321 for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 321 322 isDataDistributed_= clientDistribution_->isDataDistributed(); 322 323 … … 325 326 if (0 == client->clientRank) 326 327 { 327 size_t ssize = clientDistribution_->getLocalDataIndexOnClient(). numElements();328 size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 328 329 for (int rank = 0; rank < client->serverSize; ++rank) 329 330 connectedDataSize_[rank] = ssize; … … 359 360 clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex()); 360 361 const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 361 const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer();362 const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 362 363 std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 363 364 itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 364 365 iteGlobalMap = globalIndexOnServer.end(); 365 366 366 int nbGlobalIndex = globalIndexSendToServer.numElements(); 367 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 368 { 369 int serverRank = itGlobalMap->first; 370 std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), itVecGlobal, 371 iteVecGlobal = (itGlobalMap->second).end(); 372 for (int i = 0; i < nbGlobalIndex; ++i) 373 { 374 if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) 375 { 376 if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) 377 connectedDataSize_[serverRank] = 1; 378 else 379 ++connectedDataSize_[serverRank]; 380 } 381 } 382 } 383 384 connectedServerRank_.clear(); 385 for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { 386 connectedServerRank_.push_back(it->first); 387 } 388 if (!connectedDataSize_.empty()) 389 { 367 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 368 std::vector<int>::iterator itVec; 369 int nbGlobalIndex = globalIndexSendToServer.size(); 370 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 371 { 372 int serverRank = itGlobalMap->first; 373 int indexSize = itGlobalMap->second.size(); 374 std::vector<int> permutIndex(indexSize); 375 XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 376 XIOSAlgorithms::sortWithIndex<size_t>(itGlobalMap->second, permutIndex); 377 BinarySearch binSearch(itGlobalMap->second); 378 for (int i = 0; i < nbGlobalIndex; ++i) 379 { 380 if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexSendToServer[i], itVec)) 381 { 382 if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) 383 connectedDataSize_[serverRank] = 1; 384 else 385 ++connectedDataSize_[serverRank]; 386 } 387 } 388 } 389 390 390 connectedServerRank_.clear(); 391 for (std::map<int, size_t>::const_iterator it = connectedDataSize_.begin(); it != connectedDataSize_.end(); ++it)391 for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { 392 392 connectedServerRank_.push_back(it->first); 393 } 394 395 nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 393 } 394 if (!connectedDataSize_.empty()) 395 { 396 connectedServerRank_.clear(); 397 for (std::map<int,size_t>::const_iterator it = connectedDataSize_.begin(); it != connectedDataSize_.end(); ++it) 398 connectedServerRank_.push_back(it->first); 399 } 400 401 nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 396 402 } 397 403 … … 562 568 list<CArray<size_t,1> > listOutIndex; 563 569 const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 564 const CArray<int,1>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer();565 const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer();570 const std::vector<int>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer(); 571 const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 566 572 567 573 if (!doGridHaveDataDistributed()) … … 569 575 if (0 == client->clientRank) 570 576 { 571 const CArray<size_t, 1>& outGlobalIndexOnServer = globalIndexSendToServer; 572 const CArray<int,1>& outLocalIndexToServer = localIndexSendToServer; 577 CArray<size_t,1> outGlobalIndexOnServer(globalIndexSendToServer.size()); 578 for (int idx = 0; idx < globalIndexSendToServer.size();++idx) 579 outGlobalIndexOnServer(idx) = globalIndexSendToServer[idx]; 580 581 CArray<int,1> outLocalIndexToServer(localIndexSendToServer.size()); 582 for (int idx = 0; idx < localIndexSendToServer.size();++idx) 583 outLocalIndexToServer(idx) = localIndexSendToServer[idx]; 573 584 574 585 for (rank = 0; rank < client->serverSize; ++rank) … … 594 605 iteGlobalMap = globalIndexOnServer.end(); 595 606 596 int nbGlobalIndex = globalIndexSendToServer. numElements();607 int nbGlobalIndex = globalIndexSendToServer.size(); 597 608 std::map<int,std::vector<int> >localIndexTmp; 598 609 std::map<int,std::vector<size_t> > globalIndexTmp; 599 610 611 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 612 std::vector<int>::iterator itVec; 600 613 for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 601 614 { 602 615 int serverRank = itGlobalMap->first; 603 std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), 604 iteVecGlobal = (itGlobalMap->second).end(); 616 int indexSize = itGlobalMap->second.size(); 617 std::vector<int> permutIndex(indexSize); 618 XIOSAlgorithms::fillInIndex(indexSize, permutIndex); 619 XIOSAlgorithms::sortWithIndex<size_t>(itGlobalMap->second, permutIndex); 620 BinarySearch binSearch(itGlobalMap->second); 621 605 622 for (int i = 0; i < nbGlobalIndex; ++i) 606 623 { 607 if ( iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i)))624 if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexSendToServer[i], itVec)) 608 625 { 609 globalIndexTmp[serverRank].push_back(globalIndexSendToServer (i));610 localIndexTmp[serverRank].push_back(localIndexSendToServer (i));626 globalIndexTmp[serverRank].push_back(globalIndexSendToServer[i]); 627 localIndexTmp[serverRank].push_back(localIndexSendToServer[i]); 611 628 } 612 629 } -
XIOS/trunk/src/test/test_client.f90
r666 r668 79 79 CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj,type='curvilinear') 80 80 CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) 81 !CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat)81 CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat) 82 82 CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.) 83 83 … … 113 113 114 114 ni=0 ; lonvalue(:,:)=0; 115 ! CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lon)115 CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue) 116 116 117 117 print *,"ni",ni 118 print *,"lonvalue",lon ;118 print *,"lonvalue",lonvalue; 119 119 120 120 CALL xios_is_defined_field_attr("field_A",enabled=ok) -
XIOS/trunk/src/transformation/axis_algorithm_interpolate.cpp
r666 r668 50 50 51 51 retrieveAllAxisValue(recvBuff, indexVec); 52 order<double>(recvBuff, indexVec);52 XIOSAlgorithms::sortWithIndex<double, CVectorStorage>(recvBuff, indexVec); 53 53 computeInterpolantPoint(recvBuff, indexVec); 54 54 } -
XIOS/trunk/src/transformation/axis_algorithm_transformation.cpp
r666 r668 39 39 \param[in] axisPositionInGrid position of the axis in the grid 40 40 \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the axis on which transformation is performed) 41 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s) 41 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted 42 42 \param[in/out] globalIndexDestGrid array of global index (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated 43 43 \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated … … 48 48 const std::vector<int>& gridDestGlobalDim, 49 49 const std::vector<int>& gridSrcGlobalDim, 50 const CArray<size_t,1>& globalIndexGridDestSendToServer,50 const std::vector<size_t>& globalIndexGridDestSendToServer, 51 51 CArray<size_t,1>& globalIndexDestGrid, 52 52 std::vector<std::vector<size_t> >& globalIndexSrcGrid) … … 66 66 } 67 67 68 CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,69 iteArr = globalIndexGridDestSendToServer.end();68 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 69 iteArr = globalIndexGridDestSendToServer.end(); 70 70 71 71 while (idx < ssize) … … 91 91 } 92 92 93 itArr = std::find(itbArr, iteArr, globIndex); 94 if (iteArr != itArr) ++realGlobalIndexSize; 93 if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize; 95 94 ++idxLoop[0]; 96 95 ++idx; … … 130 129 } 131 130 132 itArr = std::find(itbArr, iteArr, globIndex); 133 if (iteArr != itArr) 131 if (std::binary_search(itbArr, iteArr, globIndex)) 134 132 { 135 133 globalIndexDestGrid(realGlobalIndex) = globIndex; -
XIOS/trunk/src/transformation/axis_algorithm_transformation.hpp
r631 r668 32 32 const std::vector<int>& gridDestGlobalDim, 33 33 const std::vector<int>& gridSrcGlobalDim, 34 const CArray<size_t,1>& globalIndexGridDestSendToServer,34 const std::vector<size_t>& globalIndexGridDestSendToServer, 35 35 CArray<size_t,1>& globalIndexDestGrid, 36 36 std::vector<std::vector<size_t> >& globalIndexSrcGrid); -
XIOS/trunk/src/transformation/domain_algorithm_transformation.cpp
r663 r668 32 32 \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed) 33 33 \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed) 34 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s) 34 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted 35 35 \param[in/out] globalIndexDestGrid array of global index (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated 36 36 \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated … … 41 41 const std::vector<int>& gridDestGlobalDim, 42 42 const std::vector<int>& gridSrcGlobalDim, 43 const CArray<size_t,1>& globalIndexGridDestSendToServer,43 const std::vector<size_t>& globalIndexGridDestSendToServer, 44 44 CArray<size_t,1>& globalIndexDestGrid, 45 45 std::vector<std::vector<size_t> >& globalIndexSrcGrid) … … 78 78 for (int i = 0; i< numElement; ++i) ssize *= gridDomainGlobalDim[i]; 79 79 80 CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,81 iteArr = globalIndexGridDestSendToServer.end();80 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 81 iteArr = globalIndexGridDestSendToServer.end(); 82 82 idx = 0; 83 83 while (idx < ssize) … … 111 111 } 112 112 113 itArr = std::find(itbArr, iteArr, globIndex); 114 if (iteArr != itArr) ++realGlobalIndexSize; 113 if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize; 115 114 ++idxLoop[0]; 116 115 ++idx; … … 158 157 } 159 158 160 itArr = std::find(itbArr, iteArr, globIndex); 161 if (iteArr != itArr) 159 if (std::binary_search(itbArr, iteArr, globIndex)) 162 160 { 163 161 globalIndexDestGrid(realGlobalIndex) = globIndex; -
XIOS/trunk/src/transformation/domain_algorithm_transformation.hpp
r631 r668 32 32 const std::vector<int>& gridDestGlobalDim, 33 33 const std::vector<int>& gridSrcGlobalDim, 34 const CArray<size_t,1>& globalIndexGridDestSendToServer,34 const std::vector<size_t>& globalIndexGridDestSendToServer, 35 35 CArray<size_t,1>& globalIndexDestGrid, 36 36 std::vector<std::vector<size_t> >& globalIndexSrcGrid); -
XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp
r657 r668 29 29 const std::vector<int>& gridDestGlobalDim, 30 30 const std::vector<int>& gridSrcGlobalDim, 31 const CArray<size_t,1>& globalIndexGridDestSendToServer,31 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource) 33 33 { … … 40 40 std::vector<std::vector<size_t> > globalIndexSrcGrid; 41 41 CArray<size_t,1> globalIndexDestGrid; 42 42 std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); 43 std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); 43 44 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 44 45 { … … 48 49 gridDestGlobalDim, 49 50 gridSrcGlobalDim, 50 globalIndexGridDestSendToServer,51 vecGlobalIndexGridSendToServer, 51 52 globalIndexDestGrid, 52 53 globalIndexSrcGrid); -
XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp
r631 r668 29 29 const std::vector<int>& gridDestGlobalDim, 30 30 const std::vector<int>& gridSrcGlobalDim, 31 const CArray<size_t,1>& globalIndexGridDestSendToServer,31 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource); 33 33 … … 44 44 \param[in] elementPositionInGrid position of the element in the grid (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) 45 45 \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the element on which transformation is performed) 46 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s) 46 \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted 47 47 \param[in/out] globalIndexDestGrid array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated 48 48 \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated … … 53 53 const std::vector<int>& gridDestGlobalDim, 54 54 const std::vector<int>& gridSrcGlobalDim, 55 const CArray<size_t,1>& globalIndexGridDestSendToServer,55 const std::vector<size_t>& globalIndexGridDestSendToServer, 56 56 CArray<size_t,1>& globalIndexDestGrid, 57 57 std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0; -
XIOS/trunk/src/transformation/grid_transformation.cpp
r660 r668 22 22 CGridTransformation::CGridTransformation(CGrid* destination, CGrid* source) 23 23 : gridSource_(source), gridDestination_(destination), originalGridSource_(source), 24 globalIndexOfCurrentGridSource_( 0), globalIndexOfOriginalGridSource_(0), weightOfGlobalIndexOfOriginalGridSource_(0), algoTypes_()24 globalIndexOfCurrentGridSource_(), globalIndexOfOriginalGridSource_(), weightOfGlobalIndexOfOriginalGridSource_(0), algoTypes_() 25 25 { 26 26 //Verify the compatibity between two grids … … 77 77 78 78 CDistributionClient distribution(client->clientRank, originalGridSource_); 79 const CArray<size_t,1>& globalIndexGridDestSendToServer = distribution.getGlobalDataIndexSendToServer(); 80 81 globalIndexOfCurrentGridSource_.resize(globalIndexGridDestSendToServer.numElements()); 82 globalIndexOfOriginalGridSource_.resize(globalIndexGridDestSendToServer.numElements()); 83 weightOfGlobalIndexOfOriginalGridSource_.resize(globalIndexGridDestSendToServer.numElements()); 79 const std::vector<size_t>& globalIndexGridDestSendToServer = distribution.getGlobalDataIndexSendToServer(); 80 81 weightOfGlobalIndexOfOriginalGridSource_.resize(globalIndexGridDestSendToServer.size()); 84 82 globalIndexOfCurrentGridSource_ = globalIndexGridDestSendToServer; 85 83 globalIndexOfOriginalGridSource_ = globalIndexGridDestSendToServer; … … 362 360 // Recalculate the distribution of grid destination 363 361 CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 364 const CArray<size_t,1>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer();362 const std::vector<size_t>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 365 363 366 364 // ComputeTransformation of global index of each element … … 397 395 //First of all, retrieve info of local mask of grid destination 398 396 CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 399 const CArray<int, 1>& localMaskIndexOnClientDest = distributionClientDest.getLocalMaskIndexOnClient();400 const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer();401 402 CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr;397 const std::vector<int>& localMaskIndexOnClientDest = distributionClientDest.getLocalMaskIndexOnClient(); 398 const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 399 400 std::vector<size_t>::const_iterator itbArr, itArr, iteArr; 403 401 itbArr = globalIndexOnClientDest.begin(); 404 402 iteArr = globalIndexOnClientDest.end(); 405 403 406 404 // Then find out which index became invalid (become masked after being applied the algorithms, or demande some masked points from grid source) 407 int num = globalIndexOfOriginalGridSource_. numElements();405 int num = globalIndexOfOriginalGridSource_.size(); 408 406 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 409 407 int maskIndexNum = 0; 410 408 for (int idx = 0; idx < num; ++idx) 411 409 { 412 if (sfmax == globalIndexOfOriginalGridSource_ (idx))413 { 414 size_t maskedGlobalIndex = globalIndexOfCurrentGridSource_ (idx);410 if (sfmax == globalIndexOfOriginalGridSource_[idx]) 411 { 412 size_t maskedGlobalIndex = globalIndexOfCurrentGridSource_[idx]; 415 413 itArr = std::find(itbArr, iteArr, maskedGlobalIndex); 416 414 if (iteArr != itArr) ++maskIndexNum; … … 422 420 for (int idx = 0; idx < num; ++idx) 423 421 { 424 if (sfmax == globalIndexOfOriginalGridSource_ (idx))425 { 426 size_t maskedGlobalIndex = globalIndexOfCurrentGridSource_ (idx);422 if (sfmax == globalIndexOfOriginalGridSource_[idx]) 423 { 424 size_t maskedGlobalIndex = globalIndexOfCurrentGridSource_[idx]; 427 425 itArr = std::find(itbArr, iteArr, maskedGlobalIndex); 428 426 if (iteArr != itArr) 429 427 { 430 428 int localIdx = std::distance(itbArr, itArr); 431 maskIndexToModify(maskIndexNum) = localMaskIndexOnClientDest (localIdx);429 maskIndexToModify(maskIndexNum) = localMaskIndexOnClientDest[localIdx]; 432 430 ++maskIndexNum; 433 431 } … … 459 457 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend, 460 458 iteSend = globalIndexToSend.end(); 461 CArray<size_t,1>::const_iterator itbArr = globalIndexOfCurrentGridSource_.begin(), itArr,462 iteArr = globalIndexOfCurrentGridSource_.end();459 std::vector<size_t>::const_iterator itbArr = globalIndexOfCurrentGridSource_.begin(), itArr, 460 iteArr = globalIndexOfCurrentGridSource_.end(); 463 461 int sendBuffSize = 0; 464 462 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 471 469 std::map<int, MPI_Request> requests; 472 470 471 std::vector<int> permutIndex(globalIndexOfCurrentGridSource_.size()); 472 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 473 XIOSAlgorithms::fillInIndex(globalIndexOfCurrentGridSource_.size(), permutIndex); 474 XIOSAlgorithms::sortWithIndex<size_t>(globalIndexOfCurrentGridSource_, permutIndex); 475 BinarySearch searchCurrentSrc(globalIndexOfCurrentGridSource_); 476 std::vector<int>::iterator itbIndex = permutIndex.begin(), itIndex, 477 iteIndex = permutIndex.end(); 478 479 // Find out local index on grid destination (received) 473 480 int currentBuffPosition = 0; 474 481 for (itSend = itbSend; itSend != iteSend; ++itSend) … … 479 486 for (int idx = 0; idx < (countSize); ++idx) 480 487 { 481 itArr = std::find(itbArr, iteArr, globalIndexOfCurrentGridSourceToSend[idx]); 482 if (iteArr != itArr) 488 if (searchCurrentSrc.search(itbIndex, iteIndex, globalIndexOfCurrentGridSourceToSend[idx], itIndex)) 483 489 { 484 int index = std::distance(itbArr, itArr);485 sendBuff[idx+currentBuffPosition] = globalIndexOfOriginalGridSource_ (index);490 // int index = std::distance(itbArr, itArr); 491 sendBuff[idx+currentBuffPosition] = globalIndexOfOriginalGridSource_[*itIndex]; //[index]; 486 492 } 487 493 } … … 522 528 } 523 529 524 if (globalIndexOfCurrentGridSource_. numElements() != nbCurrentGridSource)530 if (globalIndexOfCurrentGridSource_.size() != nbCurrentGridSource) 525 531 { 526 532 globalIndexOfCurrentGridSource_.resize(nbCurrentGridSource); … … 539 545 for (int i = 0; i < ssize; ++i) 540 546 { 541 globalIndexOfCurrentGridSource_ (k)= ((itRecv->second)[idx][i]).first;547 globalIndexOfCurrentGridSource_[k] = ((itRecv->second)[idx][i]).first; 542 548 weightOfGlobalIndexOfOriginalGridSource_(k) = ((itRecv->second)[idx][i]).second; 543 globalIndexOfOriginalGridSource_ (k)= *currentRecvBuff;549 globalIndexOfOriginalGridSource_[k] = *currentRecvBuff; 544 550 ++k; 545 551 } … … 568 574 569 575 std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 570 int nb = globalIndexOfCurrentGridSource_. numElements();576 int nb = globalIndexOfCurrentGridSource_.size(); 571 577 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 572 578 for (int idx = 0; idx < nb; ++idx) 573 579 { 574 if (sfmax != globalIndexOfOriginalGridSource_ (idx))575 globaIndexWeightFromDestToSource[globalIndexOfCurrentGridSource_ (idx)].push_back(make_pair(globalIndexOfOriginalGridSource_(idx), weightOfGlobalIndexOfOriginalGridSource_(idx))) ;580 if (sfmax != globalIndexOfOriginalGridSource_[idx]) 581 globaIndexWeightFromDestToSource[globalIndexOfCurrentGridSource_[idx]].push_back(make_pair(globalIndexOfOriginalGridSource_[idx], weightOfGlobalIndexOfOriginalGridSource_(idx))) ; 576 582 } 577 583 … … 585 591 CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 586 592 587 const CArray<int, 1>& localIndexOnClientDest = distributionClientDest.getLocalDataIndexSendToServer(); 588 const CArray<size_t,1>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 589 590 const CArray<int, 1>& localIndexOnClientSrc = distributionClientSrc.getLocalDataIndexOnClient(); 591 const CArray<size_t,1>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 592 593 std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 594 CArray<size_t, 1>::const_iterator itbArr, itArr, iteArr; 595 593 const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 594 const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 595 596 std::vector<size_t>::const_iterator itbArr, itArr, iteArr; 597 std::vector<int>::const_iterator itIndex, itbIndex, iteIndex; 596 598 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 597 599 600 std::vector<int> permutIndex; 601 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 602 598 603 // Find out local index on grid destination (received) 604 XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex); 605 XIOSAlgorithms::sortWithIndex<size_t>(globalIndexOnClientDest, permutIndex); 606 itbIndex = permutIndex.begin(); 607 iteIndex = permutIndex.end(); 608 BinarySearch searchClientDest(globalIndexOnClientDest); 599 609 itbMapRecv = globalIndexToReceive.begin(); 600 610 iteMapRecv = globalIndexToReceive.end(); 601 itbArr = globalIndexOnClientDest.begin();602 iteArr = globalIndexOnClientDest.end();603 611 for (itMapRecv = itbMapRecv; itMapRecv != iteMapRecv; ++itMapRecv) 604 612 { … … 613 621 size_t globalIndex = (itMapRecv->second)[i][idx].first; 614 622 double weight = (itMapRecv->second)[i][idx].second; 615 itArr = std::find(itbArr, iteArr, globalIndex); 616 if (iteArr != itArr) 623 if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 617 624 { 618 int localIdx = std::distance(itbArr, itArr); 619 tmpVec.push_back(make_pair(localIdx, weight)); 625 tmpVec.push_back(make_pair(*itIndex, weight)); 620 626 } 621 627 } … … 626 632 // Find out local index on grid source (to send) 627 633 std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap; 634 XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex); 635 XIOSAlgorithms::sortWithIndex<size_t>(globalIndexOnClientSrc, permutIndex); 636 itbIndex = permutIndex.begin(); 637 iteIndex = permutIndex.end(); 638 BinarySearch searchClientSrc(globalIndexOnClientSrc); 628 639 itbMap = globalIndexToSend.begin(); 629 640 iteMap = globalIndexToSend.end(); 630 itbArr = globalIndexOnClientSrc.begin();631 iteArr = globalIndexOnClientSrc.end();632 641 for (itMap = itbMap; itMap != iteMap; ++itMap) 633 642 { … … 637 646 for (int idx = 0; idx < vecSize; ++idx) 638 647 { 639 itArr = std::find(itbArr, iteArr, itMap->second[idx]); 640 if (iteArr != itArr) 648 if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex)) 641 649 { 642 int localIdx = std::distance(itbArr, itArr); 643 localIndexToSendFromGridSource_[destRank](idx) = localIdx; 650 localIndexToSendFromGridSource_[destRank](idx) = *itIndex; 644 651 } 645 652 } -
XIOS/trunk/src/transformation/grid_transformation.hpp
r653 r668 99 99 100 100 //! (Grid) Global index of grid source 101 CArray<size_t,1> globalIndexOfCurrentGridSource_;102 CArray<size_t,1> globalIndexOfOriginalGridSource_;101 std::vector<size_t> globalIndexOfCurrentGridSource_; 102 std::vector<size_t> globalIndexOfOriginalGridSource_; 103 103 CArray<double,1> weightOfGlobalIndexOfOriginalGridSource_; 104 104 }; -
XIOS/trunk/src/transformation/transformation_mapping.cpp
r666 r668 25 25 CDistributionClient distributionClientSrc(client->clientRank, gridSource_); 26 26 27 const CArray<size_t,1>& globalIndexGridSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer();27 const std::vector<size_t>& globalIndexGridSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 28 28 boost::unordered_map<size_t,int> globalIndexOfServer; 29 int globalIndexSize = globalIndexGridSrc. numElements();29 int globalIndexSize = globalIndexGridSrc.size(); 30 30 for (int idx = 0; idx < globalIndexSize; ++idx) 31 31 { 32 globalIndexOfServer[globalIndexGridSrc (idx)] = clientRank;32 globalIndexOfServer[globalIndexGridSrc[idx]] = clientRank; 33 33 } 34 34 -
XIOS/trunk/src/utils.hpp
r630 r668 222 222 }; 223 223 224 template<class T> 225 class sorter 226 { 227 const std::vector<T>& values; 228 public: 229 sorter(const std::vector<T> &v) : values(v) {} 230 bool operator()(int a, int b) { return values[a] < values[b]; } 231 }; 232 233 template<class T> 234 void order(const std::vector<T>& values, std::vector<int>& rv) 235 { 236 std::sort(rv.begin(), rv.end(), sorter<T>(values)); 224 template<typename T> 225 class CArrayStorage 226 { 227 public: 228 typedef CArray<T,1> StorageType; 229 230 public: 231 CArrayStorage(const CArray<T,1>& arr) : values(arr) {} 232 233 protected: 234 const T& atIndex(int idx) const { return values(idx); } 235 const StorageType& values; 236 }; 237 238 template<typename T> 239 class CVectorStorage 240 { 241 public: 242 typedef std::vector<T> StorageType; 243 244 public: 245 CVectorStorage(const std::vector<T>& vec) : values(vec) {} 246 247 protected: 248 const T& atIndex(int idx) const { return values[idx]; } 249 const StorageType& values; 250 }; 251 252 253 template< 254 typename T, 255 template <class> class StoragePolicy = CVectorStorage 256 > 257 class XIOSComparatorWithIndex : 258 public StoragePolicy<T> 259 { 260 public: 261 typedef typename StoragePolicy<T>::StorageType StorageType; 262 263 public: 264 XIOSComparatorWithIndex(const StorageType& v) : StoragePolicy<T>(v) {} 265 bool operator()(int a, int b) { return this->atIndex(a) < this->atIndex(b); } 266 }; 267 268 template< 269 typename T, 270 template <class> class StoragePolicy = CVectorStorage 271 > 272 class XIOSLowerBoundWithIndex : 273 public StoragePolicy<T> 274 { 275 public: 276 typedef typename StoragePolicy<T>::StorageType StorageType; 277 278 public: 279 XIOSLowerBoundWithIndex(const StorageType &v) : StoragePolicy<T>(v) {} 280 bool operator()(const int a, const T& b) { return this->atIndex(a) < b; } 281 }; 282 283 template< 284 typename T, 285 template <class> class StoragePolicy = CVectorStorage 286 > 287 class XIOSBinarySearchWithIndex : 288 public StoragePolicy<T> 289 { 290 public: 291 typedef typename StoragePolicy<T>::StorageType StorageType; 292 293 public: 294 XIOSBinarySearchWithIndex(const StorageType& v) : StoragePolicy<T>(v) {} 295 296 template<typename ForwardIterator> 297 bool search(ForwardIterator first, ForwardIterator last, const T& val, ForwardIterator& position) 298 { 299 first = std::lower_bound(first, last, val, XIOSLowerBoundWithIndex<T, StoragePolicy>(this->values)); 300 position = first; 301 return (first!=last && !(val<this->atIndex(*first))); 302 } 303 }; 304 305 306 struct XIOSAlgorithms 307 { 308 public: 309 template<typename T, template <class> class StoragePolicy = CVectorStorage> 310 static void sortWithIndex(const typename StoragePolicy<T>::StorageType& values, std::vector<int>& rv) 311 { 312 std::sort(rv.begin(), rv.end(), XIOSComparatorWithIndex<T, StoragePolicy>(values)); 313 } 314 315 //! Fill in an vector with index begin at 0 316 static void fillInIndex(int nbIndex, std::vector<int>& rvIndex) 317 { 318 if ((0 < nbIndex) && (nbIndex != rvIndex.size())) rvIndex.resize(nbIndex); 319 for (int idx = 0; idx < nbIndex; ++idx) rvIndex[idx] = idx; 320 } 321 }; 322 237 323 } 238 324 239 }240 241 325 #endif // __UTILS_HPP__
Note: See TracChangeset
for help on using the changeset viewer.