//
// Author : Anthony Geay (EDF R&D)
-#ifndef __IK_MCIDTYPE_HXX__
-#define __IK_MCIDTYPE_HXX__
+#pragma once
#include <cstdint>
#include <stddef.h>
#endif
+template <class T> inline std::size_t ToSizeT(T val)
+{
+ return static_cast<std::size_t>(val);
+}
template <class T> inline mcIdType ToIdType(T val)
{
return static_cast<mcIdType>(val);
{
return static_cast<T>(val);
}
-
-
-#endif
//
// Author : Anthony Geay (EDF R&D)
-#ifndef __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
-#define __MEDCOUPLING_MEDCOUPLINGMEMARRAY_HXX__
+#pragma once
#include "MEDCoupling.hxx"
#include "MCType.hxx"
class DataArrayDiscrete : public DataArrayTemplateClassic<T>
{
public:
- typedef typename Traits<T>::ArrayType DataArrayType;
+ using DataArrayType = typename Traits<T>::ArrayType;
public:
static DataArrayType *New();
+ static MCAuto<DataArrayType> NewFromArray(const T *arrBegin, const T *arrEnd);
T intValue() const;
bool isEqual(const DataArrayDiscrete<T>& other) const;
bool isEqualIfNotWhy(const DataArrayDiscrete<T>& other, std::string& reason) const;
throw INTERP_KERNEL::Exception("DataArrayDouble::insertAtTheEnd : not available for DataArrayDouble with number of components different than 1 !");
}
}
-
-#endif
return new typename Traits<T>::ArrayType;
}
+ /*!
+ * Returns a newly created array containing a copy of the input array defined by [ \a arrBegin, \a arrEnd )
+ */
+ template<class T>
+ MCAuto< typename Traits<T>::ArrayType > DataArrayDiscrete<T>::NewFromArray(const T *arrBegin, const T *arrEnd)
+ {
+ MCAuto< typename Traits<T>::ArrayType > ret(DataArrayDiscrete<T>::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.
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<>
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<>
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<>
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<char>
{
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;
};
}
/*!
* Helper of alltoallv and allgatherv
*/
- static std::unique_ptr<int []> ComputeOffset(const std::unique_ptr<int []>& counts, std::size_t sizeOfCounts)
+ template<class T>
+ static std::unique_ptr<T []> ComputeOffset(const std::unique_ptr<T []>& counts, std::size_t sizeOfCounts)
{
- std::unique_ptr<int []> ret(new int[sizeOfCounts]);
- ret[0] = 0;
+ std::unique_ptr<T []> ret(new T[sizeOfCounts]);
+ ret[0] = static_cast<T>(0);
for(std::size_t i = 1 ; i < sizeOfCounts ; ++i)
{
ret[i] = ret[i-1] + counts[i-1];
resultIndex = std::move(nbOfElems);
}
+/*!
+ * Generalized AllToAll collective communication.
+ */
+void AllToAllArrays(const CommInterface& ci, MPI_Comm comm, const std::vector< MCAuto<DataArrayIdType> >& arrays, std::vector< MCAuto<DataArrayIdType> >& 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<DataArrayIdType> elt) { *itArraysBis++=elt; });
+ }
+ std::unique_ptr<mcIdType[]> 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<DataArrayIdType> cellIdsFromProcs(DataArrayIdType::New());
+ cellIdsFromProcs->alloc(nbOfCellIdsSum,1);
+ std::unique_ptr<int[]> nbOfElemsInt( CommInterface::ToIntArray<mcIdType>(nbOfElems3,size) ),nbOfElemsOutInt( CommInterface::ToIntArray<mcIdType>(nbOfElems2,size) );
+ std::unique_ptr<int[]> offsetsIn( CommInterface::ComputeOffset(nbOfElemsInt,size) ), offsetsOut( CommInterface::ComputeOffset(nbOfElemsOutInt,size) );
+ {
+ MCAuto<DataArrayIdType> 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<mcIdType[]> 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> ParaUMesh::redistributeCells(const DataArrayIdType *globalCellIds) const