From d8cab8417d873eb686e7fe74707da03742eaa9d9 Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Tue, 14 Apr 2026 09:52:54 +0100 Subject: [PATCH] Clean up CompilerDirective and mark_explicit_privates in transmute scripts --- .../large_scale_cloud/pc2_bm_initiate.py | 39 +++++-------------- .../large_scale_cloud/pc2_bm_initiate.py | 28 +++---------- .../large_scale_cloud/pc2_bm_initiate.py | 39 +++++-------------- 3 files changed, 23 insertions(+), 83 deletions(-) diff --git a/applications/lfric_atm/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py b/applications/lfric_atm/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py index b1286eb05..a6bf07137 100644 --- a/applications/lfric_atm/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py +++ b/applications/lfric_atm/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py @@ -16,11 +16,10 @@ import logging from psyclone.transformations import TransformationError -from psyclone.psyir.nodes import (Loop, CodeBlock) +from psyclone.psyir.nodes import (Loop, UnknownDirective) from transmute_psytrans.transmute_functions import ( set_pure_subroutines, get_outer_loops, - mark_explicit_privates, get_compiler, first_priv_red_init, match_lhs_assignments, @@ -53,22 +52,6 @@ ] -class CompilerDirective(): - """ - Custom compiler directive class to avoid an issue - with fparser.two.Fortran2003.Directive that will - be resolved in an upcoming fparser release. - """ - def __init__(self, directive): - self.directive = directive - - def tofortran(self): - """ - Return directive with prefix - """ - return "!DIR$ " + self.directive - - def trans(psyir): """ Apply OpenMP and Compiler Directives @@ -92,10 +75,6 @@ def trans(psyir): except (TransformationError, IndexError) as err: logging.warning("Parallelisation of the 1st region failed: %s", err) - # Declare private symbols for the last loop nest explicitly, - # PSyclone misses one - mark_explicit_privates(outer_loops[2], private_variables) - # Parallelise the second region and insert compiler directives # Add redundant variable initialisation to work around a known # PSyclone issue when using CCE @@ -109,16 +88,14 @@ def trans(psyir): # Insert before OpenMP directives to avoid PSyclone errors if get_compiler() == "cce": for loop in outer_loops[2].walk(Loop)[3:5]: - cblock = CodeBlock([CompilerDirective("NOFISSION")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" NOFISSION", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[13:16]: - cblock = CodeBlock([CompilerDirective("IVDEP")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" IVDEP", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[2:7]: # Check if any eligible variables appear in subroutine @@ -129,7 +106,8 @@ def trans(psyir): options = {} if len(ignore_deps_vars) > 0: options["ignore_dependencies_for"] = ignore_deps_vars - OMP_DO_LOOP_TRANS_STATIC.apply(loop, options) + OMP_DO_LOOP_TRANS_STATIC.apply(loop, options=options, + force_private=private_variables) for loop in outer_loops[2].walk(Loop)[8:13:2]: # Check if any eligible variables appear on the LHS of @@ -139,7 +117,8 @@ def trans(psyir): if len(ignore_deps_vars) > 0: options["ignore_dependencies_for"] = ignore_deps_vars - OMP_DO_LOOP_TRANS_STATIC.apply(loop, options) + OMP_DO_LOOP_TRANS_STATIC.apply(loop, options=options, + force_private=private_variables) except (TransformationError, IndexError) as err: logging.warning("Parallelisation of the 2nd region failed: %s", err) diff --git a/applications/lfric_atm/optimisation/meto-ex1a/transmute/large_scale_cloud/pc2_bm_initiate.py b/applications/lfric_atm/optimisation/meto-ex1a/transmute/large_scale_cloud/pc2_bm_initiate.py index 054d97ac5..a6bf07137 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/transmute/large_scale_cloud/pc2_bm_initiate.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/transmute/large_scale_cloud/pc2_bm_initiate.py @@ -16,7 +16,7 @@ import logging from psyclone.transformations import TransformationError -from psyclone.psyir.nodes import (Loop, CodeBlock) +from psyclone.psyir.nodes import (Loop, UnknownDirective) from transmute_psytrans.transmute_functions import ( set_pure_subroutines, get_outer_loops, @@ -52,22 +52,6 @@ ] -class CompilerDirective(): - """ - Custom compiler directive class to avoid an issue - with fparser.two.Fortran2003.Directive that will - be resolved in an upcoming fparser release. - """ - def __init__(self, directive): - self.directive = directive - - def tofortran(self): - """ - Return directive with prefix - """ - return "!DIR$ " + self.directive - - def trans(psyir): """ Apply OpenMP and Compiler Directives @@ -104,16 +88,14 @@ def trans(psyir): # Insert before OpenMP directives to avoid PSyclone errors if get_compiler() == "cce": for loop in outer_loops[2].walk(Loop)[3:5]: - cblock = CodeBlock([CompilerDirective("NOFISSION")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" NOFISSION", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[13:16]: - cblock = CodeBlock([CompilerDirective("IVDEP")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" IVDEP", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[2:7]: # Check if any eligible variables appear in subroutine diff --git a/applications/ngarch/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py b/applications/ngarch/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py index b1286eb05..a6bf07137 100644 --- a/applications/ngarch/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py +++ b/applications/ngarch/optimisation/esnz-cascade/transmute/large_scale_cloud/pc2_bm_initiate.py @@ -16,11 +16,10 @@ import logging from psyclone.transformations import TransformationError -from psyclone.psyir.nodes import (Loop, CodeBlock) +from psyclone.psyir.nodes import (Loop, UnknownDirective) from transmute_psytrans.transmute_functions import ( set_pure_subroutines, get_outer_loops, - mark_explicit_privates, get_compiler, first_priv_red_init, match_lhs_assignments, @@ -53,22 +52,6 @@ ] -class CompilerDirective(): - """ - Custom compiler directive class to avoid an issue - with fparser.two.Fortran2003.Directive that will - be resolved in an upcoming fparser release. - """ - def __init__(self, directive): - self.directive = directive - - def tofortran(self): - """ - Return directive with prefix - """ - return "!DIR$ " + self.directive - - def trans(psyir): """ Apply OpenMP and Compiler Directives @@ -92,10 +75,6 @@ def trans(psyir): except (TransformationError, IndexError) as err: logging.warning("Parallelisation of the 1st region failed: %s", err) - # Declare private symbols for the last loop nest explicitly, - # PSyclone misses one - mark_explicit_privates(outer_loops[2], private_variables) - # Parallelise the second region and insert compiler directives # Add redundant variable initialisation to work around a known # PSyclone issue when using CCE @@ -109,16 +88,14 @@ def trans(psyir): # Insert before OpenMP directives to avoid PSyclone errors if get_compiler() == "cce": for loop in outer_loops[2].walk(Loop)[3:5]: - cblock = CodeBlock([CompilerDirective("NOFISSION")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" NOFISSION", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[13:16]: - cblock = CodeBlock([CompilerDirective("IVDEP")], - CodeBlock.Structure.STATEMENT) + dir = UnknownDirective(" IVDEP", "DIR") insert_at = loop.parent.children.index(loop) - loop.parent.children.insert(insert_at, cblock) + loop.parent.children.insert(insert_at, dir) for loop in outer_loops[2].walk(Loop)[2:7]: # Check if any eligible variables appear in subroutine @@ -129,7 +106,8 @@ def trans(psyir): options = {} if len(ignore_deps_vars) > 0: options["ignore_dependencies_for"] = ignore_deps_vars - OMP_DO_LOOP_TRANS_STATIC.apply(loop, options) + OMP_DO_LOOP_TRANS_STATIC.apply(loop, options=options, + force_private=private_variables) for loop in outer_loops[2].walk(Loop)[8:13:2]: # Check if any eligible variables appear on the LHS of @@ -139,7 +117,8 @@ def trans(psyir): if len(ignore_deps_vars) > 0: options["ignore_dependencies_for"] = ignore_deps_vars - OMP_DO_LOOP_TRANS_STATIC.apply(loop, options) + OMP_DO_LOOP_TRANS_STATIC.apply(loop, options=options, + force_private=private_variables) except (TransformationError, IndexError) as err: logging.warning("Parallelisation of the 2nd region failed: %s", err)