diff --git a/changelog b/changelog index ec878bfe0f..2200b1cc57 100644 --- a/changelog +++ b/changelog @@ -1,4 +1,7 @@ - 9) PR #3406 for # 3406. Fix issue with comment before a subroutine that + 10) PR #3413 for #3411. Remove OpenMP SUB reduction operator and relpace + with ADD as is required by OpenMP 5.2. + + 9) PR #3406 for #3406. Fix issue with comment before a subroutine that turns into a CodeBlock. 8) PR #3371 towards #3012. Add workaround to bypass psyclonefc fixed-from diff --git a/src/psyclone/psyir/backend/fortran.py b/src/psyclone/psyir/backend/fortran.py index 70f0da66b5..87f6c9abf6 100644 --- a/src/psyclone/psyir/backend/fortran.py +++ b/src/psyclone/psyir/backend/fortran.py @@ -1636,7 +1636,6 @@ def operatorclause_node(self, node): OMPDependClause.DependClauseTypes.OUT: "out", OMPDependClause.DependClauseTypes.INOUT: "inout", OMPReductionClause.ReductionClauseTypes.ADD: "+", - OMPReductionClause.ReductionClauseTypes.SUB: "-", OMPReductionClause.ReductionClauseTypes.MUL: "*", OMPReductionClause.ReductionClauseTypes.AND: ".AND.", OMPReductionClause.ReductionClauseTypes.OR: ".OR.", diff --git a/src/psyclone/psyir/nodes/omp_clauses.py b/src/psyclone/psyir/nodes/omp_clauses.py index afd0e243f6..64b81ce8ab 100644 --- a/src/psyclone/psyir/nodes/omp_clauses.py +++ b/src/psyclone/psyir/nodes/omp_clauses.py @@ -508,19 +508,18 @@ class ReductionClauseTypes(Enum): supported in PSyclone.''' # Arithmetic operators ADD = 0 - SUB = 1 - MUL = 2 + MUL = 1 # Logical operators - AND = 3 - OR = 4 - EQV = 5 # Fortran specific - NEQV = 6 # Fortran specific + AND = 2 + OR = 3 + EQV = 4 # Fortran specific + NEQV = 5 # Fortran specific # Intrinsic procedures - MAX = 7 - MIN = 8 - IAND = 9 - IOR = 10 - IEOR = 11 + MAX = 6 + MIN = 7 + IAND = 8 + IOR = 9 + IEOR = 10 def __init__(self, operator: ReductionClauseTypes, **kwargs): if not isinstance(operator, OMPReductionClause.ReductionClauseTypes): diff --git a/src/psyclone/psyir/nodes/omp_directives.py b/src/psyclone/psyir/nodes/omp_directives.py index 1252427822..66ea04cb2c 100644 --- a/src/psyclone/psyir/nodes/omp_directives.py +++ b/src/psyclone/psyir/nodes/omp_directives.py @@ -89,8 +89,9 @@ MAP_REDUCTION_OP_TO_OMP = { BinaryOperation.Operator.ADD: OMPReductionClause.ReductionClauseTypes.ADD, + # From OpenMP 5.2 the - reduction is not supported, use + instead BinaryOperation.Operator.SUB: - OMPReductionClause.ReductionClauseTypes.SUB, + OMPReductionClause.ReductionClauseTypes.ADD, BinaryOperation.Operator.MUL: OMPReductionClause.ReductionClauseTypes.MUL, BinaryOperation.Operator.AND: diff --git a/src/psyclone/tests/psyir/nodes/omp_directives_test.py b/src/psyclone/tests/psyir/nodes/omp_directives_test.py index d40de24f01..c113cf60d5 100644 --- a/src/psyclone/tests/psyir/nodes/omp_directives_test.py +++ b/src/psyclone/tests/psyir/nodes/omp_directives_test.py @@ -4871,6 +4871,9 @@ def test_reduction_arith_ops(op, fortran_reader, fortran_writer): loop = psyir.walk(Loop)[0] omplooptrans.apply(loop, enable_reductions=True) output = fortran_writer(psyir) + # The + and - operators are equivalent, from OpenMP 5.2 the - is deprecated + if op == "-": + op = "+" assert f"reduction({op}: acc)" in output