]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
ParaDataArray is on
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Apr 2020 21:05:04 +0000 (23:05 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 29 Apr 2020 21:05:04 +0000 (23:05 +0200)
src/MEDCoupling/MEDCouplingMemArray.txx
src/ParaMEDMEM/CommInterface.hxx
src/ParaMEDMEM/ParaDataArray.cxx
src/ParaMEDMEM/ParaDataArray.hxx
src/ParaMEDMEM/ParaDataArray.txx
src/ParaMEDMEM_Swig/ParaMEDMEM.i
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i

index 70aefc7a536aa9365f4d0b88c8289d4f0f303de4..25148688fd83aba8985b79625902ad20a04a7de6 100755 (executable)
@@ -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<T>::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice");
+    mcIdType nbElems=DataArrayTools<T>::GetNumberOfItemGivenBESRelative(start,stop,step,"DataArray::GetSlice");
     mcIdType minNbOfElemsPerSlice=nbElems/nbOfSlices;
     startSlice=start+minNbOfElemsPerSlice*step*sliceId;
     if(sliceId<nbOfSlices-1)
index a59fce0b90856cc23388b4c98bda66c3224a138e..5ba1e95a24e9e9acdc973a5e65e953e12f9b6fdc 100644 (file)
@@ -136,21 +136,23 @@ namespace MEDCoupling
       rank = -1;
       this->commRank(comm,&rank);
       std::unique_ptr<mcIdType[]> 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<int[]> 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<mcIdType>(nbOfElems,size);
         offsetsIn = CommInterface::ComputeOffset(nbOfElemsInt,size);
       }
       this->gatherV(array->begin(),nbOfCellsRequested,ParaTraits<T>::MPIDataType,result.get(),nbOfElemsInt.get(),offsetsIn.get(),ParaTraits<T>::MPIDataType,root,comm);
-      resultIndex = ComputeOffsetFull<mcIdType>(nbOfElems,size);
+      if(rank==root)
+      {
+        resultIndex = ComputeOffsetFull<mcIdType>(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);
index f0f16ef1190024005d04c72a13cf45519d6877ed..2f990286fd84745492a95035c14de8e6df03836a 100644 (file)
@@ -24,6 +24,8 @@ using namespace MEDCoupling;
 
 template class ParaDataArrayTemplate<Int32>;
 template class ParaDataArrayTemplate<Int64>;
+template class ParaDataArrayDiscrete<Int32>;
+template class ParaDataArrayDiscrete<Int64>;
 
 ParaDataArrayInt32 *ParaDataArrayInt32::New(DataArrayInt32 *seqDa)
 {
index e06f714ef111dc8aa7f9b3b1a9ff85037e4ef975..f02c3d68d442e55b67fdc7bef753c340d0614052 100644 (file)
@@ -41,7 +41,7 @@ namespace MEDCoupling
   protected:
     std::size_t getHeapMemorySizeWithoutChildren() const override;
     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const override;
-    void checkOKOneComponent(const std::string& msg);
+    void checkOKOneComponent(const std::string& msg) const;
   protected:
     MCAuto<typename Traits<T>::ArrayType> _seq_da;
   };
@@ -50,7 +50,7 @@ namespace MEDCoupling
   class ParaDataArrayDiscrete : public ParaDataArrayTemplate<T>
   {
   public:
-    typename Traits<T>::ArrayType *buildComplement(T nbOfElems) const;
+    DataArrayIdType *buildComplement(T nbOfElems) const;
   protected:
     ParaDataArrayDiscrete(typename Traits<T>::ArrayType *seqDa):ParaDataArrayTemplate<T>(seqDa) { }
   };
index 898a41946fc8b790bfc1fbec0e39153fc8980f3f..652b325f2f87093715c8581476280400f462868d 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "ParaDataArray.hxx"
 #include "CommInterface.hxx"
+#include "MEDCouplingMemArray.txx"
 
 #include <sstream>
 
@@ -46,7 +47,7 @@ namespace MEDCoupling
   }
   
   template<class T>
-  void ParaDataArrayTemplate<T>::checkOKOneComponent(const std::string& msg)
+  void ParaDataArrayTemplate<T>::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<class T>
-  typename Traits<T>::ArrayType *ParaDataArrayDiscrete<T>::buildComplement(T nbOfElems) const
+  DataArrayIdType *ParaDataArrayDiscrete<T>::buildComplement(T nbOfElems) const
   {
     using DataArrayT = typename Traits<T>::ArrayType;
     this->checkOKOneComponent("ParaDataArray::buildComplement");
@@ -76,17 +77,17 @@ namespace MEDCoupling
     std::vector< MCAuto<DataArrayT> > idsCaptured(size);
     for(int curRk = 0 ; curRk < size ; ++curRk)
     {
-      mcIdType curStart(0),curEnd(0);
-      DataArrayTools<T>::GetSlice(0,nbOfElems,1,static_cast<T>(curRk),static_cast<T>(size),curStart,curEnd);
+      T curStart(0),curEnd(0);
+      DataArrayTools<T>::GetSlice(0,nbOfElems,1,ToIdType(curRk),ToIdType(size),curStart,curEnd);
       MCAuto<DataArrayIdType> 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<DataArrayIdType> aggregatedIds;
+    MCAuto<DataArrayT> aggregatedIds;
     {
       std::vector< MCAuto<DataArrayT> > myRkIdsCaptured;
       ci.allToAllArraysT<T>(comm,idsCaptured,myRkIdsCaptured);
-      aggregatedIds = DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(myRkIdsCaptured));
+      aggregatedIds = DataArrayT::Aggregate(FromVecAutoToVecOfConst<DataArrayT>(myRkIdsCaptured));
     }
     aggregatedIds->sort();
     aggregatedIds = aggregatedIds->buildUnique();
@@ -94,9 +95,14 @@ namespace MEDCoupling
     ci.commRank(comm,&rank);
     T vmin(std::numeric_limits<T>::max()),vmax(-std::numeric_limits<T>::max());
     DataArrayTools<T>::GetSlice(0,nbOfElems,1,static_cast<T>(rank),static_cast<T>(size),vmin,vmax);
-    MCAuto<DataArrayIdType> retIds(aggregatedIds->findIdsNotInRange(vmin,vmax));
-    MCAuto<DataArrayT> ret(aggregatedIds->selectByTupleIdSafe(retIds->begin(),retIds->end()));
-    return nullptr;
+    aggregatedIds->applyLin(1,-vmin);
+    MCAuto<DataArrayIdType> seqComp(aggregatedIds->buildComplement(ToIdType(vmax-vmin)));
+    seqComp->applyLin(1,ToIdType(vmin));
+    //
+    std::vector< MCAuto<DataArrayIdType> > arraysOut;
+    ci.gatherArrays(comm,0,seqComp,arraysOut);
+    MCAuto<DataArrayIdType> ret(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(arraysOut)));
+    return ret.retn();
   }
 
 }
index dbe2a6000ca83334120222a85035e81450b8b41f..5ba926d7fc34034ecfa478a1c857eaae75413c58 100644 (file)
@@ -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"
index 2c685f7c142dbd22712af7f5a1b13229bf49c73a..896f77469c751f2bcf95f3219ea7efb2c48d7712 100644 (file)
@@ -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
+%}