stfc / PSyclone

Domain-specific compiler and code transformation system for Finite Difference/Volume/Element Earth-system models in Fortran
BSD 3-Clause "New" or "Revised" License
107 stars 29 forks source link

New LFRic BuiltIns - field_min_max and copy_field routines based on intrinsic Fortran precisions #2674

Open rjlmalone opened 3 months ago

rjlmalone commented 3 months ago

Introduction: The release of LFRic version 1.1 has seen psykal_builtin_light module replaced by sci_psykal_builtin_light_mod, which, at present, provides support for field_min_max and two other routines (pending Psyclone issue #489), but does not include the copy_field invokes, which use similar parallelised methods, based on intrinsic Fortran precisions. Field_min_max and copy_field are covered by LFRic tickets #4109 and #4024.

1/ LFRic Core version 1.0

Ref: [log:LFRic/branches/dev/richardmalone/apps1.0_b6]

1.0/ The relevant modules are located at (apps1.0_b6):

       ./components/science/source/algorithm/field_minmax_alg_mod.f90
       ./components/science/source/algorithm/copy_field_alg_mod.f90
           ./components/science/source/psy/psykal_builtin_light_mod.f90

1.1/ Psykal_builtin_light_mod contained two new classes of invoke subroutines for field min_max and field copy operations, optimised for parallel processing, utlilising only intrinsic iso Fortran numeric precisions. These are distinct from similar functions based on science numeric classes (r_single, r_double, r_def, r_tran, r_solver).

1.2/ These new invoke functions, used in field_min_max_alg_mod and copy_field_alg_mod, are as follows:

        invoke_r32_field_min_max
        invoke_r64_field_min_max
        invoke_copy_field_32_64
        invoke_copy_field_64_32
        invoke_copy_field_32_32
        invoke_copy_field_64_64

   where: [32, 64] are intrinsic iso Fortran real precisions 

2/ LFRic Core version 1.1

Ref: [log:LFRic/branches/dev/richardmalone/core1.1_b6N]

2.0/ The relevant modules are located at (core1.1_b6N):

./components/science/source/algorithm/field_minmax_alg_mod.f90
./components/science/source/algorithm/copy_field_alg_mod.f90
    ./components/science/source/psy/sci_psykal_builtin_light_mod.f90

2.1/ In Core version 1.1, field_min_max invoke routines currently reside in sci_psykal_builtin_light_mod, with note that:

! This is a PSyKAl-lite implementation of a built-in that will be implemented 
! under PSYclone issue #489. See that issue for further details.

2.2/ At present time there are no equivalent entries for copy_field invoke routines in sci_psykal_builtin_light_mod.f90

3.0/ PSYclone and structural similarities between field_minmax and field_copy

The field_minmax and field_copy code share much in common even though one returns two scalars and the other a whole field: They both have very similar assumptions and stucture, use the same omp decorators, span the same loop architecture, norms and numerical intrinsics. So I would suspect they would transform in Psyclone in similar fashion to PSYclone issue #489.

arporter commented 1 month ago

PSyclone could, in principle, optimise out the copy operations when it knows that the precision doesn't change.