From: Anthony Geay Date: Wed, 29 Apr 2020 21:05:04 +0000 (+0200) Subject: ParaDataArray is on X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=54634d601af7bb51c66257d2cea418783520d458;p=tools%2Fmedcoupling.git ParaDataArray is on --- diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index 70aefc7a5..25148688f 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -593,7 +593,7 @@ namespace MEDCoupling std::ostringstream oss; oss << "DataArray::GetSlice : sliceId (" << nbOfSlices << ") must be in [0 , nbOfSlices (" << nbOfSlices << ") ) !"; throw INTERP_KERNEL::Exception(oss.str().c_str()); } - mcIdType nbElems=DataArrayTemplate::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice"); + mcIdType nbElems=DataArrayTools::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice"); mcIdType minNbOfElemsPerSlice=nbElems/nbOfSlices; startSlice=start+minNbOfElemsPerSlice*step*sliceId; if(sliceIdcommRank(comm,&rank); std::unique_ptr nbOfElems; - if(rank==0) + if(rank==root) nbOfElems.reset(new mcIdType[size]); mcIdType nbOfCellsRequested(array->getNumberOfTuples()); this->gather(&nbOfCellsRequested,1,MPI_ID_TYPE,nbOfElems.get(),1,MPI_ID_TYPE,root,comm); - mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems.get(),nbOfElems.get()+size,0)); - if(rank==0) - result.reset(new T[nbOfCellIdsSum]); std::unique_ptr nbOfElemsInt,offsetsIn; - if(rank==0) + if(rank==root) { + mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems.get(),nbOfElems.get()+size,0)); + result.reset(new T[nbOfCellIdsSum]); nbOfElemsInt = CommInterface::ToIntArray(nbOfElems,size); offsetsIn = CommInterface::ComputeOffset(nbOfElemsInt,size); } this->gatherV(array->begin(),nbOfCellsRequested,ParaTraits::MPIDataType,result.get(),nbOfElemsInt.get(),offsetsIn.get(),ParaTraits::MPIDataType,root,comm); - resultIndex = ComputeOffsetFull(nbOfElems,size); + if(rank==root) + { + resultIndex = ComputeOffsetFull(nbOfElems,size); + } return size; } @@ -166,7 +168,7 @@ namespace MEDCoupling for(int i = 0 ; i < size ; ++i) { arraysOut[i] = DataArrayT::New(); - if(rank == 0) + if(rank == root) { mcIdType nbOfEltPack(resultIndex[i+1]-resultIndex[i]); arraysOut[i]->alloc(nbOfEltPack,1); diff --git a/src/ParaMEDMEM/ParaDataArray.cxx b/src/ParaMEDMEM/ParaDataArray.cxx index f0f16ef11..2f990286f 100644 --- a/src/ParaMEDMEM/ParaDataArray.cxx +++ b/src/ParaMEDMEM/ParaDataArray.cxx @@ -24,6 +24,8 @@ using namespace MEDCoupling; template class ParaDataArrayTemplate; template class ParaDataArrayTemplate; +template class ParaDataArrayDiscrete; +template class ParaDataArrayDiscrete; ParaDataArrayInt32 *ParaDataArrayInt32::New(DataArrayInt32 *seqDa) { diff --git a/src/ParaMEDMEM/ParaDataArray.hxx b/src/ParaMEDMEM/ParaDataArray.hxx index e06f714ef..f02c3d68d 100644 --- a/src/ParaMEDMEM/ParaDataArray.hxx +++ b/src/ParaMEDMEM/ParaDataArray.hxx @@ -41,7 +41,7 @@ namespace MEDCoupling protected: std::size_t getHeapMemorySizeWithoutChildren() const override; std::vector getDirectChildrenWithNull() const override; - void checkOKOneComponent(const std::string& msg); + void checkOKOneComponent(const std::string& msg) const; protected: MCAuto::ArrayType> _seq_da; }; @@ -50,7 +50,7 @@ namespace MEDCoupling class ParaDataArrayDiscrete : public ParaDataArrayTemplate { public: - typename Traits::ArrayType *buildComplement(T nbOfElems) const; + DataArrayIdType *buildComplement(T nbOfElems) const; protected: ParaDataArrayDiscrete(typename Traits::ArrayType *seqDa):ParaDataArrayTemplate(seqDa) { } }; diff --git a/src/ParaMEDMEM/ParaDataArray.txx b/src/ParaMEDMEM/ParaDataArray.txx index 898a41946..652b325f2 100644 --- a/src/ParaMEDMEM/ParaDataArray.txx +++ b/src/ParaMEDMEM/ParaDataArray.txx @@ -22,6 +22,7 @@ #include "ParaDataArray.hxx" #include "CommInterface.hxx" +#include "MEDCouplingMemArray.txx" #include @@ -46,7 +47,7 @@ namespace MEDCoupling } template - void ParaDataArrayTemplate::checkOKOneComponent(const std::string& msg) + void ParaDataArrayTemplate::checkOKOneComponent(const std::string& msg) const { if(this->_seq_da.isNull()) { @@ -65,7 +66,7 @@ namespace MEDCoupling Parallel version of DataArrayInt::buildComplement. Returns result on proc 0. Not allocated DataArrayT is returned for all procs. */ template - typename Traits::ArrayType *ParaDataArrayDiscrete::buildComplement(T nbOfElems) const + DataArrayIdType *ParaDataArrayDiscrete::buildComplement(T nbOfElems) const { using DataArrayT = typename Traits::ArrayType; this->checkOKOneComponent("ParaDataArray::buildComplement"); @@ -76,17 +77,17 @@ namespace MEDCoupling std::vector< MCAuto > idsCaptured(size); for(int curRk = 0 ; curRk < size ; ++curRk) { - mcIdType curStart(0),curEnd(0); - DataArrayTools::GetSlice(0,nbOfElems,1,static_cast(curRk),static_cast(size),curStart,curEnd); + T curStart(0),curEnd(0); + DataArrayTools::GetSlice(0,nbOfElems,1,ToIdType(curRk),ToIdType(size),curStart,curEnd); MCAuto idsInGlobalIds(this->_seq_da->findIdsInRange(curStart,curEnd)); idsCaptured[curRk] = this->_seq_da->selectByTupleIdSafe(idsInGlobalIds->begin(),idsInGlobalIds->end()); } // communication : 1 arrays are going to be all2allized : ids - MCAuto aggregatedIds; + MCAuto aggregatedIds; { std::vector< MCAuto > myRkIdsCaptured; ci.allToAllArraysT(comm,idsCaptured,myRkIdsCaptured); - aggregatedIds = DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(myRkIdsCaptured)); + aggregatedIds = DataArrayT::Aggregate(FromVecAutoToVecOfConst(myRkIdsCaptured)); } aggregatedIds->sort(); aggregatedIds = aggregatedIds->buildUnique(); @@ -94,9 +95,14 @@ namespace MEDCoupling ci.commRank(comm,&rank); T vmin(std::numeric_limits::max()),vmax(-std::numeric_limits::max()); DataArrayTools::GetSlice(0,nbOfElems,1,static_cast(rank),static_cast(size),vmin,vmax); - MCAuto retIds(aggregatedIds->findIdsNotInRange(vmin,vmax)); - MCAuto ret(aggregatedIds->selectByTupleIdSafe(retIds->begin(),retIds->end())); - return nullptr; + aggregatedIds->applyLin(1,-vmin); + MCAuto seqComp(aggregatedIds->buildComplement(ToIdType(vmax-vmin))); + seqComp->applyLin(1,ToIdType(vmin)); + // + std::vector< MCAuto > arraysOut; + ci.gatherArrays(comm,0,seqComp,arraysOut); + MCAuto ret(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst(arraysOut))); + return ret.retn(); } } diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEM.i b/src/ParaMEDMEM_Swig/ParaMEDMEM.i index dbe2a6000..5ba926d7f 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEM.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEM.i @@ -173,13 +173,6 @@ def MEDCouplingDenseMatrixIadd(self,*args): def MEDCouplingDenseMatrixIsub(self,*args): import _ParaMEDMEM return _ParaMEDMEM.DenseMatrix____isub___(self, self, *args) - -if MEDCouplingUse64BitIDs(): - ParaDataArrayInt = ParaDataArrayInt64 -else: - ParaDataArrayInt = ParaDataArrayInt32 -pass - %} %include "MEDCouplingFinalize.i" diff --git a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i index 2c685f7c1..896f77469 100644 --- a/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i +++ b/src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i @@ -217,7 +217,7 @@ namespace MEDCoupling { public: static ParaDataArrayInt32 *New(DataArrayInt32 *seqDa); - DataArrayInt32 *buildComplement(int nbOfElems) const; + DataArrayIdType *buildComplement(int nbOfElems) const; %extend { ParaDataArrayInt32(DataArrayInt32 *seqDa) @@ -231,7 +231,7 @@ namespace MEDCoupling { public: static ParaDataArrayInt64 *New(DataArrayInt64 *seqDa); - DataArrayInt64 *buildComplement(long nbOfElems) const; + DataArrayIdType *buildComplement(long nbOfElems) const; %extend { ParaDataArrayInt64(DataArrayInt64 *seqDa) @@ -318,3 +318,10 @@ public: return ret; } } + +%pythoncode %{ +if MEDCouplingUse64BitIDs(): + ParaDataArrayInt = ParaDataArrayInt64 +else: + ParaDataArrayInt = ParaDataArrayInt32 +%}