From 2a71426dbc0df937b3e2ed5796aa343bf300597e Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Tue, 9 Jun 2026 09:40:37 +0100 Subject: [PATCH 1/2] Changes needed to support psyclone 3.3 Co-authored-by: Andrew Porter Co-authored-by: Aidan Chalk <3043914+LonelyCat124@users.noreply.github.com> --- .../esnz-cascade/psykal/global.py | 6 +- .../optimisation/meto-ex1a/psykal/global.py | 6 +- .../esnz-cascade/psykal/global.py | 6 +- .../optimisation/meto-ex1a/psykal/global.py | 6 +- .../core/top_level/ukca_main1-ukca_main1.py | 7 ++- .../core/aerosols/glomap/ukca_aero_ctl.py | 11 ++-- .../chemistry/ukca_chemistry_ctl_full_mod.py | 31 +++++----- .../psykal/algorithm/casim_alg_mod.py | 7 ++- .../large_scale_cloud/pc2_bm_initiate.py | 39 +++--------- .../psykal/algorithm/casim_alg_mod.py | 7 ++- .../physics_constants_mod.py | 26 +++++--- .../psykal/algorithm/skeb_main_alg_mod.py | 26 +++++--- .../psykal/algorithm/spt_main_alg_mod.py | 27 +++++--- .../large_scale_cloud/pc2_bm_initiate.py | 39 +++--------- .../core/top_level/ukca_main1-ukca_main1.py | 7 ++- .../core/aerosols/glomap/ukca_aero_ctl.py | 11 ++-- .../chemistry/ukca_chemistry_ctl_full_mod.py | 34 +++++------ .../meto-ex1a/algorithm/casim_alg_mod.py | 7 ++- .../large_scale_cloud/pc2_bm_initiate.py | 39 +++--------- .../transmute_psytrans/transmute_functions.py | 61 +++---------------- .../source/algorithm/jules_imp_alg_mod.x90 | 2 +- .../diagnostics/jules_imp_diags_mod.x90 | 2 +- .../diagnostics/jules_snow_diags_mod.x90 | 2 +- .../diagnostics/jules_soil_diags_mod.x90 | 2 +- .../source/algorithm/bl_imp_alg_mod.x90 | 2 +- .../semi_implicit_timestep_alg_mod.X90 | 3 +- .../common/map_w2_to_sh_w2_alg_mod.x90 | 2 +- 27 files changed, 169 insertions(+), 249 deletions(-) diff --git a/applications/adjoint_tests/optimisation/esnz-cascade/psykal/global.py b/applications/adjoint_tests/optimisation/esnz-cascade/psykal/global.py index d9174a028..ba3947014 100644 --- a/applications/adjoint_tests/optimisation/esnz-cascade/psykal/global.py +++ b/applications/adjoint_tests/optimisation/esnz-cascade/psykal/global.py @@ -13,8 +13,8 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule # NOTE: Whilst gen_*_lookup_code kernels are called from psy-lite, @@ -63,7 +63,7 @@ def openmp_parallelise_loops_adj(psyir): :param psyir: the PSyIR of the PSy-layer. :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` ''' - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object diff --git a/applications/adjoint_tests/optimisation/meto-ex1a/psykal/global.py b/applications/adjoint_tests/optimisation/meto-ex1a/psykal/global.py index d9174a028..ba3947014 100644 --- a/applications/adjoint_tests/optimisation/meto-ex1a/psykal/global.py +++ b/applications/adjoint_tests/optimisation/meto-ex1a/psykal/global.py @@ -13,8 +13,8 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule # NOTE: Whilst gen_*_lookup_code kernels are called from psy-lite, @@ -63,7 +63,7 @@ def openmp_parallelise_loops_adj(psyir): :param psyir: the PSyIR of the PSy-layer. :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` ''' - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object diff --git a/applications/jedi_lfric_tests/optimisation/esnz-cascade/psykal/global.py b/applications/jedi_lfric_tests/optimisation/esnz-cascade/psykal/global.py index d9174a028..ba3947014 100644 --- a/applications/jedi_lfric_tests/optimisation/esnz-cascade/psykal/global.py +++ b/applications/jedi_lfric_tests/optimisation/esnz-cascade/psykal/global.py @@ -13,8 +13,8 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule # NOTE: Whilst gen_*_lookup_code kernels are called from psy-lite, @@ -63,7 +63,7 @@ def openmp_parallelise_loops_adj(psyir): :param psyir: the PSyIR of the PSy-layer. :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` ''' - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object diff --git a/applications/jedi_lfric_tests/optimisation/meto-ex1a/psykal/global.py b/applications/jedi_lfric_tests/optimisation/meto-ex1a/psykal/global.py index d9174a028..ba3947014 100644 --- a/applications/jedi_lfric_tests/optimisation/meto-ex1a/psykal/global.py +++ b/applications/jedi_lfric_tests/optimisation/meto-ex1a/psykal/global.py @@ -13,8 +13,8 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule # NOTE: Whilst gen_*_lookup_code kernels are called from psy-lite, @@ -63,7 +63,7 @@ def openmp_parallelise_loops_adj(psyir): :param psyir: the PSyIR of the PSy-layer. :type psyir: :py:class:`psyclone.psyir.nodes.FileContainer` ''' - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object diff --git a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py index 1d423f7ca..8afb0c959 100644 --- a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py +++ b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py @@ -48,7 +48,7 @@ from psyclone.psyir.nodes import ( Assignment, Reference, Literal, IfBlock, Call) from psyclone.psyir.symbols import ( - INTEGER_TYPE, RoutineSymbol, CHARACTER_TYPE) + ScalarType, RoutineSymbol) # Transformation Parameters # ========================= @@ -97,12 +97,13 @@ def trans(psyir): if assign.rhs.name == match_rhs: if chunk_size is not None: assign.rhs.replace_with( - Literal(str(chunk_size), INTEGER_TYPE)) + Literal(str(chunk_size), + ScalarType.integer_type())) found = assign # Insert print call if found: print_call = Call() print_call.addchild(Reference(RoutineSymbol("umPrint"))) - print_call.addchild(Literal(message_text, CHARACTER_TYPE)) + print_call.addchild(Literal(message_text, ScalarType.character_type())) found.parent.addchild(print_call, index=found.position+1) diff --git a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py index 5126827f7..7d517a400 100644 --- a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py +++ b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py @@ -25,8 +25,7 @@ PSyclone as of version 3.1 is not capable of fully determining which variables need to be set PRIVATE, since many of these are arrays (and using `privatise_arrays` has not been found to work). The - suggested fix from STFC is to use `explicitly_private_symbols`, which is - captured in `mark_explicit_privates` from `transmute_functions`. + suggested fix from STFC is to use the `force_private` option. The workaround is to set anything beginning in `seg_` to PRIVATE, since these variables are the ones used in the chunking and therefore need to be private to each thread. @@ -42,7 +41,6 @@ from psyclone.psyir.symbols import DataSymbol from transmute_psytrans.transmute_functions import ( first_priv_red_init, - mark_explicit_privates, ) OMP_TRANS = OMPParallelLoopTrans() @@ -74,7 +72,7 @@ def trans(psyir): # some non-PURE subroutines called within this loop "force": True, # several WRITE statements used for diagnostics - "node-type-check": False, + "node_type_check": False, } # For the coarse-grained approach, we have *one* loop we want to work on # - the loop over segments. This gives almost complete coverage for GLOMAP, @@ -84,13 +82,12 @@ def trans(psyir): # identify the loop in question - the loop over segments if hasattr(loop.stop_expr, "name") and loop.stop_expr.name in ["nseg"]: try: + # set some symbols to be PRIVATE symbols_to_add = get_private_symbols_from_name(loop, "seg_") # add a few more symbols that don't fit this syntax symbols_to_add.extend( ["i_end", "i_end_cp", "j", "nbs_index", "y"] ) - # set some symbols to be PRIVATE - mark_explicit_privates(loop, symbols_to_add) # CCE compiler fix - initialise some FIRSTPRIVATE variables first_priv_red_init( loop, @@ -98,7 +95,7 @@ def trans(psyir): insert_at_start=True, ) OMPParallelLoopTrans(omp_schedule="dynamic").apply( - loop, options=opts + loop, force_private=symbols_to_add, **opts ) except TransformationError as err: diff --git a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py index fb35cc63e..21c01eb67 100644 --- a/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py +++ b/applications/lfric_atm/optimisation/azngarch-sandbox/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py @@ -134,6 +134,7 @@ DataSymbol, ImportInterface, RoutineSymbol, + ScalarType, Symbol, ) from psyclone.psyir.transformations.reference2arrayrange_trans import ( @@ -244,7 +245,7 @@ def trans(psyir): desired_chunk_size_var = routine.symbol_table.find_or_create_tag( "desired_chunk_size", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) if desired_chunk_size is None: assign_desired_chunk_size = Assignment.create( @@ -253,7 +254,7 @@ def trans(psyir): else: assign_desired_chunk_size = Assignment.create( Reference(desired_chunk_size_var), - Literal(str(desired_chunk_size), INTEGER_TYPE)) + Literal(str(desired_chunk_size), ScalarType.integer_type())) # Introduce full-domain array for each ASAD array # ----------------------------------------------- @@ -266,18 +267,18 @@ def trans(psyir): bounds.append(IntrinsicCall.create( IntrinsicCall.Intrinsic.SIZE, [Reference(Symbol(var_name)), - ("dim", Literal(str(i), INTEGER_TYPE))])) + ("dim", Literal(str(i), ScalarType.integer_type()))])) # Create variables new_var = routine.symbol_table.find_or_create_tag( "full_" + var_name, symbol_type=DataSymbol, - datatype=ArrayType(REAL_TYPE, bounds)) + datatype=ArrayType(ScalarType.real_type(), bounds)) full_vars[var_name] = (bounds, new_var) # Add initialiser if var_name in refs_before: initialiser = Assignment.create( ArrayReference.create(new_var, [":" for b in bounds]), - Literal("0.0", REAL_TYPE)) + Literal("0.0", ScalarType.real_type())) routine.addchild(initialiser, index=0) # Replace each use of ASAD array with full-domain counterpart @@ -311,15 +312,15 @@ def trans(psyir): chunk_begin_var = routine.symbol_table.find_or_create_tag( "chunk_begin", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) chunk_end_var = routine.symbol_table.find_or_create_tag( "chunk_end", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) chunk_size_var = routine.symbol_table.find_or_create_tag( "chunk_size", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) # Create assignment for chunk_end minop = IntrinsicCall.create( @@ -331,7 +332,7 @@ def trans(psyir): BinaryOperation.create( BinaryOperation.Operator.SUB, Reference(desired_chunk_size_var), - Literal("1", INTEGER_TYPE)))]) + Literal("1", ScalarType.integer_type())))]) assign_chunk_end = Assignment.create(Reference(chunk_end_var), minop) # Create assignment for chunk_size @@ -339,7 +340,7 @@ def trans(psyir): BinaryOperation.Operator.SUB, BinaryOperation.create( BinaryOperation.Operator.ADD, - Literal("1", INTEGER_TYPE), + Literal("1", ScalarType.integer_type()), Reference(chunk_end_var)), Reference(chunk_begin_var)) assign_chunk_size = Assignment.create(Reference(chunk_size_var), @@ -348,7 +349,7 @@ def trans(psyir): # Create chunking loop loop = Loop(variable=chunk_begin_var) asad_call.replace_with(loop) - loop.children = [Literal("1", INTEGER_TYPE), + loop.children = [Literal("1", ScalarType.integer_type()), Reference(array_size_var), Reference(desired_chunk_size_var), Schedule(parent=loop, children=[asad_call])] @@ -357,7 +358,7 @@ def trans(psyir): for var_name in refs_before: (bounds, full_var) = full_vars[var_name] var_sym = DataSymbol( - var_name, datatype=ArrayType(REAL_TYPE, bounds)) + var_name, datatype=ArrayType(ScalarType.real_type(), bounds)) assign_full_var = Assignment.create( ArrayReference.create(var_sym, [":" for b in bounds]), ArrayReference.create(full_var, [":" for b in bounds])) @@ -367,7 +368,7 @@ def trans(psyir): for var_name in refs_after: (bounds, full_var) = full_vars[var_name] var_sym = DataSymbol( - var_name, datatype=ArrayType(REAL_TYPE, bounds)) + var_name, datatype=ArrayType(ScalarType.real_type(), bounds)) assign_full_var = Assignment.create( ArrayReference.create(full_var, [":" for b in bounds]), ArrayReference.create(var_sym, [":" for b in bounds])) @@ -381,7 +382,7 @@ def trans(psyir): # Update references to arrays for ref in loop.loop_body.walk(ArrayReference): if ref.name in asad_vars.keys(): - ref.indices[0].start = Literal("1", INTEGER_TYPE) + ref.indices[0].start = Literal("1", ScalarType.integer_type()) ref.indices[0].stop = Reference(chunk_size_var) else: ref.indices[0].start = Reference(chunk_begin_var) @@ -396,7 +397,7 @@ def trans(psyir): print_call = Call() print_call.addchild(Reference(RoutineSymbol("umPrint"))) - print_call.addchild(Literal(message_text, CHARACTER_TYPE)) + print_call.addchild(Literal(message_text, ScalarType.character_type())) loop.parent.addchild(print_call, index=loop.position) # Assign desired chunk size diff --git a/applications/lfric_atm/optimisation/esnz-cascade/psykal/algorithm/casim_alg_mod.py b/applications/lfric_atm/optimisation/esnz-cascade/psykal/algorithm/casim_alg_mod.py index c0a61b30c..eab62c447 100644 --- a/applications/lfric_atm/optimisation/esnz-cascade/psykal/algorithm/casim_alg_mod.py +++ b/applications/lfric_atm/optimisation/esnz-cascade/psykal/algorithm/casim_alg_mod.py @@ -13,8 +13,9 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) + +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule @@ -40,7 +41,7 @@ def trans(psyir): # casim_kernel_type or as psyclone knows is in it's representaion # invoke_1_casim_kernel_type - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object 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/psykal/algorithm/casim_alg_mod.py b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/casim_alg_mod.py index c0a61b30c..eab62c447 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/casim_alg_mod.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/casim_alg_mod.py @@ -13,8 +13,9 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) + +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans from psyclone.psyGen import InvokeSchedule @@ -40,7 +41,7 @@ def trans(psyir): # casim_kernel_type or as psyclone knows is in it's representaion # invoke_1_casim_kernel_type - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the InvokeSchedule in the PSyIR object diff --git a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/runtime_constants/physics_constants_mod.py b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/runtime_constants/physics_constants_mod.py index 827b59572..4c9200618 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/runtime_constants/physics_constants_mod.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/runtime_constants/physics_constants_mod.py @@ -19,12 +19,22 @@ from psyclone.psyir.nodes import Directive, Loop, Routine from psyclone.psyir.transformations import ( ACCKernelsTrans, TransformationError, OMPTargetTrans, - OMPDeclareTargetTrans) + OMPDeclareTargetTrans, OMPParallelTrans) from psyclone.transformations import ( - Dynamo0p3ColourTrans, Dynamo0p3OMPLoopTrans, - Dynamo0p3RedundantComputationTrans, OMPParallelTrans, - ACCParallelTrans, ACCLoopTrans, ACCRoutineTrans, - OMPLoopTrans) + LFRicColourTrans, LFRicOMPLoopTrans, + ACCParallelTrans, ACCRoutineTrans, OMPLoopTrans) +try: + from psyclone.psyir.transformations import ACCLoopTrans +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ACCLoopTrans +try: + from psyclone.domain.lfric.transformations import ( + LFRicRedundantComputationTrans) +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ( + LFRicRedundantComputationTrans) from psyclone.domain.common.transformations import KernelModuleInlineTrans @@ -56,9 +66,9 @@ def trans(psyir): ''' inline_trans = KernelModuleInlineTrans() - rtrans = Dynamo0p3RedundantComputationTrans() - ctrans = Dynamo0p3ColourTrans() - otrans = Dynamo0p3OMPLoopTrans() + rtrans = LFRicRedundantComputationTrans() + ctrans = LFRicColourTrans() + otrans = LFRicOMPLoopTrans() const = LFRicConstants() cpu_parallel = OMPParallelTrans() diff --git a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/skeb_main_alg_mod.py b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/skeb_main_alg_mod.py index 1553a56d3..2b1c82775 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/skeb_main_alg_mod.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/skeb_main_alg_mod.py @@ -19,12 +19,22 @@ from psyclone.psyir.nodes import Directive, Loop, Routine from psyclone.psyir.transformations import ( ACCKernelsTrans, TransformationError, OMPTargetTrans, - OMPDeclareTargetTrans) + OMPDeclareTargetTrans, OMPParallelTrans) from psyclone.transformations import ( - Dynamo0p3ColourTrans, Dynamo0p3OMPLoopTrans, - Dynamo0p3RedundantComputationTrans, OMPParallelTrans, - ACCParallelTrans, ACCLoopTrans, ACCRoutineTrans, - OMPLoopTrans) + LFRicColourTrans, LFRicOMPLoopTrans, + ACCParallelTrans, ACCRoutineTrans, OMPLoopTrans) +try: + from psyclone.psyir.transformations import ACCLoopTrans +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ACCLoopTrans +try: + from psyclone.domain.lfric.transformations import ( + LFRicRedundantComputationTrans) +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ( + LFRicRedundantComputationTrans) from psyclone.domain.common.transformations import KernelModuleInlineTrans @@ -54,9 +64,9 @@ def trans(psyir): ''' inline_trans = KernelModuleInlineTrans() - rtrans = Dynamo0p3RedundantComputationTrans() - ctrans = Dynamo0p3ColourTrans() - otrans = Dynamo0p3OMPLoopTrans() + rtrans = LFRicRedundantComputationTrans() + ctrans = LFRicColourTrans() + otrans = LFRicOMPLoopTrans() const = LFRicConstants() cpu_parallel = OMPParallelTrans() diff --git a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/spt_main_alg_mod.py b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/spt_main_alg_mod.py index e8d1d7bfd..24fb52d83 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/spt_main_alg_mod.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/psykal/algorithm/spt_main_alg_mod.py @@ -19,12 +19,23 @@ from psyclone.psyir.nodes import Directive, Loop, Routine from psyclone.psyir.transformations import ( ACCKernelsTrans, TransformationError, OMPTargetTrans, - OMPDeclareTargetTrans) + OMPDeclareTargetTrans, OMPParallelTrans) from psyclone.transformations import ( - Dynamo0p3ColourTrans, Dynamo0p3OMPLoopTrans, - Dynamo0p3RedundantComputationTrans, OMPParallelTrans, - ACCParallelTrans, ACCLoopTrans, ACCRoutineTrans, - OMPLoopTrans) + LFRicColourTrans, LFRicOMPLoopTrans, + ACCParallelTrans, ACCRoutineTrans, OMPLoopTrans) + +try: + from psyclone.psyir.transformations import ACCLoopTrans +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ACCLoopTrans +try: + from psyclone.domain.lfric.transformations import ( + LFRicRedundantComputationTrans) +except ImportError: + # Support for psyclone < 3.3 + from psyclone.transformations import ( + LFRicRedundantComputationTrans) from psyclone.domain.common.transformations import KernelModuleInlineTrans @@ -61,9 +72,9 @@ def trans(psyir): ''' inline_trans = KernelModuleInlineTrans() - rtrans = Dynamo0p3RedundantComputationTrans() - ctrans = Dynamo0p3ColourTrans() - otrans = Dynamo0p3OMPLoopTrans() + rtrans = LFRicRedundantComputationTrans() + ctrans = LFRicColourTrans() + otrans = LFRicOMPLoopTrans() const = LFRicConstants() cpu_parallel = OMPParallelTrans() 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 b1286eb05..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,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/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py index 1d423f7ca..8afb0c959 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/control/core/top_level/ukca_main1-ukca_main1.py @@ -48,7 +48,7 @@ from psyclone.psyir.nodes import ( Assignment, Reference, Literal, IfBlock, Call) from psyclone.psyir.symbols import ( - INTEGER_TYPE, RoutineSymbol, CHARACTER_TYPE) + ScalarType, RoutineSymbol) # Transformation Parameters # ========================= @@ -97,12 +97,13 @@ def trans(psyir): if assign.rhs.name == match_rhs: if chunk_size is not None: assign.rhs.replace_with( - Literal(str(chunk_size), INTEGER_TYPE)) + Literal(str(chunk_size), + ScalarType.integer_type())) found = assign # Insert print call if found: print_call = Call() print_call.addchild(Reference(RoutineSymbol("umPrint"))) - print_call.addchild(Literal(message_text, CHARACTER_TYPE)) + print_call.addchild(Literal(message_text, ScalarType.character_type())) found.parent.addchild(print_call, index=found.position+1) diff --git a/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py index fa3efe0a8..05b410b49 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/aerosols/glomap/ukca_aero_ctl.py @@ -25,8 +25,7 @@ PSyclone as of version 3.1 is not capable of fully determining which variables need to be set PRIVATE, since many of these are arrays (and using `privatise_arrays` has not been found to work). The - suggested fix from STFC is to use `explicitly_private_symbols`, which is - captured in `mark_explicit_privates` from `transmute_functions`. + suggested fix from STFC is to use the `force_private` option. The workaround is to set anything beginning in `seg_` to PRIVATE, since these variables are the ones used in the chunking and therefore need to be private to each thread. @@ -42,7 +41,6 @@ from psyclone.psyir.symbols import DataSymbol from transmute_psytrans.transmute_functions import ( first_priv_red_init, - mark_explicit_privates, ) OMP_TRANS = OMPParallelLoopTrans() @@ -74,7 +72,7 @@ def trans(psyir): # some non-PURE subroutines called within this loop "force": True, # several WRITE statements used for diagnostics - "node-type-check": False, + "node_type_check": False, } # For the coarse-grained approach, we have *one* loop we want to work on # - the loop over segments. This gives almost complete coverage for GLOMAP, @@ -84,13 +82,12 @@ def trans(psyir): # identify the loop in question - the loop over segments if hasattr(loop.stop_expr, "name") and loop.stop_expr.name in ["nseg"]: try: + # Manually select private symbols symbols_to_add = get_private_symbols_from_name(loop, "seg_") # add a few more symbols that don't fit this syntax symbols_to_add.extend( ["i_end", "i_end_cp", "j", "nbs_index", "y"] ) - # set some symbols to be PRIVATE - mark_explicit_privates(loop, symbols_to_add) # CCE compiler fix - initialise some FIRSTPRIVATE variables first_priv_red_init( loop, @@ -120,7 +117,7 @@ def trans(psyir): insert_at_start=True, ) OMPParallelLoopTrans(omp_schedule="dynamic").apply( - loop, options=opts + loop, force_private=symbols_to_add, **opts ) except TransformationError as err: diff --git a/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py index 364c23851..4de2e18a1 100644 --- a/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py +++ b/applications/lfric_atm/optimisation/meto-ex1a/transmute/science/ukca/src/science/core/chemistry/ukca_chemistry_ctl_full_mod.py @@ -127,14 +127,12 @@ UnaryOperation, ) from psyclone.psyir.symbols import ( - CHARACTER_TYPE, - INTEGER_TYPE, - REAL_TYPE, ArrayType, ContainerSymbol, DataSymbol, ImportInterface, RoutineSymbol, + ScalarType, Symbol, ) from psyclone.psyir.transformations.reference2arrayrange_trans import ( @@ -243,7 +241,7 @@ def trans(psyir): desired_chunk_size_var = routine.symbol_table.find_or_create_tag( "desired_chunk_size", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) if desired_chunk_size is None: assign_desired_chunk_size = Assignment.create( @@ -252,7 +250,7 @@ def trans(psyir): else: assign_desired_chunk_size = Assignment.create( Reference(desired_chunk_size_var), - Literal(str(desired_chunk_size), INTEGER_TYPE)) + Literal(str(desired_chunk_size), ScalarType.integer_type())) # Introduce full-domain array for each ASAD array # ----------------------------------------------- @@ -265,18 +263,18 @@ def trans(psyir): bounds.append(IntrinsicCall.create( IntrinsicCall.Intrinsic.SIZE, [Reference(Symbol(var_name)), - ("dim", Literal(str(i), INTEGER_TYPE))])) + ("dim", Literal(str(i), ScalarType.integer_type()))])) # Create variables new_var = routine.symbol_table.find_or_create_tag( "full_" + var_name, symbol_type=DataSymbol, - datatype=ArrayType(REAL_TYPE, bounds)) + datatype=ArrayType(ScalarType.real_type(), bounds)) full_vars[var_name] = (bounds, new_var) # Add initialiser if var_name in refs_before: initialiser = Assignment.create( ArrayReference.create(new_var, [":" for b in bounds]), - Literal("0.0", REAL_TYPE)) + Literal("0.0", ScalarType.real_type())) routine.addchild(initialiser, index=0) # Replace each use of ASAD array with full-domain counterpart @@ -310,15 +308,15 @@ def trans(psyir): chunk_begin_var = routine.symbol_table.find_or_create_tag( "chunk_begin", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) chunk_end_var = routine.symbol_table.find_or_create_tag( "chunk_end", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) chunk_size_var = routine.symbol_table.find_or_create_tag( "chunk_size", symbol_type=DataSymbol, - datatype=INTEGER_TYPE) + datatype=ScalarType.integer_type()) # Create assignment for chunk_end minop = IntrinsicCall.create( @@ -330,7 +328,7 @@ def trans(psyir): BinaryOperation.create( BinaryOperation.Operator.SUB, Reference(desired_chunk_size_var), - Literal("1", INTEGER_TYPE)))]) + Literal("1", ScalarType.integer_type())))]) assign_chunk_end = Assignment.create(Reference(chunk_end_var), minop) # Create assignment for chunk_size @@ -338,7 +336,7 @@ def trans(psyir): BinaryOperation.Operator.SUB, BinaryOperation.create( BinaryOperation.Operator.ADD, - Literal("1", INTEGER_TYPE), + Literal("1", ScalarType.integer_type()), Reference(chunk_end_var)), Reference(chunk_begin_var)) assign_chunk_size = Assignment.create(Reference(chunk_size_var), @@ -347,7 +345,7 @@ def trans(psyir): # Create chunking loop loop = Loop(variable=chunk_begin_var) asad_call.replace_with(loop) - loop.children = [Literal("1", INTEGER_TYPE), + loop.children = [Literal("1", ScalarType.integer_type()), Reference(array_size_var), Reference(desired_chunk_size_var), Schedule(parent=loop, children=[asad_call])] @@ -356,7 +354,7 @@ def trans(psyir): for var_name in refs_before: (bounds, full_var) = full_vars[var_name] var_sym = DataSymbol( - var_name, datatype=ArrayType(REAL_TYPE, bounds)) + var_name, datatype=ArrayType(ScalarType.real_type(), bounds)) assign_full_var = Assignment.create( ArrayReference.create(var_sym, [":" for b in bounds]), ArrayReference.create(full_var, [":" for b in bounds])) @@ -366,7 +364,7 @@ def trans(psyir): for var_name in refs_after: (bounds, full_var) = full_vars[var_name] var_sym = DataSymbol( - var_name, datatype=ArrayType(REAL_TYPE, bounds)) + var_name, datatype=ArrayType(ScalarType.real_type(), bounds)) assign_full_var = Assignment.create( ArrayReference.create(full_var, [":" for b in bounds]), ArrayReference.create(var_sym, [":" for b in bounds])) @@ -380,7 +378,7 @@ def trans(psyir): # Update references to arrays for ref in loop.loop_body.walk(ArrayReference): if ref.name in asad_vars.keys(): - ref.indices[0].start = Literal("1", INTEGER_TYPE) + ref.indices[0].start = Literal("1", ScalarType.integer_type()) ref.indices[0].stop = Reference(chunk_size_var) else: ref.indices[0].start = Reference(chunk_begin_var) @@ -395,7 +393,7 @@ def trans(psyir): print_call = Call() print_call.addchild(Reference(RoutineSymbol("umPrint"))) - print_call.addchild(Literal(message_text, CHARACTER_TYPE)) + print_call.addchild(Literal(message_text, ScalarType.character_type())) loop.parent.addchild(print_call, index=loop.position) # Assign desired chunk size diff --git a/applications/lfric_coupled/optimisation/meto-ex1a/algorithm/casim_alg_mod.py b/applications/lfric_coupled/optimisation/meto-ex1a/algorithm/casim_alg_mod.py index 0175299ea..19a40d2dd 100644 --- a/applications/lfric_coupled/optimisation/meto-ex1a/algorithm/casim_alg_mod.py +++ b/applications/lfric_coupled/optimisation/meto-ex1a/algorithm/casim_alg_mod.py @@ -13,8 +13,9 @@ from psyclone_tools import (redundant_computation_setval, colour_loops, view_transformed_schedule) -from psyclone.transformations import (Dynamo0p3OMPLoopTrans, - OMPParallelTrans) + +from psyclone.psyir.transformations import OMPParallelTrans +from psyclone.transformations import LFRicOMPLoopTrans def trans(psy): @@ -34,7 +35,7 @@ def trans(psy): # such as this where we want to avoid the subroutine # casim_kernel_type or as psyclone knows is in it's representaion # invoke_1_casim_kernel_type - otrans = Dynamo0p3OMPLoopTrans() + otrans = LFRicOMPLoopTrans() oregtrans = OMPParallelTrans() # Loop over all the Invokes in the PSy object for invoke in psy.invokes.invoke_list: 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) diff --git a/interfaces/build/transmute_psytrans/transmute_functions.py b/interfaces/build/transmute_psytrans/transmute_functions.py index b206feda7..a1eab8d9b 100644 --- a/interfaces/build/transmute_psytrans/transmute_functions.py +++ b/interfaces/build/transmute_psytrans/transmute_functions.py @@ -32,13 +32,12 @@ RoutineSymbol, ImportInterface, UnsupportedFortranType, - INTEGER_TYPE, - CHARACTER_TYPE, + ScalarType ) +from psyclone.psyir.transformations import OMPParallelTrans from psyclone.transformations import ( OMPLoopTrans, TransformationError, - OMPParallelTrans, OMPParallelLoopTrans, ) @@ -284,50 +283,6 @@ def omp_do_for_heavy_loops( logging.warning("Failed OMP on %s-loop: %s", loop_var, err) -def mark_explicit_privates(node, names): - """ - Add symbols named in `names` to `node.explicitly_private_symbols`. - - Generic version of the original helper. Works with any PSyIR node that: - - has a `scope.symbol_table`, and - - provides an `explicitly_private_symbols` set-like attribute. - - Warns if a requested symbol cannot be found or is not a DataSymbol. - """ - # Be forgiving so this helper can be used beyond Loop nodes - scope = getattr(node, "scope", None) - symtab = getattr(scope, "symbol_table", None) - if symtab is None: - logging.warning( - "[warn] cannot set explicit privates:" - "node has no scope.symbol_table." - ) - return - - if not hasattr(node, "explicitly_private_symbols"): - logging.warning( - "[warn] cannot set explicit privates:" - " node has no 'explicitly_private_symbols'." - ) - return - - for name in names: - try: - sym = symtab.lookup(name) - if isinstance(sym, DataSymbol): - node.explicitly_private_symbols.add(sym) - else: - logging.warning( - " [warn] private symbol '%s' is not a DataSymbol.", - name, - ) - except KeyError: - logging.warning( - "[warn] private symbol '%s' not found in symbol table.", - name, - ) - - def get_compiler(): """ Best-effort compiler family from env. @@ -437,9 +392,6 @@ def add_parallel_do_over_meta_segments( # Ensure scalars that may be emitted as FIRSTPRIVATE have a value first_priv_red_init(target, init_scalars) - # Explicit privates per policy - mark_explicit_privates(target, privates) - # Apply the dynamic-scheduled directive (forced) try: if in_parallel_region: @@ -448,7 +400,8 @@ def add_parallel_do_over_meta_segments( "applying OMP DO (forced, dynamic).", target.position, ) - OMP_DO_LOOP_TRANS_DYNAMIC.apply(target, options={"force": True}) + OMP_DO_LOOP_TRANS_DYNAMIC.apply( + target, force=True, force_private=privates) else: logging.info( "Found target loop at %s:" @@ -456,7 +409,7 @@ def add_parallel_do_over_meta_segments( target.position, ) OMP_PARALLEL_LOOP_DO_TRANS_DYNAMIC.apply( - target, options={"force": True} + target, force_private=privates, force=True ) logging.info("Member-count PARALLEL DO inserted (dynamic).") @@ -515,7 +468,7 @@ def first_priv_red_init(node_target, init_scalars, insert_at_start=False): # rather than UnsupportedFortranType if isinstance(sym.datatype, UnsupportedFortranType): init = Assignment.create( - Reference(sym), Literal("", CHARACTER_TYPE) + Reference(sym), Literal("", ScalarType.character_type()) ) else: init = Assignment.create( @@ -649,7 +602,7 @@ def loop_replacement_of(routine_itr, parent = routine_itr assign = Assignment.create( Reference(loop.variable), - Literal("1", INTEGER_TYPE)) + Literal("1", ScalarType.integer_type())) parent.children.insert(0, assign) do_once = True diff --git a/interfaces/jules_interface/source/algorithm/jules_imp_alg_mod.x90 b/interfaces/jules_interface/source/algorithm/jules_imp_alg_mod.x90 index 355b37f74..a9df9d60a 100644 --- a/interfaces/jules_interface/source/algorithm/jules_imp_alg_mod.x90 +++ b/interfaces/jules_interface/source/algorithm/jules_imp_alg_mod.x90 @@ -7,7 +7,7 @@ module jules_imp_alg_mod - use constants_mod, only: i_def + use constants_mod, only: i_def, r_def use model_clock_mod, only: model_clock_type use field_mod, only: field_type use integer_field_mod, only: integer_field_type diff --git a/interfaces/jules_interface/source/diagnostics/jules_imp_diags_mod.x90 b/interfaces/jules_interface/source/diagnostics/jules_imp_diags_mod.x90 index 13a36d4bf..c94975f49 100644 --- a/interfaces/jules_interface/source/diagnostics/jules_imp_diags_mod.x90 +++ b/interfaces/jules_interface/source/diagnostics/jules_imp_diags_mod.x90 @@ -7,7 +7,7 @@ module jules_imp_diags_mod - use constants_mod, only: l_def + use constants_mod, only: l_def, r_def use field_mod, only: field_type use jules_control_init_mod, only: n_surf_tile, n_land_tile use sci_weighted_ave_kernel_mod, only: weighted_ave_kernel_type diff --git a/interfaces/jules_interface/source/diagnostics/jules_snow_diags_mod.x90 b/interfaces/jules_interface/source/diagnostics/jules_snow_diags_mod.x90 index d48f4f014..294719b77 100644 --- a/interfaces/jules_interface/source/diagnostics/jules_snow_diags_mod.x90 +++ b/interfaces/jules_interface/source/diagnostics/jules_snow_diags_mod.x90 @@ -7,7 +7,7 @@ module jules_snow_diags_mod - use constants_mod, only: l_def + use constants_mod, only: l_def, r_def use field_mod, only: field_type use timing_mod, only: start_timing, stop_timing, tik, LPROF use sci_weighted_ave_kernel_mod, only: weighted_ave_kernel_type diff --git a/interfaces/jules_interface/source/diagnostics/jules_soil_diags_mod.x90 b/interfaces/jules_interface/source/diagnostics/jules_soil_diags_mod.x90 index a3db5c361..b0b3a7dd7 100644 --- a/interfaces/jules_interface/source/diagnostics/jules_soil_diags_mod.x90 +++ b/interfaces/jules_interface/source/diagnostics/jules_soil_diags_mod.x90 @@ -7,7 +7,7 @@ module jules_soil_diags_mod - use constants_mod, only: l_def + use constants_mod, only: l_def, r_def use field_mod, only: field_type use timing_mod, only: start_timing, stop_timing, tik, LPROF use sci_weighted_ave_kernel_mod, only: weighted_ave_kernel_type diff --git a/interfaces/physics_schemes_interface/source/algorithm/bl_imp_alg_mod.x90 b/interfaces/physics_schemes_interface/source/algorithm/bl_imp_alg_mod.x90 index 541d574c1..d63ee4873 100644 --- a/interfaces/physics_schemes_interface/source/algorithm/bl_imp_alg_mod.x90 +++ b/interfaces/physics_schemes_interface/source/algorithm/bl_imp_alg_mod.x90 @@ -7,7 +7,7 @@ module bl_imp_alg_mod - use constants_mod, only: i_def, l_def + use constants_mod, only: i_def, l_def, r_def use model_clock_mod, only: model_clock_type use field_mod, only: field_type use integer_field_mod, only: integer_field_type diff --git a/science/gungho/source/algorithm/timestepping/semi_implicit_timestep_alg_mod.X90 b/science/gungho/source/algorithm/timestepping/semi_implicit_timestep_alg_mod.X90 index 8d6399c95..c96ecb77f 100644 --- a/science/gungho/source/algorithm/timestepping/semi_implicit_timestep_alg_mod.X90 +++ b/science/gungho/source/algorithm/timestepping/semi_implicit_timestep_alg_mod.X90 @@ -8,7 +8,7 @@ !! 3D equations. module semi_implicit_timestep_alg_mod - use constants_mod, only: i_def, r_def, l_def, str_def + use constants_mod, only: i_def, r_def, l_def, str_def, r_tran use fs_continuity_mod, only: Wtheta, W2 use log_mod, only: log_event, & log_scratch_space, & @@ -730,6 +730,7 @@ contains if ( LPROF ) call start_timing( id, 'semi_implicit_timestep' ) + lbc_option = 0 cast_dt = real(model_clock%get_seconds_per_step(), r_def) if (limited_area .and. use_wavedynamics) then diff --git a/science/gungho/source/algorithm/transport/common/map_w2_to_sh_w2_alg_mod.x90 b/science/gungho/source/algorithm/transport/common/map_w2_to_sh_w2_alg_mod.x90 index ec53467ba..713257fac 100644 --- a/science/gungho/source/algorithm/transport/common/map_w2_to_sh_w2_alg_mod.x90 +++ b/science/gungho/source/algorithm/transport/common/map_w2_to_sh_w2_alg_mod.x90 @@ -9,7 +9,7 @@ module map_w2_to_sh_w2_alg_mod use sci_consist_w2_to_sh_w2_kernel_mod, & only: consist_w2_to_sh_w2_kernel_type - use constants_mod, only: i_def + use constants_mod, only: i_def, r_tran use extrusion_mod, only: SHIFTED use fs_continuity_mod, only: Wtheta use sci_geometric_constants_mod, & From 52848a6ad841122a6b224d26745c41a3a4539121 Mon Sep 17 00:00:00 2001 From: Sergi Siso Date: Tue, 9 Jun 2026 09:43:05 +0100 Subject: [PATCH 2/2] Add names to the CONTRIBUTORS list Co-authored-by: Andrew Porter Co-authored-by: Aidan Chalk <3043914+LonelyCat124@users.noreply.github.com> Signed-off-by: Sergi Siso --- CONTRIBUTORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a63866f12..dcb5f43b2 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -48,3 +48,6 @@ | theabro | Nathan Luke Abraham | NCAS & University of Cambridge | 2026-04-15 | | ss421 | Steven Sandbach | Met Office | 2026-04-20 | | MichaelWhitall | Michael Whitall | Met Office | 2026-04-22 | +| sergisiso | Sergi Siso | UKRI-STFC | 2026-06-09 | +| arporter | Andrew Porter | UKRI-STFC | 2026-06-09 | +| LonelyCat124 | Aidan Chalk | UKRI-STFC | 2026-06-09 |