From: Anthony Geay Date: Sun, 26 Apr 2020 22:28:57 +0000 (+0200) Subject: Some cleanup X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fagy%2Fpara_mesh_opt_2;p=tools%2Fmedcoupling.git Some cleanup --- diff --git a/src/ParaMEDMEM/CommInterface.cxx b/src/ParaMEDMEM/CommInterface.cxx index 725b76fb1..6fda70ddd 100644 --- a/src/ParaMEDMEM/CommInterface.cxx +++ b/src/ParaMEDMEM/CommInterface.cxx @@ -105,6 +105,13 @@ namespace MEDCoupling this->allToAllArraysT(comm,arrays,arraysOut); } + void CommInterface::allToAllArrays(MPI_Comm comm, const std::vector< MCAuto >& arrays, MCAuto& arraysOut) const + { + std::unique_ptr notUsed1; + mcIdType notUsed2; + this->allToAllArraysT2(comm,arrays,arraysOut,notUsed1,notUsed2); + } + /*! * Generalized AllToAll collective communication. */ @@ -112,4 +119,5 @@ namespace MEDCoupling { this->allToAllArraysT(comm,arrays,arraysOut); } + } diff --git a/src/ParaMEDMEM/CommInterface.hxx b/src/ParaMEDMEM/CommInterface.hxx index d795185cc..e969f9394 100644 --- a/src/ParaMEDMEM/CommInterface.hxx +++ b/src/ParaMEDMEM/CommInterface.hxx @@ -122,8 +122,9 @@ namespace MEDCoupling int allGatherArrays(MPI_Comm comm, const DataArrayIdType *array, std::unique_ptr& result, std::unique_ptr& resultIndex) const; void allToAllArrays(MPI_Comm comm, const std::vector< MCAuto >& arrays, std::vector< MCAuto >& arraysOut) const; void allToAllArrays(MPI_Comm comm, const std::vector< MCAuto >& arrays, std::vector< MCAuto >& arraysOut) const; + void allToAllArrays(MPI_Comm comm, const std::vector< MCAuto >& arrays, MCAuto& arraysOut) const; template - void allToAllArraysT(MPI_Comm comm, const std::vector< MCAuto::ArrayType> >& arrays, std::vector< MCAuto::ArrayType> >& arraysOut) const + int allToAllArraysT2(MPI_Comm comm, const std::vector< MCAuto::ArrayType> >& arrays, MCAuto::ArrayType>& arrayOut, std::unique_ptr& nbOfElems2, mcIdType& nbOfComponents) const { using DataArrayT = typename Traits::ArrayType; int size; @@ -132,8 +133,9 @@ namespace MEDCoupling throw INTERP_KERNEL::Exception("AllToAllArrays : internal error ! Invalid size of input array."); std::vector< const DataArrayT *> arraysBis(FromVecAutoToVecOfConst(arrays)); - std::unique_ptr nbOfElems2(new mcIdType[size]),nbOfElems3(new mcIdType[size]); - mcIdType nbOfComponents(std::numeric_limits::max()); + std::unique_ptr nbOfElems3(new mcIdType[size]); + nbOfElems2.reset(new mcIdType[size]); + nbOfComponents = std::numeric_limits::max(); for(int curRk = 0 ; curRk < size ; ++curRk) { mcIdType curNbOfCompo( ToIdType( arrays[curRk]->getNumberOfComponents() ) ); @@ -150,15 +152,26 @@ namespace MEDCoupling } this->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(DataArrayT::New()); - cellIdsFromProcs->alloc(nbOfCellIdsSum/nbOfComponents,nbOfComponents); + arrayOut = DataArrayT::New(); + arrayOut->alloc(nbOfCellIdsSum/nbOfComponents,nbOfComponents); 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) ); { MCAuto arraysAcc(DataArrayT::Aggregate(arraysBis)); this->allToAllV(arraysAcc->begin(),nbOfElemsInt.get(),offsetsIn.get(),ParaTraits::MPIDataType, - cellIdsFromProcs->getPointer(),nbOfElemsOutInt.get(),offsetsOut.get(),ParaTraits::MPIDataType,comm); + arrayOut->getPointer(),nbOfElemsOutInt.get(),offsetsOut.get(),ParaTraits::MPIDataType,comm); } + return size; + } + + template + void allToAllArraysT(MPI_Comm comm, const std::vector< MCAuto::ArrayType> >& arrays, std::vector< MCAuto::ArrayType> >& arraysOut) const + { + using DataArrayT = typename Traits::ArrayType; + MCAuto cellIdsFromProcs; + std::unique_ptr nbOfElems2; + mcIdType nbOfComponents(0); + int size(this->allToAllArraysT2(comm,arrays,cellIdsFromProcs,nbOfElems2,nbOfComponents)); std::unique_ptr offsetsOutIdType( CommInterface::ComputeOffset(nbOfElems2,size) ); // build output arraysOut by spliting cellIdsFromProcs into parts arraysOut.resize(size); diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index 0ceb35565..60d44a323 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -132,30 +132,22 @@ MCAuto ParaUMesh::getCellIdsLyingOnNodes(const DataArrayIdType } /*! + * Return part of \a this mesh split over COMM_WORLD. Part is defined by global cell ids array \a globaCellIds. */ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const { MPI_Comm comm(MPI_COMM_WORLD); CommInterface ci; - int size; - ci.commSize(comm,&size); - std::unique_ptr nbOfElems(new mcIdType[size]); - mcIdType nbOfCellsRequested(globalCellIds->getNumberOfTuples()); - ci.allGather(&nbOfCellsRequested,1,MPI_ID_TYPE,nbOfElems.get(),1,MPI_ID_TYPE,comm); - mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems.get(),nbOfElems.get()+size,0)); - std::unique_ptr allGlobalCellIds(new mcIdType[nbOfCellIdsSum]); - std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems,size) ); - std::unique_ptr offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ); - ci.allGatherV(globalCellIds->begin(),nbOfCellsRequested,MPI_ID_TYPE,allGlobalCellIds.get(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE,comm); - mcIdType offset(0); + std::unique_ptr allGlobalCellIds,allGlobalCellIdsIndex; + int size(ci.allGatherArrays(comm,globalCellIds,allGlobalCellIds,allGlobalCellIdsIndex)); // Prepare ParaUMesh parts to be sent : compute for each proc the contribution of current rank. std::vector< MCAuto > globalCellIdsToBeSent(size),globalNodeIdsToBeSent(size); std::vector< MCAuto > meshPartsToBeSent(size); for(int curRk = 0 ; curRk < size ; ++curRk) { + mcIdType offset(allGlobalCellIdsIndex[curRk]); MCAuto globalCellIdsOfCurProc(DataArrayIdType::New()); - globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,nbOfElems[curRk],1); - offset += nbOfElems[curRk]; + globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,allGlobalCellIdsIndex[curRk+1]-offset,1); // the key call is here : compute for rank curRk the cells to be sent MCAuto globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds MCAuto localCellIdsCaptured(_cell_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end())); @@ -185,14 +177,13 @@ ParaUMesh *ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) co ci.allToAllArrays(comm,FromVecConstToVecAuto(connectivityToBeSent),connectivityReceived); } //coordinates - std::vector< MCAuto > coordsReceived; + MCAuto coords; { std::vector coordsToBeSent(UMeshCoordsIterator(0,&meshPartsToBeSent2),UMeshCoordsIterator(meshPartsToBeSent2.size(),&meshPartsToBeSent2)); - ci.allToAllArrays(comm,FromVecConstToVecAuto(coordsToBeSent),coordsReceived); + ci.allToAllArrays(comm,FromVecConstToVecAuto(coordsToBeSent),coords); } /////// Sort it all ! // firstly deal with nodes. - MCAuto coords( DataArrayDouble::Aggregate(FromVecAutoToVecOfConst(coordsReceived)) ); MCAuto aggregatedNodeIds( DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(globalNodeIdsReceived)) ); MCAuto aggregatedNodeIdsSorted(aggregatedNodeIds->copySorted()); MCAuto nodeIdsIntoAggregatedIds(DataArrayIdType::FindPermutationFromFirstToSecondDuplicate(aggregatedNodeIdsSorted,aggregatedNodeIds));