From d826ff846ed8d5bdffcc824303e498c0b8266257 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Tue, 10 Mar 2020 22:36:24 +0100 Subject: [PATCH] With memory optimization --- src/ParaMEDMEM/ParaUMesh.cxx | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index fed10a5f8..ad6803606 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -65,41 +65,53 @@ MCAuto ParaUMesh::getCellIdsLyingOnNodes(DataArrayIdType *globa CommInterface ci; int size; ci.commSize(comm,&size); - std::unique_ptr nbOfElems(new mcIdType[size]),nbOfElems2(new mcIdType[size]); + std::unique_ptr nbOfElems(new mcIdType[size]),nbOfElems2(new mcIdType[size]),nbOfElems3(new mcIdType[size]); mcIdType nbOfNodeIdsLoc(globalNodeIds->getNumberOfTuples()); ci.allGather(&nbOfNodeIdsLoc,1,MPI_ID_TYPE,nbOfElems.get(),1,MPI_ID_TYPE,comm); - mcIdType nbOfNodeIdsSum(std::accumulate(nbOfElems.get(),nbOfElems.get()+size,0)); std::vector< MCAuto > tabs(size); + // loop to avoid to all procs to have all the nodes per proc + for(int subDiv = 0 ; subDiv < size ; ++subDiv) { + std::unique_ptr nbOfElemsSp(CommInterface::SplitArrayOfLength(nbOfElems,size,subDiv,size)); + mcIdType nbOfNodeIdsSum(std::accumulate(nbOfElemsSp.get(),nbOfElemsSp.get()+size,0)); std::unique_ptr allGlobalNodeIds(new mcIdType[nbOfNodeIdsSum]); - std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems,size) ); + std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElemsSp,size) ); std::unique_ptr offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ); - ci.allGatherV(globalNodeIds->begin(),globalNodeIds->getNumberOfTuples(),MPI_ID_TYPE,allGlobalNodeIds.get(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE,comm); + mcIdType startGlobalNodeIds,endGlobalNodeIds; + DataArray::GetSlice(0,globalNodeIds->getNumberOfTuples(),1,subDiv,size,startGlobalNodeIds,endGlobalNodeIds); + ci.allGatherV(globalNodeIds->begin()+startGlobalNodeIds,endGlobalNodeIds-startGlobalNodeIds,MPI_ID_TYPE,allGlobalNodeIds.get(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE,comm); mcIdType offset(0); for(int curRk = 0 ; curRk < size ; ++curRk) { MCAuto globalNodeIdsOfCurProc(DataArrayIdType::New()); - globalNodeIdsOfCurProc->useArray(allGlobalNodeIds.get()+offset,false,DeallocType::CPP_DEALLOC,nbOfElems[curRk],1); - offset += nbOfElems[curRk]; + globalNodeIdsOfCurProc->useArray(allGlobalNodeIds.get()+offset,false,DeallocType::CPP_DEALLOC,nbOfElemsSp[curRk],1); + offset += nbOfElemsSp[curRk]; MCAuto globalNodeIdsCaptured(_node_global->buildIntersection(globalNodeIdsOfCurProc)); MCAuto localNodeIdsToLocate(_node_global->findIdForEach(globalNodeIdsCaptured->begin(),globalNodeIdsCaptured->end())); MCAuto localCellCaptured(_mesh->getCellIdsLyingOnNodes(localNodeIdsToLocate->begin(),localNodeIdsToLocate->end(),false)); MCAuto localCellCapturedGlob(_cell_global->selectByTupleIdSafe(localCellCaptured->begin(),localCellCaptured->end())); - nbOfElems[curRk] = localCellCapturedGlob->getNumberOfTuples(); - tabs[curRk] = localCellCapturedGlob; + if(tabs[curRk].isNull()) + tabs[curRk] = localCellCapturedGlob; + else + tabs[curRk]->insertAtTheEnd(localCellCapturedGlob->begin(),localCellCapturedGlob->end()); } } + for(int curRk = 0 ; curRk < size ; ++curRk) + { + tabs[curRk] = tabs[curRk]->buildUniqueNotSorted(); + nbOfElems3[curRk] = tabs[curRk]->getNumberOfTuples(); + } std::vector tabss(tabs.begin(),tabs.end()); MCAuto cells(DataArrayIdType::Aggregate(tabss)); - ci.allToAll(nbOfElems.get(),1,MPI_ID_TYPE,nbOfElems2.get(),1,MPI_ID_TYPE,comm); + ci.allToAll(nbOfElems3.get(),1,MPI_ID_TYPE,nbOfElems2.get(),1,MPI_ID_TYPE,comm); mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems2.get(),nbOfElems2.get()+size,0)); MCAuto cellIdsFromProcs(DataArrayIdType::New()); cellIdsFromProcs->alloc(nbOfCellIdsSum,1); { - std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems,size) ),nbOfElemsOutInt( CommInterface::ToIntArray(nbOfElems2,size) ); + std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems3,size) ),nbOfElemsOutInt( CommInterface::ToIntArray(nbOfElems2,size) ); std::unique_ptr offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ), offsetsOut( CommInterface::ComputeOffset(nbOfElemsOutInt,size) ); ci.allToAllV(cells->begin(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE, - cellIdsFromProcs->getPointer(),nbOfElemsOutInt.get(),offsetsOut.get(),MPI_ID_TYPE,comm); + cellIdsFromProcs->getPointer(),nbOfElemsOutInt.get(),offsetsOut.get(),MPI_ID_TYPE,comm); } cellIdsFromProcs->sort(); return cellIdsFromProcs; -- 2.39.2