From ba5b79c131fd0eef4bb6d3b3935436e39eef7062 Mon Sep 17 00:00:00 2001 From: LonelyCat124 <3043914+LonelyCat124@users.noreply.github.com.> Date: Thu, 30 Apr 2026 12:59:47 +0100 Subject: [PATCH 1/6] Move OMPParallelTrans to create the data sharing attributes instead of at lowering time --- .../psyir/nodes/dynamic_omp_task_directive.py | 39 +++++++++++-------- src/psyclone/psyir/nodes/omp_directives.py | 34 ++++++++++------ .../psyir/transformations/omp_loop_trans.py | 4 +- .../transformations/omp_parallel_trans.py | 6 +++ .../lfric_transformations_test.py | 12 +++++- .../transformations/openmp/openmp_test.py | 1 + src/psyclone/tests/psyir/backend/c_test.py | 1 + .../tests/psyir/backend/fortran_test.py | 1 + .../tests/psyir/backend/psyir_openmp_test.py | 4 +- .../tests/psyir/nodes/omp_directives_test.py | 22 ++++++++--- .../parallel_loop_trans_test.py | 10 +++++ src/psyclone/transformations.py | 10 +++++ 12 files changed, 106 insertions(+), 38 deletions(-) diff --git a/src/psyclone/psyir/nodes/dynamic_omp_task_directive.py b/src/psyclone/psyir/nodes/dynamic_omp_task_directive.py index 78286d66a7..382f16b124 100644 --- a/src/psyclone/psyir/nodes/dynamic_omp_task_directive.py +++ b/src/psyclone/psyir/nodes/dynamic_omp_task_directive.py @@ -2102,6 +2102,28 @@ def _compute_clauses(self): out_clause, ) + def generate_data_and_depend_clauses(self): + """ + Adds the data and depend clauses needed for this task directive. + """ + # Create the clauses + ( + private_clause, + firstprivate_clause, + shared_clause, + in_clause, + out_clause, + ) = self._compute_clauses() + + # Replace the children with the new children + old_children = self.pop_all_children() + self.addchild(old_children[0]) + self.addchild(private_clause) + self.addchild(firstprivate_clause) + self.addchild(shared_clause) + self.addchild(in_clause) + self.addchild(out_clause) + def lower_to_language_level(self): """ Lowers the structure of the PSyIR tree inside the Directive @@ -2137,22 +2159,7 @@ def lower_to_language_level(self): ) # Create the clauses - ( - private_clause, - firstprivate_clause, - shared_clause, - in_clause, - out_clause, - ) = self._compute_clauses() - - # Replace the children with the new children - old_children = self.pop_all_children() - self.addchild(old_children[0]) - self.addchild(private_clause) - self.addchild(firstprivate_clause) - self.addchild(shared_clause) - self.addchild(in_clause) - self.addchild(out_clause) + self.generate_data_and_depend_clauses() super().lower_to_language_level() # Replace this node with an OMPTaskDirective diff --git a/src/psyclone/psyir/nodes/omp_directives.py b/src/psyclone/psyir/nodes/omp_directives.py index 66ea04cb2c..4c69ab72bb 100644 --- a/src/psyclone/psyir/nodes/omp_directives.py +++ b/src/psyclone/psyir/nodes/omp_directives.py @@ -1282,6 +1282,27 @@ def private_clause(self): ''' return self.children[2] + def generate_data_clauses(self): + ''' + Adds the private and firstprivate clauses to this OMPParallelDirective + according to the contained nodes. + ''' + reprod_red_call_list = self.reductions(reprod=True) + private, fprivate, need_sync = self.infer_sharing_attributes() + # Order the clause variables alphabetically (to facilitate comparisons) + if reprod_red_call_list: + table = self.ancestor(Routine).symbol_table + thread_idx = table.find_or_create_tag( + "omp_thread_index", root_name="th_idx", + symbol_type=DataSymbol, datatype=INTEGER_TYPE) + private.add(thread_idx) + private_clause = OMPPrivateClause.create( + sorted(private, key=lambda x: x.name)) + fprivate_clause = OMPFirstprivateClause.create( + sorted(fprivate, key=lambda x: x.name)) + self.children[2].replace_with(private_clause) + self.children[3].replace_with(fprivate_clause) + def lower_to_language_level(self) -> Node: ''' In-place construction of clauses as PSyIR constructs. @@ -1356,15 +1377,7 @@ def lower_to_language_level(self) -> Node: # Create data sharing clauses (before lowering, so the CodedKern # semantics are taken into account) - private, fprivate, need_sync = self.infer_sharing_attributes() - - # Order the clause variables alphabetically (to facilitate comparisons) - if reprod_red_call_list: - private.add(thread_idx) - private_clause = OMPPrivateClause.create( - sorted(private, key=lambda x: x.name)) - fprivate_clause = OMPFirstprivateClause.create( - sorted(fprivate, key=lambda x: x.name)) + _, _, need_sync = self.infer_sharing_attributes() # Check all of the need_sync nodes are synchronized in children. # unless it has reduction_kernels which are handled separately @@ -1387,9 +1400,6 @@ def lower_to_language_level(self) -> Node: " or the code includes the necessary " "synchronisations.", type(self).__name__, sym.name) - self.children[2].replace_with(private_clause) - self.children[3].replace_with(fprivate_clause) - # Continue lowering children (but not the clauses we just added) for child in self.children[:2]: child.lower_to_language_level() diff --git a/src/psyclone/psyir/transformations/omp_loop_trans.py b/src/psyclone/psyir/transformations/omp_loop_trans.py index 694c6293be..8178c8f31c 100644 --- a/src/psyclone/psyir/transformations/omp_loop_trans.py +++ b/src/psyclone/psyir/transformations/omp_loop_trans.py @@ -342,7 +342,9 @@ def apply(self, node, options=None, parent = node.parent position = node.position super().apply(node, local_options, reduction_ops=red_ops, **kwargs) - + if self.omp_directive == "paralleldo": + node.ancestor(OMPParallelDirective, + include_self=True).generate_data_clauses() # Add reduction clauses to the newly introduced directive directive = parent.children[position] for (op, ref) in self.inferred_reduction_clauses: diff --git a/src/psyclone/psyir/transformations/omp_parallel_trans.py b/src/psyclone/psyir/transformations/omp_parallel_trans.py index 91a43f5386..63320dfd0b 100644 --- a/src/psyclone/psyir/transformations/omp_parallel_trans.py +++ b/src/psyclone/psyir/transformations/omp_parallel_trans.py @@ -131,5 +131,11 @@ def validate(self, node_list: list[Node], options=None): # Now call the general validation checks super().validate(node_list, options) + def apply(self, node_list, options=None): + super().apply(node_list, options=options) + node_list = self.get_node_list(node_list) + node_list[0].ancestor(OMPParallelDirective, + include_self=True).generate_data_clauses() + __all__ = ["OMPParallelTrans"] diff --git a/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py b/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py index ce3983a913..214f841674 100644 --- a/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py +++ b/src/psyclone/tests/domain/lfric/transformations/lfric_transformations_test.py @@ -3877,6 +3877,8 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " x_innerproduct_y(asum,f1,f2)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + + 3*indent + "Reference[name:'th_idx']\n" + 2*indent + ompfprivate + "[]\n" + indent + "1: " + gsum + "[scalar='asum']\n" + indent + "2: " + ompparallel + "[]\n" + @@ -3893,6 +3895,7 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " inc_a_times_x(asum,f1)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + 2*indent + ompfprivate + "[]\n" + indent + "3: " + ompparallel + "[]\n" + 2*indent + sched + "[]\n" + @@ -3908,6 +3911,8 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " sum_x(bsum,f2)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + + 3*indent + "Reference[name:'th_idx']\n" + 2*indent + ompfprivate + "[]\n" + indent + "4: " + gsum + "[scalar='bsum']\n") if not annexed: @@ -3929,6 +3934,8 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " x_innerproduct_y(asum,f1,f2)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + + 3*indent + "Reference[name:'th_idx']\n" + 2*indent + ompfprivate + "[]\n" + indent + "1: " + ompparallel + "[]\n" + 2*indent + sched + "[]\n" + @@ -3944,6 +3951,7 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " inc_a_times_x(asum,f1)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + 2*indent + ompfprivate + "[]\n" + indent + "2: " + ompparallel + "[]\n" + 2*indent + sched + "[]\n" + @@ -3959,13 +3967,15 @@ def test_reprod_view(monkeypatch, annexed, dist_mem): 7*indent + "0: " + call + " sum_x(bsum,f2)\n" + 2*indent + ompdefault + "[default=DefaultClauseTypes.SHARED]\n" + 2*indent + ompprivate + "[]\n" + + 3*indent + "Reference[name:'df']\n" + + 3*indent + "Reference[name:'th_idx']\n" + 2*indent + ompfprivate + "[]\n") if expected not in result: print("Expected ...") print(expected) print("Found ...") print(result) - assert 0 + assert expected in result @pytest.mark.parametrize("reprod", [True, False]) diff --git a/src/psyclone/tests/nemo/transformations/openmp/openmp_test.py b/src/psyclone/tests/nemo/transformations/openmp/openmp_test.py index e978081f69..204d6f78da 100644 --- a/src/psyclone/tests/nemo/transformations/openmp/openmp_test.py +++ b/src/psyclone/tests/nemo/transformations/openmp/openmp_test.py @@ -89,6 +89,7 @@ def test_omp_explicit_gen(fortran_reader, fortran_writer): " !$omp end parallel do\n" "\n" "end program explicit_do") + print(fortran_writer(psyir).lower()) assert expected in fortran_writer(psyir).lower() # Check that calling gen a second time gives the same code assert expected in fortran_writer(psyir).lower() diff --git a/src/psyclone/tests/psyir/backend/c_test.py b/src/psyclone/tests/psyir/backend/c_test.py index 9ff881be37..c4a0fa9e25 100644 --- a/src/psyclone/tests/psyir/backend/c_test.py +++ b/src/psyclone/tests/psyir/backend/c_test.py @@ -571,6 +571,7 @@ def test_cw_directive_with_clause(fortran_reader): master = OMPMasterDirective(children=[directive]) parallel = OMPParallelDirective.create(children=[master]) schedule.addchild(parallel, 0) + parallel.generate_data_clauses() assert '''#pragma omp parallel default(shared), private(i) { #pragma omp master diff --git a/src/psyclone/tests/psyir/backend/fortran_test.py b/src/psyclone/tests/psyir/backend/fortran_test.py index f52227e460..d99e4a4f95 100644 --- a/src/psyclone/tests/psyir/backend/fortran_test.py +++ b/src/psyclone/tests/psyir/backend/fortran_test.py @@ -2034,6 +2034,7 @@ def test_fw_directive_with_clause(fortran_reader, fortran_writer): master = OMPMasterDirective(children=[directive]) parallel = OMPParallelDirective.create(children=[master]) schedule.addchild(parallel, 0) + parallel.generate_data_clauses() assert '''!$omp parallel default(shared) private(i) !$omp master !$omp taskloop num_tasks(32) nogroup diff --git a/src/psyclone/tests/psyir/backend/psyir_openmp_test.py b/src/psyclone/tests/psyir/backend/psyir_openmp_test.py index da675760ce..dfcedd2a6c 100644 --- a/src/psyclone/tests/psyir/backend/psyir_openmp_test.py +++ b/src/psyclone/tests/psyir/backend/psyir_openmp_test.py @@ -141,7 +141,7 @@ def test_gocean_omp_parallel(): # So only convert starting from the OMPParallelDirective fvisitor = FortranWriter() result = fvisitor(invoke.schedule[0]) - correct = '''!$omp parallel default(shared) + correct = '''!$omp parallel default(shared) private(i,j) a = b !$omp end parallel''' assert correct in result @@ -149,7 +149,7 @@ def test_gocean_omp_parallel(): cvisitor = CWriter() # Remove newlines for easier RE matching result = cvisitor(invoke.schedule[0]) - correct = '''#pragma omp parallel default(shared) + correct = '''#pragma omp parallel default(shared), private(i,j) { a = b; }''' diff --git a/src/psyclone/tests/psyir/nodes/omp_directives_test.py b/src/psyclone/tests/psyir/nodes/omp_directives_test.py index c113cf60d5..31ff33aa28 100644 --- a/src/psyclone/tests/psyir/nodes/omp_directives_test.py +++ b/src/psyclone/tests/psyir/nodes/omp_directives_test.py @@ -80,8 +80,11 @@ TEST_LOGGER_INF = "psyclone.psyir.tools.reduction_inference" -def test_ompparallel_lowering(fortran_reader, monkeypatch, caplog): - ''' Check that lowering an OMP Parallel region leaves it with the +def test_ompparallel_generate_data_clauses_and_lowering( + fortran_reader, monkeypatch, caplog +): + ''' Check that lowering an OMP Parallel region and calling + generate_data_clauses (as the transformations do) leaves it with the appropriate begin_string and clauses for the backend to generate the right code''' code = ''' @@ -106,6 +109,7 @@ def test_ompparallel_lowering(fortran_reader, monkeypatch, caplog): ptrans.apply(loops[0].parent.parent) assert isinstance(tree.children[0].children[0], OMPParallelDirective) pdir = tree.children[0].children[0] + pdir.generate_data_clauses() pdir.lower_to_language_level() assert pdir.begin_string() == "omp parallel" assert len(pdir.children) == 4 @@ -124,6 +128,7 @@ def test_ompparallel_lowering(fortran_reader, monkeypatch, caplog): # Add loop pdir.children[0].addchild(new_loop) + pdir.generate_data_clauses() pdir.lower_to_language_level() assert pdir.children[2] is not priv_clause @@ -131,6 +136,7 @@ def test_ompparallel_lowering(fortran_reader, monkeypatch, caplog): monkeypatch.setattr(pdir, "infer_sharing_attributes", lambda: ({Symbol("a")}, {Symbol("b")}, None)) + pdir.generate_data_clauses() pdir.lower_to_language_level() assert isinstance(pdir.children[2], OMPPrivateClause) assert len(pdir.children[2].children) == 1 @@ -169,9 +175,11 @@ def test_ompparallel_lowering(fortran_reader, monkeypatch, caplog): "\n" in caplog.text) -def test_omp_parallel_do_lowering(fortran_reader, monkeypatch, caplog): - ''' Check that lowering an OMP Parallel Do leaves it with the - appropriate begin_string and clauses for the backend to generate +def test_omp_parallel_do_generate_data_clauses( + fortran_reader, monkeypatch, caplog +): + ''' Check that generate_data_clauses on an OMP Parallel Do leaves it with + the appropriate begin_string and clauses for the backend to generate the right code''' code = ''' @@ -212,6 +220,8 @@ def test_omp_parallel_do_lowering(fortran_reader, monkeypatch, caplog): # Change the schedule pdir._omp_schedule = "dynamic" + pdir.generate_data_clauses() + # Schedule is only updated in lowering. pdir.lower_to_language_level() assert pdir.children[2] is not priv_clause assert isinstance(pdir.children[2], OMPPrivateClause) @@ -224,7 +234,7 @@ def test_omp_parallel_do_lowering(fortran_reader, monkeypatch, caplog): monkeypatch.setattr(pdir, "infer_sharing_attributes", lambda: ({Symbol("a")}, {Symbol("b")}, None)) - pdir.lower_to_language_level() + pdir.generate_data_clauses() assert isinstance(pdir.children[2], OMPPrivateClause) assert len(pdir.children[2].children) == 1 assert pdir.children[2].children[0].name == 'a' diff --git a/src/psyclone/tests/psyir/transformations/parallel_loop_trans_test.py b/src/psyclone/tests/psyir/transformations/parallel_loop_trans_test.py index 4374ef8dd6..2085138eb9 100644 --- a/src/psyclone/tests/psyir/transformations/parallel_loop_trans_test.py +++ b/src/psyclone/tests/psyir/transformations/parallel_loop_trans_test.py @@ -64,6 +64,14 @@ def _directive(self, children, collapse=None): ''' return OMPParallelDoDirective(children=children, collapse=collapse) + def apply(self, node, options=None, **kwargs): + '''Applies the ParaTrans to the provided node.''' + super().apply(node, options=options, **kwargs) + # Since we create OMPParallelDoDirectives we have to call + # the relevant method. + node.ancestor(OMPParallelDoDirective, + include_self=True).generate_data_clauses() + CODE = ''' subroutine my_sub() @@ -149,6 +157,7 @@ def test_paralooptrans_validate_pure_calls(fortran_reader, fortran_writer): loop = psyir.walk(Loop)[0] trans.apply(loop) code = fortran_writer(psyir) + print(code) assert "!$omp parallel do default(shared) private(i,j,k)" in code @@ -665,6 +674,7 @@ def test_paralooptrans_with_array_privatisation(fortran_reader, logger="psyclone.psyir.transformations"): trans.apply(loop, {"privatise_arrays": True, "force_private": ["ztmp2", "symbol_not_in_loop"]}) + print(fortran_writer(psyir)) assert ("!$omp parallel do default(shared) private(ji,jj,ztmp) " "firstprivate(ztmp2)" in fortran_writer(psyir)) assert ("ParaTrans has been provided with the 'symbol_not_in_loop' symbol " diff --git a/src/psyclone/transformations.py b/src/psyclone/transformations.py index 5ed92afbc3..8f5a432408 100644 --- a/src/psyclone/transformations.py +++ b/src/psyclone/transformations.py @@ -300,6 +300,8 @@ def apply(self, node, options=None, **kwargs): # add the OpenMP loop directive as a child of the node's parent node_parent.addchild(directive, index=node_position) + node.ancestor(OMPParallelDirective, + include_self=True).generate_data_clauses() class LFRicOMPParallelLoopTrans(OMPParallelLoopTrans): @@ -362,6 +364,11 @@ def validate(self, node, options=None): local_options["force"] = True super().validate(node, options=local_options) + def apply(self, node, options=None): + super().apply(node, options=options) + node.ancestor(OMPParallelDirective, + include_self=True).generate_data_clauses() + class GOceanOMPParallelLoopTrans(OMPParallelLoopTrans): @@ -408,6 +415,9 @@ def apply(self, node, options=None): OMPParallelLoopTrans.apply(self, node) + node.ancestor(OMPParallelDirective, + include_self=True).generate_data_clauses() + class LFRicOMPLoopTrans(OMPLoopTrans): From 9625dd1e38bc64c50237898c9e19470c01f4bcf8 Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Thu, 14 May 2026 15:30:32 +0100 Subject: [PATCH 2/6] #3420 Add documentation for the maximal_omp_parallel_region_trans subtransformation option --- .../psyir/transformations/maximal_omp_parallel_region_trans.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/psyclone/psyir/transformations/maximal_omp_parallel_region_trans.py b/src/psyclone/psyir/transformations/maximal_omp_parallel_region_trans.py index a4d51a995d..17dc9ec8e6 100644 --- a/src/psyclone/psyir/transformations/maximal_omp_parallel_region_trans.py +++ b/src/psyclone/psyir/transformations/maximal_omp_parallel_region_trans.py @@ -88,6 +88,9 @@ class MaximalOMPParallelRegionTrans(MaximalRegionTrans): def apply(self, nodes: Union[Node, Schedule, list[Node]], **kwargs): '''Applies the transformation to the nodes provided. + In addition to its own keyword argument options, it also accepts any + options valid for :py:class:`OMPParallelTrans` + :param nodes: can be a single node, a schedule or a list of nodes. ''' super().apply(nodes, **kwargs) From b850318a4670fa688356287016fc85701a44b966 Mon Sep 17 00:00:00 2001 From: LonelyCat124 <3043914+LonelyCat124@users.noreply.github.com.> Date: Fri, 15 May 2026 13:43:47 +0100 Subject: [PATCH 3/6] Fixed not calling generate_data_clauses sometimes --- .../psyir/transformations/omp_loop_trans.py | 4 +- .../transformations/transformations_test.py | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/psyclone/psyir/transformations/omp_loop_trans.py b/src/psyclone/psyir/transformations/omp_loop_trans.py index 8178c8f31c..48eacf5a43 100644 --- a/src/psyclone/psyir/transformations/omp_loop_trans.py +++ b/src/psyclone/psyir/transformations/omp_loop_trans.py @@ -342,8 +342,8 @@ def apply(self, node, options=None, parent = node.parent position = node.position super().apply(node, local_options, reduction_ops=red_ops, **kwargs) - if self.omp_directive == "paralleldo": - node.ancestor(OMPParallelDirective, + if self.omp_directive != "loop": + node.ancestor((OMPParallelDoDirective, OMPDoDirective), include_self=True).generate_data_clauses() # Add reduction clauses to the newly introduced directive directive = parent.children[position] diff --git a/src/psyclone/tests/psyir/transformations/transformations_test.py b/src/psyclone/tests/psyir/transformations/transformations_test.py index 3698f90949..125385be2a 100644 --- a/src/psyclone/tests/psyir/transformations/transformations_test.py +++ b/src/psyclone/tests/psyir/transformations/transformations_test.py @@ -608,6 +608,44 @@ def test_omploop_trans_new_options(sample_psyir): in str(excinfo.value)) +def test_omplooptrans_apply_teamsloop_collapse( + fortran_reader, fortran_writer +): + '''Test the behaviour of the OMPLoopTrans is as expected with + teams loop and collapse''' + code = """ + subroutine x() + integer :: i, j + integer, dimension(100, 100):: arr + do i = 1, 100 + do j = 1, 100 + arr(i, j) = 1 + end do + end do + end subroutine x""" + psyir = fortran_reader.psyir_from_source(code) + looptrans = OMPLoopTrans(omp_directive="teamsloop") + loops = psyir.walk(Loop) + looptrans.apply(loops[0], options={"collapse": True}) + out = fortran_writer(psyir) + correct = """subroutine x() + integer :: i + integer :: j + integer, dimension(100,100) :: arr + + !$omp teams loop collapse(2) default(shared) private(i,j) schedule(auto) + do i = 1, 100, 1 + do j = 1, 100, 1 + arr(i,j) = 1 + enddo + enddo + !$omp end teams loop + +end subroutine x +""" + assert correct == out + + def test_omplooptrans_apply_nowait(fortran_reader, fortran_writer): '''Test the behaviour of the OMPLoopTrans is as expected when we request nowait.''' From b6642f322e8c8379c0dac958170925fd2c3826d8 Mon Sep 17 00:00:00 2001 From: LonelyCat124 <3043914+LonelyCat124@users.noreply.github.com.> Date: Fri, 15 May 2026 13:49:46 +0100 Subject: [PATCH 4/6] fix auto merge error --- src/psyclone/psyir/transformations/omp_parallel_trans.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/psyclone/psyir/transformations/omp_parallel_trans.py b/src/psyclone/psyir/transformations/omp_parallel_trans.py index 03da89bbfc..4aa3610986 100644 --- a/src/psyclone/psyir/transformations/omp_parallel_trans.py +++ b/src/psyclone/psyir/transformations/omp_parallel_trans.py @@ -137,11 +137,9 @@ def apply(self, nodes: list[Node], options=None, **kwargs): :param nodes: list of Nodes to put within parallel region. ''' # TODO #2668: Remove options. - super().apply(nodes, options, **kwargs) + super().apply(nodes, options=options, **kwargs) - def apply(self, node_list, options=None): - super().apply(node_list, options=options) - node_list = self.get_node_list(node_list) + node_list = self.get_node_list(nodes) node_list[0].ancestor(OMPParallelDirective, include_self=True).generate_data_clauses() From 504529232306aed06059084f7424ac6bdcdd0410 Mon Sep 17 00:00:00 2001 From: LonelyCat124 <3043914+LonelyCat124@users.noreply.github.com.> Date: Fri, 15 May 2026 13:54:28 +0100 Subject: [PATCH 5/6] Mistake in transformation --- src/psyclone/psyir/transformations/omp_loop_trans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psyclone/psyir/transformations/omp_loop_trans.py b/src/psyclone/psyir/transformations/omp_loop_trans.py index 48eacf5a43..c13fbae268 100644 --- a/src/psyclone/psyir/transformations/omp_loop_trans.py +++ b/src/psyclone/psyir/transformations/omp_loop_trans.py @@ -342,7 +342,7 @@ def apply(self, node, options=None, parent = node.parent position = node.position super().apply(node, local_options, reduction_ops=red_ops, **kwargs) - if self.omp_directive != "loop": + if self.omp_directive not in ["do", "loop"]: node.ancestor((OMPParallelDoDirective, OMPDoDirective), include_self=True).generate_data_clauses() # Add reduction clauses to the newly introduced directive From 5e1ceb2cac1b6b173996c1a8b6aabf4e74ad4207 Mon Sep 17 00:00:00 2001 From: LonelyCat124 <3043914+LonelyCat124@users.noreply.github.com.> Date: Fri, 15 May 2026 13:57:51 +0100 Subject: [PATCH 6/6] Previous mistake fix --- src/psyclone/psyir/transformations/omp_loop_trans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/psyclone/psyir/transformations/omp_loop_trans.py b/src/psyclone/psyir/transformations/omp_loop_trans.py index c13fbae268..0bb86e38b5 100644 --- a/src/psyclone/psyir/transformations/omp_loop_trans.py +++ b/src/psyclone/psyir/transformations/omp_loop_trans.py @@ -343,7 +343,7 @@ def apply(self, node, options=None, position = node.position super().apply(node, local_options, reduction_ops=red_ops, **kwargs) if self.omp_directive not in ["do", "loop"]: - node.ancestor((OMPParallelDoDirective, OMPDoDirective), + node.ancestor((OMPParallelDoDirective), include_self=True).generate_data_clauses() # Add reduction clauses to the newly introduced directive directive = parent.children[position]