From 96bd677b465621956deabb8f5a8da29e5139f2aa Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Sat, 18 Apr 2020 08:01:47 +0200 Subject: [PATCH] WIP --- src/MEDCoupling/MCAuto.hxx | 1 + src/MEDCoupling/MEDCouplingSkyLineArray.hxx | 23 +++++++++++++++ src/ParaMEDMEM/ParaSkyLineArray.cxx | 31 +++++++++++++++++++-- src/ParaMEDMEM/ParaUMesh.cxx | 1 - 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index d1a8a2892..1d47b7f67 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -31,6 +31,7 @@ namespace MEDCoupling class MCAuto { public: + static MCAuto TakeRef(T *ptr) { MCAuto ret(MCAuto(nullptr)); ret.takeRef(ptr); return ret; } MCAuto(const MCAuto& other):_ptr(0) { referPtr(other._ptr); } MCAuto(T *ptr=0):_ptr(ptr) { } ~MCAuto() { destroyPtr(); } diff --git a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx index 356e28a8e..f7280c1be 100644 --- a/src/MEDCoupling/MEDCouplingSkyLineArray.hxx +++ b/src/MEDCoupling/MEDCouplingSkyLineArray.hxx @@ -26,6 +26,7 @@ #include "NormalizedGeometricTypes" #include +#include namespace MEDCoupling { @@ -63,6 +64,28 @@ namespace MEDCoupling static MEDCouplingSkyLineArray * New( const MEDCouplingSkyLineArray & other ); static MEDCouplingSkyLineArray * BuildFromPolyhedronConn( const DataArrayIdType* c, const DataArrayIdType* cI ); + + static std::vector< MCAuto > RetrieveVecIndex(const std::vector< MCAuto >& vecSka) + { + auto fct = [](MEDCouplingSkyLineArray *ska) { return ska->getIndexArray(); }; + return RetrieveVecOfSkyLineArrayGen(vecSka,fct); + } + + static std::vector< MCAuto > RetrieveVecValues(const std::vector< MCAuto >& vecSka) + { + auto fct = [](MEDCouplingSkyLineArray *ska) { return ska->getValuesArray(); }; + return RetrieveVecOfSkyLineArrayGen(vecSka,fct); + } + + static std::vector< MCAuto > RetrieveVecOfSkyLineArrayGen(const std::vector< MCAuto >& vecSka, std::function fct) + { + std::size_t sz(vecSka.size()); + std::vector< MCAuto > ret(sz); + std::vector< MCAuto >::iterator it(ret.begin()); + std::for_each(vecSka.begin(),vecSka.end(),[&it,fct](MCAuto elt) { *it++ = MCAuto::TakeRef(fct(elt)); } ); + return ret; + } + std::string getClassName() const override { return std::string("MEDCouplingSkyLineArray"); } std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; diff --git a/src/ParaMEDMEM/ParaSkyLineArray.cxx b/src/ParaMEDMEM/ParaSkyLineArray.cxx index 5672037f0..fc88c3807 100644 --- a/src/ParaMEDMEM/ParaSkyLineArray.cxx +++ b/src/ParaMEDMEM/ParaSkyLineArray.cxx @@ -35,7 +35,6 @@ #include #include -using namespace std; using namespace MEDCoupling; ParaSkyLineArray::ParaSkyLineArray(MEDCouplingSkyLineArray *ska, DataArrayIdType *globalIds) @@ -60,5 +59,33 @@ std::vector ParaSkyLineArray::getDirectChildrenWithNull MCAuto ParaSkyLineArray::equiRedistribute(mcIdType nbOfEntities) const { - //TODO + MPI_Comm comm(MPI_COMM_WORLD); + CommInterface ci; + int size; + ci.commSize(comm,&size); + std::vector< MCAuto > skToBeSent(size); + std::vector< MCAuto > idsCaptured(size); + for(int curRk = 0 ; curRk < size ; ++curRk) + { + mcIdType curStart(0),curEnd(0); + DataArrayIdType::GetSlice(0,nbOfEntities,1,curRk,size,curStart,curEnd); + idsCaptured[curRk] = _global_ids->findIdsInRange(curStart,curEnd); + { + DataArrayIdType *tmpValues(nullptr),*tmpIndex(nullptr); + DataArrayIdType::ExtractFromIndexedArrays(idsCaptured[curRk]->begin(),idsCaptured[curRk]->end(),this->_ska->getValuesArray(),this->_ska->getIndexArray(),tmpValues,tmpIndex); + skToBeSent[curRk] = MEDCouplingSkyLineArray::New(tmpIndex,tmpValues); + } + } + // communication : 3 arrays are going to be all2allized : ids, SkyLine index and SyLine values + std::vector< MCAuto > myRkIdsCaptured, myRkSkIndex, myRkSkValues; + ci.allToAllArrays(comm,idsCaptured,myRkIdsCaptured); + { + std::vector< MCAuto > indexToBeSent(MEDCouplingSkyLineArray::RetrieveVecIndex(skToBeSent)); + ci.allToAllArrays(comm,indexToBeSent,myRkSkIndex); + } + { + std::vector< MCAuto > valuesToBeSent(MEDCouplingSkyLineArray::RetrieveVecValues(skToBeSent)); + ci.allToAllArrays(comm,valuesToBeSent,myRkSkValues); + } + // assemble the 3 arrays myRkIdsCaptured, myRkSkIndex, myRkSkValues } \ No newline at end of file diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index 5a44f74b4..812a7e4d8 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -35,7 +35,6 @@ #include #include -using namespace std; using namespace MEDCoupling; ParaUMesh::ParaUMesh(MEDCouplingUMesh *mesh, DataArrayIdType *globalCellIds, DataArrayIdType *globalNodeIds) -- 2.39.2