From: Anthony Geay Date: Wed, 15 Apr 2020 21:07:45 +0000 (+0200) Subject: WIP X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b70792de00845b56cca991fa72dcf5baf1a495b7;p=tools%2Fmedcoupling.git WIP --- diff --git a/src/INTERP_KERNEL/MCIdType.hxx b/src/INTERP_KERNEL/MCIdType.hxx index 6accd369b..5441c7ab0 100644 --- a/src/INTERP_KERNEL/MCIdType.hxx +++ b/src/INTERP_KERNEL/MCIdType.hxx @@ -18,8 +18,7 @@ // // Author : Anthony Geay (EDF R&D) -#ifndef __IK_MCIDTYPE_HXX__ -#define __IK_MCIDTYPE_HXX__ +#pragma once #include #include @@ -35,6 +34,10 @@ typedef std::int64_t mcIdType; #endif +template inline std::size_t ToSizeT(T val) +{ + return static_cast(val); +} template inline mcIdType ToIdType(T val) { return static_cast(val); @@ -43,6 +46,3 @@ template inline T FromIdType(mcIdType val) { return static_cast(val); } - - -#endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.hxx b/src/MEDCoupling/MEDCouplingMemArray.hxx index 030f2c013..6605b5145 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.hxx +++ b/src/MEDCoupling/MEDCouplingMemArray.hxx @@ -18,8 +18,7 @@ // // Author : Anthony Geay (EDF R&D) -#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__ -#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__ +#pragma once #include "MEDCoupling.hxx" #include "MCType.hxx" @@ -542,9 +541,10 @@ namespace MEDCoupling class DataArrayDiscrete : public DataArrayTemplateClassic { public: - typedef typename Traits::ArrayType DataArrayType; + using DataArrayType = typename Traits::ArrayType; public: static DataArrayType *New(); + static MCAuto NewFromArray(const T *arrBegin, const T *arrEnd); T intValue() const; bool isEqual(const DataArrayDiscrete& other) const; bool isEqualIfNotWhy(const DataArrayDiscrete& other, std::string& reason) const; @@ -1058,5 +1058,3 @@ namespace MEDCoupling throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !"); } } - -#endif diff --git a/src/MEDCoupling/MEDCouplingMemArray.txx b/src/MEDCoupling/MEDCouplingMemArray.txx index e054290ad..ac198f8e7 100755 --- a/src/MEDCoupling/MEDCouplingMemArray.txx +++ b/src/MEDCoupling/MEDCouplingMemArray.txx @@ -3634,6 +3634,19 @@ struct NotInRange return new typename Traits::ArrayType; } + /*! + * Returns a newly created array containing a copy of the input array defined by [ \a arrBegin, \a arrEnd ) + */ + template + MCAuto< typename Traits::ArrayType > DataArrayDiscrete::NewFromArray(const T *arrBegin, const T *arrEnd) + { + MCAuto< typename Traits::ArrayType > ret(DataArrayDiscrete::New()); + std::size_t nbElts(std::distance(arrBegin,arrEnd)); + ret->alloc(nbElts,1); + std::copy(arrBegin,arrEnd,ret->getPointer()); + return ret; + } + /*! * Checks if values of \a this and another DataArrayInt are equal. For more info see * \ref MEDCouplingArrayBasicsCompare. diff --git a/src/MEDCoupling/MEDCouplingTraits.hxx b/src/MEDCoupling/MEDCouplingTraits.hxx index 9d10b48fa..a138eb4c2 100644 --- a/src/MEDCoupling/MEDCouplingTraits.hxx +++ b/src/MEDCoupling/MEDCouplingTraits.hxx @@ -58,10 +58,10 @@ namespace MEDCoupling static const char FieldTypeName[]; static const char NPYStr[]; static const char ReprStr[]; - typedef DataArrayDouble ArrayType; - typedef DataArrayDouble ArrayTypeCh; - typedef MEDCouplingFieldDouble FieldType; - typedef DataArrayDoubleTuple ArrayTuple; + using ArrayType = DataArrayDouble; + using ArrayTypeCh = DataArrayDouble; + using FieldType = MEDCouplingFieldDouble; + using ArrayTuple = DataArrayDoubleTuple; }; template<> @@ -71,10 +71,10 @@ namespace MEDCoupling static const char FieldTypeName[]; static const char NPYStr[]; static const char ReprStr[]; - typedef DataArrayFloat ArrayType; - typedef DataArrayFloat ArrayTypeCh; - typedef MEDCouplingFieldFloat FieldType; - typedef DataArrayFloatTuple ArrayTuple; + using ArrayType = DataArrayFloat; + using ArrayTypeCh = DataArrayFloat; + using FieldType = MEDCouplingFieldFloat; + using ArrayTuple = DataArrayFloatTuple; }; template<> @@ -85,11 +85,11 @@ namespace MEDCoupling static const char NPYStr[]; static const char ReprStr[]; static const char VTKReprStr[]; - typedef DataArrayInt32 ArrayType; - typedef DataArrayInt32 ArrayTypeCh; - typedef MEDCouplingFieldInt FieldType; - typedef DataArrayInt32Tuple ArrayTuple; - typedef DataArrayInt32Iterator IteratorType; + using ArrayType = DataArrayInt32; + using ArrayTypeCh = DataArrayInt32; + using FieldType = MEDCouplingFieldInt; + using ArrayTuple = DataArrayInt32Tuple; + using IteratorType = DataArrayInt32Iterator; }; template<> @@ -100,21 +100,21 @@ namespace MEDCoupling static const char NPYStr[]; static const char ReprStr[]; static const char VTKReprStr[]; - typedef DataArrayInt64 ArrayType; - typedef DataArrayInt64 ArrayTypeCh; - //typedef MEDCouplingFieldInt64 FieldType; - typedef DataArrayInt64Tuple ArrayTuple; - typedef DataArrayInt64Iterator IteratorType; + using ArrayType = DataArrayInt64; + using ArrayTypeCh = DataArrayInt64; + //using FieldType = MEDCouplingFieldInt64; + using ArrayTuple = DataArrayInt64Tuple; + using IteratorType = DataArrayInt64Iterator; }; template<> struct MEDCOUPLING_EXPORT Traits { static const char ArrayTypeName[]; - typedef DataArrayByte ArrayTypeCh; - typedef DataArrayChar ArrayType; - typedef DataArrayByteTuple ArrayTuple; - typedef DataArrayByteIterator IteratorType; + using ArrayTypeCh = DataArrayByte; + using ArrayType = DataArrayChar; + using ArrayTuple = DataArrayByteTuple; + using IteratorType = DataArrayByteIterator; }; } diff --git a/src/ParaMEDMEM/CommInterface.hxx b/src/ParaMEDMEM/CommInterface.hxx index 967501cdb..96471f670 100644 --- a/src/ParaMEDMEM/CommInterface.hxx +++ b/src/ParaMEDMEM/CommInterface.hxx @@ -124,10 +124,11 @@ namespace MEDCoupling /*! * Helper of alltoallv and allgatherv */ - static std::unique_ptr ComputeOffset(const std::unique_ptr& counts, std::size_t sizeOfCounts) + template + static std::unique_ptr ComputeOffset(const std::unique_ptr& counts, std::size_t sizeOfCounts) { - std::unique_ptr ret(new int[sizeOfCounts]); - ret[0] = 0; + std::unique_ptr ret(new T[sizeOfCounts]); + ret[0] = static_cast(0); for(std::size_t i = 1 ; i < sizeOfCounts ; ++i) { ret[i] = ret[i-1] + counts[i-1]; diff --git a/src/ParaMEDMEM/ParaUMesh.cxx b/src/ParaMEDMEM/ParaUMesh.cxx index 080a9ab4a..0b844e96c 100644 --- a/src/ParaMEDMEM/ParaUMesh.cxx +++ b/src/ParaMEDMEM/ParaUMesh.cxx @@ -136,6 +136,45 @@ void AllGatherArrays(const CommInterface& ci, MPI_Comm comm, const DataArrayIdTy resultIndex = std::move(nbOfElems); } +/*! + * Generalized AllToAll collective communication. + */ +void AllToAllArrays(const CommInterface& ci, MPI_Comm comm, const std::vector< MCAuto >& arrays, std::vector< MCAuto >& arraysOut) +{ + int size; + ci.commSize(comm,&size); + if( arrays.size() != ToSizeT(size) ) + throw INTERP_KERNEL::Exception("AllToAllArrays : internal error ! Invalid size of input array."); + std::vector< const DataArrayIdType *> arraysBis(size); + { + std::vector< const DataArrayIdType *>::iterator itArraysBis(arraysBis.begin()); + std::for_each(arrays.begin(),arrays.end(),[&itArraysBis](MCAuto elt) { *itArraysBis++=elt; }); + } + std::unique_ptr nbOfElems2(new mcIdType[size]),nbOfElems3(new mcIdType[size]); + for(int curRk = 0 ; curRk < size ; ++curRk) + { + nbOfElems3[curRk] = arrays[curRk]->getNumberOfTuples(); + } + ci.allToAll(nbOfElems3.get(),1,MPI_ID_TYPE,nbOfElems2.get(),1,MPI_ID_TYPE,comm); + mcIdType nbOfCellIdsSum(std::accumulate(nbOfElems2.get(),nbOfElems2.get()+size,0)); + MCAuto cellIdsFromProcs(DataArrayIdType::New()); + cellIdsFromProcs->alloc(nbOfCellIdsSum,1); + std::unique_ptr nbOfElemsInt( CommInterface::ToIntArray(nbOfElems3,size) ),nbOfElemsOutInt( CommInterface::ToIntArray(nbOfElems2,size) ); + std::unique_ptr offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ), offsetsOut( CommInterface::ComputeOffset(nbOfElemsOutInt,size) ); + { + MCAuto arraysAcc(DataArrayIdType::Aggregate(arraysBis)); + ci.allToAllV(arraysAcc->begin(),nbOfElemsInt.get(),offsetsIn.get(),MPI_ID_TYPE, + cellIdsFromProcs->getPointer(),nbOfElemsOutInt.get(),offsetsOut.get(),MPI_ID_TYPE,comm); + } + std::unique_ptr offsetsOutIdType( CommInterface::ComputeOffset(nbOfElems2,size) ); + // build output arraysOut by spliting cellIdsFromProcs into parts + arraysOut.resize(size); + for(int curRk = 0 ; curRk < size ; ++curRk) + { + arraysOut[curRk] = DataArrayIdType::NewFromArray(cellIdsFromProcs->begin()+offsetsOutIdType[curRk],cellIdsFromProcs->begin()+offsetsOutIdType[curRk]+nbOfElems2[curRk]); + } +} + /*! */ MCAuto ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const