Skip to content

Commit 2414b4e

Browse files
committed
Modernize declaration of custom reductions.
1 parent 96292ae commit 2414b4e

2 files changed

Lines changed: 30 additions & 11 deletions

File tree

include/opdi/backend/macro/macros.hpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,28 @@
235235

236236
// reduction macros
237237

238-
#define OPDI_INTERNAL_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT, ID) \
239-
TYPE operator OP (opdi::Reducer<TYPE, ID> const& lhs, \
240-
opdi::Reducer<TYPE, ID> const& rhs) { \
241-
return lhs.value OP rhs.value; \
242-
} \
243-
\
244-
OPDI_PRAGMA(omp declare reduction(OP_NAME : TYPE : \
245-
opdi::Reducer<TYPE, ID>(omp_out) = opdi::Reducer<TYPE, ID>(omp_out) OP opdi::Reducer<TYPE, ID>(omp_in)) \
246-
initializer(omp_priv = INIT))
238+
#if _OPENMP >= 202411
239+
#define OPDI_INTERNAL_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT, ID) \
240+
TYPE operator OP (opdi::Reducer<TYPE, ID> const& lhs, \
241+
opdi::Reducer<TYPE, ID> const& rhs) { \
242+
return lhs.value OP rhs.value; \
243+
} \
244+
\
245+
OPDI_PRAGMA(omp declare_reduction(OP_NAME : TYPE) \
246+
combiner(opdi::Reducer<TYPE, ID>(omp_out) = \
247+
opdi::Reducer<TYPE, ID>(omp_out) OP opdi::Reducer<TYPE, ID>(omp_in)) \
248+
initializer(omp_priv = INIT))
249+
#else
250+
#define OPDI_INTERNAL_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT, ID) \
251+
TYPE operator OP (opdi::Reducer<TYPE, ID> const& lhs, \
252+
opdi::Reducer<TYPE, ID> const& rhs) { \
253+
return lhs.value OP rhs.value; \
254+
} \
255+
\
256+
OPDI_PRAGMA(omp declare reduction(OP_NAME : TYPE : \
257+
opdi::Reducer<TYPE, ID>(omp_out) = opdi::Reducer<TYPE, ID>(omp_out) OP opdi::Reducer<TYPE, ID>(omp_in)) \
258+
initializer(omp_priv = INIT))
259+
#endif
247260

248261
#define OPDI_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT) \
249262
OPDI_INTERNAL_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT, __COUNTER__)

include/opdi/backend/ompt/macros.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,13 @@
9292
#define OPDI_BARRIER(...) \
9393
OPDI_PRAGMA(omp barrier __VA_ARGS__)
9494

95-
#define OPDI_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT) \
96-
OPDI_PRAGMA(omp declare reduction(OP_NAME : TYPE : omp_out = omp_out OP omp_in) initializer(omp_priv = INIT))
95+
#if _OPENMP >= 202411
96+
#define OPDI_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT) \
97+
OPDI_PRAGMA(omp declare_reduction(OP_NAME : TYPE) combiner(omp_out = omp_out OP omp_in) \
98+
initializer(omp_priv = INIT))
99+
#else
100+
#define OPDI_DECLARE_REDUCTION(OP_NAME, TYPE, OP, INIT) \
101+
OPDI_PRAGMA(omp declare reduction(OP_NAME : TYPE : omp_out = omp_out OP omp_in) initializer(omp_priv = INIT))
102+
#endif
97103

98104
#define OPDI_REDUCTION

0 commit comments

Comments
 (0)