From: Anthony Geay Date: Wed, 11 Mar 2020 21:54:15 +0000 (+0100) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d3ca57ac5630f4db04e97c973afa175b4aa4e25e;p=tools%2Fmedcoupling.git WIP --- diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index ad6803606..0b939fd17 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -57,7 +57,7 @@ ParaUMesh::ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, Dat * This method computes the cells part of distributed mesh lying on \a globalNodeIds nodes. * The input \a globalNodeIds are not supposed to reside on the current process. */ -MCAuto ParaUMesh::getCellIdsLyingOnNodes(DataArrayIdType *globalNodeIds, bool fullyIn) const +MCAuto ParaUMesh::getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const { if(fullyIn) throw INTERP_KERNEL::Exception("ParaUMesh::getCellIdsLyingOnNodes : not implemented yet for fullyIn == True !"); @@ -116,3 +116,36 @@ MCAuto ParaUMesh::getCellIdsLyingOnNodes(DataArrayIdType *globa cellIdsFromProcs->sort(); return cellIdsFromProcs; } + +/*! + */ +MCAuto 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]),nbOfElems2(new mcIdType[size]); + mcIdType nbOfNodeIdsLoc(globalCellIds->getNumberOfTuples()); + ci.allGather(&nbOfNodeIdsLoc,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(),nbOfNodeIdsLoc,MPI_ID_TYPE,allGlobalCellIds.get(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE,comm); + mcIdType offset(0); + for(int curRk = 0 ; curRk < size ; ++curRk) + { + MCAuto globalCellIdsOfCurProc(DataArrayIdType::New()); + globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,nbOfElems[curRk],1); + offset += nbOfElems[curRk]; + // prepare all2all session + MCAuto globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds + MCAuto localCellIdsCaptured(_node_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end())); + MCAuto meshPart(_mesh->buildPartOfMySelf(localCellIdsCaptured->begin(),localCellIdsCaptured->end(),true)); + MCAuto o2n(meshPart->zipCoordsTraducer());// OK for the mesh + MCAuto n2o(o2n->invertArrayO2N2N2O(meshPart->getNumberOfNodes())); + MCAuto globalNodeIdsPart(_node_global->selectByTupleIdSafe(n2o->begin(),n2o->end())); // OK for the global nodeIds + } + +} diff --git a/src/ParaMEDMEM/ParaUMesh.hxx b/src/ParaMEDMEM/ParaUMesh.hxx index d9b0993ed..3d0bff392 100644 --- a/src/ParaMEDMEM/ParaUMesh.hxx +++ b/src/ParaMEDMEM/ParaUMesh.hxx @@ -38,7 +38,8 @@ namespace MEDCoupling { public: ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); - MCAuto getCellIdsLyingOnNodes(DataArrayIdType *globalNodeIds, bool fullyIn) const; + MCAuto getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const; + MCAuto redistributeCells(const DataArrayIdType *globalCellIds) const; virtual ~ParaUMesh() { } private: MCAuto _mesh; diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index fd986e0b8..054d680b9 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -129,7 +129,7 @@ namespace MEDCoupling ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds); %extend { - DataArrayIdType *getCellIdsLyingOnNodes(DataArrayIdType *globalNodeIds, bool fullyIn) const + DataArrayIdType *getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const { MCAuto ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn)); return ret.retn();