]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
WIP agy/paraspliter
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 11 Mar 2020 21:54:15 +0000 (22:54 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 11 Mar 2020 21:54:15 +0000 (22:54 +0100)
src/ParaMEDMEM/ParaUMesh.cxx
src/ParaMEDMEM/ParaUMesh.hxx
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i

index ad6803606f2c3748203a87168ee9f2ef04aca501..0b939fd17ad1266cdb80d74e4814b0255fe23c36 100644 (file)
@@ -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<DataArrayIdType> ParaUMesh::getCellIdsLyingOnNodes(DataArrayIdType *globalNodeIds, bool fullyIn) const
+MCAuto<DataArrayIdType> 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<DataArrayIdType> ParaUMesh::getCellIdsLyingOnNodes(DataArrayIdType *globa
   cellIdsFromProcs->sort();
   return cellIdsFromProcs;
 }
+
+/*!
+ */
+MCAuto<ParaUMesh> ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const
+{
+  MPI_Comm comm(MPI_COMM_WORLD);
+  CommInterface ci;
+  int size;
+  ci.commSize(comm,&size);
+  std::unique_ptr<mcIdType[]> 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<mcIdType[]> allGlobalCellIds(new mcIdType[nbOfCellIdsSum]);
+  std::unique_ptr<int[]> nbOfElemsInt( CommInterface::ToIntArray<mcIdType>(nbOfElems,size) );
+  std::unique_ptr<int[]> 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<DataArrayIdType> globalCellIdsOfCurProc(DataArrayIdType::New());
+    globalCellIdsOfCurProc->useArray(allGlobalCellIds.get()+offset,false,DeallocType::CPP_DEALLOC,nbOfElems[curRk],1);
+    offset += nbOfElems[curRk];
+    // prepare all2all session
+    MCAuto<DataArrayIdType> globalCellIdsCaptured(_cell_global->buildIntersection(globalCellIdsOfCurProc));// OK for the global cellIds
+    MCAuto<DataArrayIdType> localCellIdsCaptured(_node_global->findIdForEach(globalCellIdsCaptured->begin(),globalCellIdsCaptured->end()));
+    MCAuto<MEDCouplingUMesh> meshPart(_mesh->buildPartOfMySelf(localCellIdsCaptured->begin(),localCellIdsCaptured->end(),true));
+    MCAuto<DataArrayIdType> o2n(meshPart->zipCoordsTraducer());// OK for the mesh
+    MCAuto<DataArrayIdType> n2o(o2n->invertArrayO2N2N2O(meshPart->getNumberOfNodes()));
+    MCAuto<DataArrayIdType> globalNodeIdsPart(_node_global->selectByTupleIdSafe(n2o->begin(),n2o->end())); // OK for the global nodeIds
+  }
+  
+}
index d9b0993ed66edd89ae37dd02d37eef1f165d98c3..3d0bff3920bed5a7f2471bf37dafd35af1c0ad6c 100644 (file)
@@ -38,7 +38,8 @@ namespace MEDCoupling
   {
   public:
     ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds);
-    MCAuto<DataArrayIdType> getCellIdsLyingOnNodes(DataArrayIdType *globalNodeIds, bool fullyIn) const;
+    MCAuto<DataArrayIdType> getCellIdsLyingOnNodes(const DataArrayIdType *globalNodeIds, bool fullyIn) const;
+    MCAuto<ParaUMesh> redistributeCells(const DataArrayIdType *globalCellIds) const;
     virtual ~ParaUMesh() { }
   private:
     MCAuto<MEDCouplingUMesh> _mesh;
index fd986e0b8a673ada704a9a3b12d9e097581c1881..054d680b936fca4f2022b4cbd6cb2f9464b4e60e 100644 (file)
@@ -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<DataArrayIdType> ret(self->getCellIdsLyingOnNodes(globalNodeIds,fullyIn));
         return ret.retn();