12#ifndef ARCCORE_MESSAGEPASSINGMPI_MPIDATATYPE_H
13#define ARCCORE_MESSAGEPASSINGMPI_MPIDATATYPE_H
17#include "arccore/message_passing_mpi/MessagePassingMpiGlobal.h"
20#include "arccore/base/FatalErrorException.h"
27namespace Arccore::MessagePassing::Mpi
55template<
typename RealType>
64 MPI_Op m_min_operator;
65 MPI_Op m_max_operator;
66 MPI_Op m_sum_operator;
68 static void ARCCORE_MPIOP_CALL _MinOperator(
void* a,
void* b,
int* len,MPI_Datatype* type);
69 static void ARCCORE_MPIOP_CALL _MaxOperator(
void* a,
void* b,
int* len,MPI_Datatype* type);
70 static void ARCCORE_MPIOP_CALL _SumOperator(
void* a,
void* b,
int* len,MPI_Datatype* type);
71 void _create(
bool is_commutative);
75template<
typename RealType>
inline
79 m_min_operator = MPI_OP_NULL;
80 m_max_operator = MPI_OP_NULL;
81 m_sum_operator = MPI_OP_NULL;
82 _create(is_commutative);
85template<
typename RealType>
inline
86void ARCCORE_MPIOP_CALL StdMpiReduceOperator<RealType>::
87_MinOperator(
void* a,
void* b,
int* len,MPI_Datatype* type)
90 RealType* ra = (RealType*)a;
91 RealType* rb = (RealType*)b;
96 rb[i] = std::min(va,vb);
100template<
typename RealType>
inline
101void ARCCORE_MPIOP_CALL StdMpiReduceOperator<RealType>::
102_MaxOperator(
void* a,
void* b,
int* len,MPI_Datatype* type)
104 ARCCORE_UNUSED(type);
105 RealType* ra = (RealType*)a;
106 RealType* rb = (RealType*)b;
111 rb[i] = std::max(va,vb);
115template<
typename RealType>
inline
116void ARCCORE_MPIOP_CALL StdMpiReduceOperator<RealType>::
117_SumOperator(
void* a,
void* b,
int* len,MPI_Datatype* type)
119 ARCCORE_UNUSED(type);
120 RealType* ra = (RealType*)a;
121 RealType* rb = (RealType*)b;
130template<
typename RealType>
inline
131void StdMpiReduceOperator<RealType>::
132_create(
bool is_commutative)
134 int commutative = (is_commutative) ? 1 : 0;
135 MPI_Op_create(_MinOperator,commutative,&m_min_operator);
136 MPI_Op_create(_MaxOperator,commutative,&m_max_operator);
137 MPI_Op_create(_SumOperator,commutative,&m_sum_operator);
140template<
typename RealType>
inline
141void StdMpiReduceOperator<RealType>::
144 if (m_min_operator!=MPI_OP_NULL){
145 MPI_Op_free(&m_min_operator);
146 m_min_operator = MPI_OP_NULL;
148 if (m_max_operator!=MPI_OP_NULL){
149 MPI_Op_free(&m_max_operator);
150 m_max_operator = MPI_OP_NULL;
152 if (m_sum_operator!=MPI_OP_NULL){
153 MPI_Op_free(&m_sum_operator);
154 m_sum_operator = MPI_OP_NULL;
161template<
typename RealType>
inline
162MPI_Op StdMpiReduceOperator<RealType>::
165 MPI_Op op = MPI_OP_NULL;
167 case ReduceMax: op = m_max_operator;
break;
168 case ReduceMin: op = m_min_operator;
break;
169 case ReduceSum: op = m_sum_operator;
break;
172 ARCCORE_FATAL(
"Reduce operation unknown or not implemented");
194 return m_reduce_operator->reduceOperator(reduce_type);
196 MPI_Datatype datatype()
const {
return m_datatype; }
204 MPI_Datatype m_datatype;
Opérateur de réduction interne MPI (MPI_MAX, MPI_MIN, MPI_SUM)
Opérateurs de réduction pour les types complexes (Real2, Real3, Real2x2 et Real3x3)
Opérateurs de réduction pour les types classiques.
Integer len(const char *s)
Retourne la longueur de la chaîne s.
eReduceType
Types des réductions supportées.
@ ReduceMin
Minimum des valeurs.
@ ReduceSum
Somme des valeurs.
@ ReduceMax
Maximum des valeurs.
Int32 Integer
Type représentant un entier.