From b25a7c52a27dfd52edc10bc0ebe12776af0f03df Mon Sep 17 00:00:00 2001 From: Ryan Mulhall <35538242+rem1776@users.noreply.github.com> Date: Wed, 20 Sep 2023 11:37:54 -0400 Subject: [PATCH] feat: expand mixed precision support to most modules (#1366) BREAKING CHANGE: In coupler_types.F90, `coupler_nd_field_type` and `coupler_nd_values_type` have been renamed to indicate real kind value: `coupler_nd_real4/8_field_type` and `coupler_nd_real4/8_values_type`. The `bc` field within `coupler_nd_bc_type` was modified to use r8_kind within the value and field types, and an additional field added `bc_r4` to use r4_kind values. Includes: * feat: eliminate use of real numbers for mixed precision in `block_control` (#1195) * feat: mixed precision field_manager (#1205) * feat: mixed precision random_numbers_mod (#1191) * feat: mixed precision time_manager reals to r8 and clean up (#1196) * feat: mixed Precision tracer_manager (#1212) * Mixed precision monin_obukhov (#1116) * Mixed precision: `monin_obukhov` unit tests (#1272) * mixed-precision diag_integral_mod (#1217) * mixed precision time_interp (#1252) * mixed precision interpolator_mod (#1305) * Mixed precision astronomy (#1092) * Mixed precision `data_override_mod` (#1323) * mixed precision exchange (#1341) * coupler mixed precision (#1353) * Mixed precision topography_mod (#1250) --------- Co-authored-by: rem1776 Co-authored-by: MiKyung Lee <58964324+mlee03@users.noreply.github.com> Co-authored-by: mlee03 Co-authored-by: Caitlyn McAllister <65364559+mcallic2@users.noreply.github.com> Co-authored-by: Jesse Lentz <42011922+J-Lentz@users.noreply.github.com> --- CHANGELOG.md | 2 +- CMakeLists.txt | 32 +- astronomy/Makefile.am | 13 +- astronomy/astronomy.F90 | 2425 ++-------- astronomy/include/astronomy.inc | 1595 ++++++ astronomy/include/astronomy_r4.fh | 107 + astronomy/include/astronomy_r8.fh | 107 + axis_utils/include/axis_utils2.inc | 5 - axis_utils/include/axis_utils2_r4.fh | 2 +- axis_utils/include/axis_utils2_r8.fh | 2 +- block_control/block_control.F90 | 7 +- configure.ac | 11 + coupler/Makefile.am | 8 +- coupler/atmos_ocean_fluxes.F90 | 549 ++- coupler/coupler_types.F90 | 4277 +++++++++-------- coupler/include/coupler_types.inc | 1211 +++++ coupler/include/coupler_types_r4.fh | 53 + coupler/include/coupler_types_r8.fh | 53 + data_override/Makefile.am | 10 +- data_override/data_override.F90 | 1331 +---- data_override/get_grid_version.F90 | 242 +- data_override/include/data_override.inc | 1245 +++++ data_override/include/data_override_r4.fh | 65 + data_override/include/data_override_r8.fh | 65 + data_override/include/get_grid_version.inc | 246 + data_override/include/get_grid_version_r4.fh | 33 + data_override/include/get_grid_version_r8.fh | 33 + diag_integral/Makefile.am | 12 +- diag_integral/diag_integral.F90 | 465 +- diag_integral/include/diag_integral.inc | 403 ++ diag_integral/include/diag_integral_r4.fh | 44 + diag_integral/include/diag_integral_r8.fh | 44 + exchange/stock_constants.F90 | 41 +- exchange/xgrid.F90 | 901 ++-- field_manager/Makefile.am | 30 +- field_manager/field_manager.F90 | 319 +- field_manager/fm_util.F90 | 365 +- field_manager/include/field_manager.inc | 246 + field_manager/include/field_manager_r4.fh | 40 + field_manager/include/field_manager_r8.fh | 40 + field_manager/include/fm_util.inc | 356 ++ field_manager/include/fm_util_r4.fh | 31 + field_manager/include/fm_util_r8.fh | 31 + .../include/horiz_interp_bicubic_r4.fh | 2 +- .../include/horiz_interp_bicubic_r8.fh | 2 +- .../include/horiz_interp_bilinear_r4.fh | 2 +- .../include/horiz_interp_bilinear_r8.fh | 2 +- .../include/horiz_interp_conserve_r4.fh | 2 +- .../include/horiz_interp_conserve_r8.fh | 2 +- horiz_interp/include/horiz_interp_r4.fh | 2 +- horiz_interp/include/horiz_interp_r8.fh | 2 +- .../include/horiz_interp_spherical_r4.fh | 2 +- .../include/horiz_interp_spherical_r8.fh | 2 +- horiz_interp/include/horiz_interp_type.inc | 2 +- horiz_interp/include/horiz_interp_type_r4.fh | 2 +- horiz_interp/include/horiz_interp_type_r8.fh | 2 +- interpolator/Makefile.am | 7 +- interpolator/include/interpolator.inc | 3411 +++++++++++++ interpolator/include/interpolator_r4.fh | 70 + interpolator/include/interpolator_r8.fh | 70 + interpolator/interpolator.F90 | 3527 +------------- libFMS.F90 | 18 +- m4/gx_fortran_legacy_options.m4 | 2 +- monin_obukhov/Makefile.am | 29 +- monin_obukhov/include/monin_obukhov.inc | 852 ++++ monin_obukhov/include/monin_obukhov_inter.inc | 722 +++ .../include/monin_obukhov_inter_r4.fh | 59 + .../include/monin_obukhov_inter_r8.fh | 59 + monin_obukhov/include/monin_obukhov_r4.fh | 108 + monin_obukhov/include/monin_obukhov_r8.fh | 112 + monin_obukhov/monin_obukhov.F90 | 903 +--- monin_obukhov/monin_obukhov_inter.F90 | 712 +-- platform/platform.F90 | 2 +- random_numbers/Makefile.am | 7 +- random_numbers/include/random_numbers.inc | 52 + random_numbers/include/random_numbers_r4.fh | 35 + random_numbers/include/random_numbers_r8.fh | 35 + random_numbers/mersennetwister.F90 | 14 +- random_numbers/random_numbers.F90 | 53 +- sat_vapor_pres/sat_vapor_pres_k.F90 | 2 +- test_fms/Makefile.am | 7 +- test_fms/astronomy/Makefile.am | 55 + test_fms/astronomy/test_astronomy.F90 | 284 ++ test_fms/astronomy/test_astronomy.sh | 47 + test_fms/coupler/Makefile.am | 22 +- test_fms/coupler/test_atmos_ocean_fluxes.F90 | 218 + test_fms/coupler/test_coupler.sh | 36 +- test_fms/coupler/test_coupler_2d.F90 | 127 +- test_fms/coupler/test_coupler_3d.F90 | 128 +- test_fms/coupler/test_coupler_utils.inc | 271 ++ test_fms/data_override/Makefile.am | 28 +- test_fms/data_override/test_data_override.F90 | 106 +- test_fms/data_override/test_data_override2.sh | 34 +- .../test_data_override_ongrid.F90 | 85 +- test_fms/data_override/test_get_grid_v1.F90 | 46 +- test_fms/diag_integral/Makefile.am | 49 + test_fms/diag_integral/test_diag_integral.F90 | 225 + test_fms/diag_integral/test_diag_integral2.sh | 40 + test_fms/exchange/test_xgrid.F90 | 8 +- test_fms/field_manager/Makefile.am | 11 +- test_fms/field_manager/test_field_manager.F90 | 51 +- test_fms/field_manager/test_field_manager2.sh | 6 +- test_fms/interpolator/Makefile.am | 11 +- test_fms/interpolator/test_interpolator2.F90 | 309 ++ test_fms/interpolator/test_interpolator2.sh | 9 +- .../test_interpolator_write_climatology.inc | 286 ++ test_fms/monin_obukhov/Makefile.am | 10 +- test_fms/monin_obukhov/input.r4.nml | 35 + test_fms/monin_obukhov/input.r8.nml | 17 + test_fms/monin_obukhov/test_monin_obukhov.F90 | 740 ++- test_fms/monin_obukhov/test_monin_obukhov2.sh | 20 +- test_fms/mpp/test_mpp_update_domains_main.F90 | 2 +- test_fms/random_numbers/Makefile.am | 52 + .../random_numbers/test_random_numbers.F90 | 279 ++ .../random_numbers/test_random_numbers.sh | 37 + test_fms/time_interp/Makefile.am | 15 +- test_fms/time_interp/test_time_interp.F90 | 91 +- test_fms/time_interp/test_time_interp2.sh | 32 +- .../time_interp/test_time_interp_external.F90 | 528 +- test_fms/time_manager/test_time_manager.F90 | 16 +- test_fms/tracer_manager/Makefile.am | 51 + .../tracer_manager/test_tracer_manager.F90 | 116 + .../tracer_manager/test_tracer_manager2.sh | 109 + time_interp/Makefile.am | 10 +- time_interp/include/time_interp.inc | 475 ++ time_interp/include/time_interp_external.inc | 1424 ++++++ time_interp/include/time_interp_external2.inc | 303 ++ .../include/time_interp_external2_r4.fh | 31 + .../include/time_interp_external2_r8.fh | 31 + time_interp/include/time_interp_r4.fh | 43 + time_interp/include/time_interp_r8.fh | 43 + time_interp/time_interp.F90 | 744 +-- time_interp/time_interp_external2.F90 | 880 ++-- time_manager/get_cal_time.F90 | 97 +- time_manager/time_manager.F90 | 1149 +---- topography/Makefile.am | 26 +- topography/gaussian_topog.F90 | 237 +- topography/include/gaussian_topog.inc | 148 + topography/include/gaussian_topog_r4.fh | 44 + topography/include/gaussian_topog_r8.fh | 43 + topography/include/topography.inc | 593 +++ topography/include/topography_r4.fh | 95 + topography/include/topography_r8.fh | 95 + topography/topography.F90 | 737 +-- tracer_manager/Makefile.am | 9 +- tracer_manager/include/tracer_manager.inc | 147 + tracer_manager/include/tracer_manager_r4.fh | 28 + tracer_manager/include/tracer_manager_r8.fh | 28 + tracer_manager/tracer_manager.F90 | 172 +- 149 files changed, 24296 insertions(+), 15969 deletions(-) create mode 100644 astronomy/include/astronomy.inc create mode 100644 astronomy/include/astronomy_r4.fh create mode 100644 astronomy/include/astronomy_r8.fh create mode 100644 coupler/include/coupler_types.inc create mode 100644 coupler/include/coupler_types_r4.fh create mode 100644 coupler/include/coupler_types_r8.fh create mode 100644 data_override/include/data_override.inc create mode 100644 data_override/include/data_override_r4.fh create mode 100644 data_override/include/data_override_r8.fh create mode 100644 data_override/include/get_grid_version.inc create mode 100644 data_override/include/get_grid_version_r4.fh create mode 100644 data_override/include/get_grid_version_r8.fh create mode 100644 diag_integral/include/diag_integral.inc create mode 100644 diag_integral/include/diag_integral_r4.fh create mode 100644 diag_integral/include/diag_integral_r8.fh create mode 100644 field_manager/include/field_manager.inc create mode 100644 field_manager/include/field_manager_r4.fh create mode 100644 field_manager/include/field_manager_r8.fh create mode 100644 field_manager/include/fm_util.inc create mode 100644 field_manager/include/fm_util_r4.fh create mode 100644 field_manager/include/fm_util_r8.fh create mode 100644 interpolator/include/interpolator.inc create mode 100644 interpolator/include/interpolator_r4.fh create mode 100644 interpolator/include/interpolator_r8.fh create mode 100644 monin_obukhov/include/monin_obukhov.inc create mode 100644 monin_obukhov/include/monin_obukhov_inter.inc create mode 100644 monin_obukhov/include/monin_obukhov_inter_r4.fh create mode 100644 monin_obukhov/include/monin_obukhov_inter_r8.fh create mode 100644 monin_obukhov/include/monin_obukhov_r4.fh create mode 100644 monin_obukhov/include/monin_obukhov_r8.fh create mode 100644 random_numbers/include/random_numbers.inc create mode 100644 random_numbers/include/random_numbers_r4.fh create mode 100644 random_numbers/include/random_numbers_r8.fh create mode 100644 test_fms/astronomy/Makefile.am create mode 100644 test_fms/astronomy/test_astronomy.F90 create mode 100755 test_fms/astronomy/test_astronomy.sh create mode 100644 test_fms/coupler/test_atmos_ocean_fluxes.F90 create mode 100644 test_fms/coupler/test_coupler_utils.inc create mode 100644 test_fms/diag_integral/Makefile.am create mode 100644 test_fms/diag_integral/test_diag_integral.F90 create mode 100755 test_fms/diag_integral/test_diag_integral2.sh create mode 100644 test_fms/interpolator/test_interpolator2.F90 create mode 100644 test_fms/interpolator/test_interpolator_write_climatology.inc create mode 100644 test_fms/monin_obukhov/input.r4.nml create mode 100644 test_fms/monin_obukhov/input.r8.nml create mode 100644 test_fms/random_numbers/Makefile.am create mode 100644 test_fms/random_numbers/test_random_numbers.F90 create mode 100755 test_fms/random_numbers/test_random_numbers.sh create mode 100644 test_fms/tracer_manager/Makefile.am create mode 100644 test_fms/tracer_manager/test_tracer_manager.F90 create mode 100755 test_fms/tracer_manager/test_tracer_manager2.sh create mode 100644 time_interp/include/time_interp.inc create mode 100644 time_interp/include/time_interp_external.inc create mode 100644 time_interp/include/time_interp_external2.inc create mode 100644 time_interp/include/time_interp_external2_r4.fh create mode 100644 time_interp/include/time_interp_external2_r8.fh create mode 100644 time_interp/include/time_interp_r4.fh create mode 100644 time_interp/include/time_interp_r8.fh create mode 100644 topography/include/gaussian_topog.inc create mode 100644 topography/include/gaussian_topog_r4.fh create mode 100644 topography/include/gaussian_topog_r8.fh create mode 100644 topography/include/topography.inc create mode 100644 topography/include/topography_r4.fh create mode 100644 topography/include/topography_r8.fh create mode 100644 tracer_manager/include/tracer_manager.inc create mode 100644 tracer_manager/include/tracer_manager_r4.fh create mode 100644 tracer_manager/include/tracer_manager_r8.fh diff --git a/CHANGELOG.md b/CHANGELOG.md index 32cc50cd27..2c616e647d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ sequential patch number (starting from `01`). - LIBFMS: The libFMS.F90 file (module name `fms`) meant to provide global access has been updated to include 'fms' and it's module/subdirectory name as prefixes for all names. This will only affect external codes that are already using the global module (via `use fms`) and not individual modules. - MIXED PRECISION: Updates the axis_utils2, horiz_interp, sat_vapor_pressure, and axis_utils subdirectories to support mixed precision real values. - FMS2_IO: Added in mpp_scatter and mpp_gather performance changes from the 2023.01.01 patch. See below for more details. -- FMS2_IO: Improved error messages to give more debugging information +- FMS2_IO: Improved error messages to give more debugging information - FMS_MOD: Changed fms_init to include a system call to set the stack size to unlimited, removed previously added stack size fixes - MONIN_OBUKHOV: Restructures the subroutines in `stable_mix` interface so that 1d calls the underlying implementation, and 2 and 3d call it on 1d slices of the data as opposed to passing in mismatched arrays. - MPP: Updates from JEDI for ajoint version the mpp halo filling (mpp_do_update_ad.fh), adds checkpoint for forward buffer information. diff --git a/CMakeLists.txt b/CMakeLists.txt index ff75d3cf90..f5ef9a7d38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,12 +305,26 @@ foreach(kind ${kinds}) fms2_io/include string_utils/include mpp/include + column_diagnostics/include + monin_obukhov/include sat_vapor_pres/include horiz_interp/include + diag_integral/include + random_numbers/include diag_manager/include constants4 + topography/include + axis_utils/include + mosaic2/include constants - axis_utils/include) + astronomy/include + field_manager/include + time_interp/include + tracer_manager/include + interpolator/include + coupler/include + data_override/include) + target_compile_definitions(${libTgt}_f PRIVATE "${fms_defs}") target_compile_definitions(${libTgt}_f PRIVATE "${${kind}_defs}") @@ -346,11 +360,25 @@ foreach(kind ${kinds}) $ $ $ + $ + $ + $ $ + $ $ + $ $ $ - $) + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) target_include_directories(${libTgt} INTERFACE $ diff --git a/astronomy/Makefile.am b/astronomy/Makefile.am index 33d4acaf3c..50a1449412 100644 --- a/astronomy/Makefile.am +++ b/astronomy/Makefile.am @@ -23,14 +23,23 @@ # Ed Hartnett 2/22/19 # Include .h and .mod files. -AM_CPPFLAGS = -I$(top_srcdir)/include +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/astronomy/include AM_FCFLAGS = $(FC_MODINC). $(FC_MODOUT)$(MODDIR) # Build this uninstalled convenience library. noinst_LTLIBRARIES = libastronomy.la # The convenience library depends on its source. -libastronomy_la_SOURCES = astronomy.F90 +libastronomy_la_SOURCES = \ + astronomy.F90 \ + include/astronomy_r4.fh \ + include/astronomy_r8.fh \ + include/astronomy.inc + +astronomy.$(FC_MODEXT): \ +include/astronomy_r4.fh \ +include/astronomy_r8.fh \ +include/astronomy.inc BUILT_SOURCES = astronomy_mod.$(FC_MODEXT) nodist_include_HEADERS = astronomy_mod.$(FC_MODEXT) diff --git a/astronomy/astronomy.F90 b/astronomy/astronomy.F90 index 192fc8f22a..48e314efd8 100644 --- a/astronomy/astronomy.F90 +++ b/astronomy/astronomy.F90 @@ -29,296 +29,321 @@ module astronomy_mod -use fms_mod, only: fms_init, & - mpp_pe, mpp_root_pe, stdlog, & - write_version_number, & - check_nml_error, error_mesg, & - FATAL, NOTE, WARNING -use time_manager_mod, only: time_type, set_time, get_time, & - get_date_julian, set_date_julian, & - set_date, length_of_year, & - time_manager_init, & - operator(-), operator(+), & - operator( // ), operator(<) -use constants_mod, only: constants_init, PI -use mpp_mod, only: input_nml_file - -!-------------------------------------------------------------------- - -implicit none -private - -!--------------------------------------------------------------------- -!----------- version number for this module -------------------------- + use fms_mod, only: fms_init, & + mpp_pe, mpp_root_pe, stdlog, & + write_version_number, & + check_nml_error, error_mesg, & + FATAL, NOTE, WARNING + use time_manager_mod, only: time_type, set_time, get_time, & + get_date_julian, set_date_julian, & + set_date, length_of_year, & + time_manager_init, & + operator(-), operator(+), & + operator( // ), operator(<) + use fms_io_utils_mod, only: get_data_type_string + use constants_mod, only: constants_init, PI + use mpp_mod, only: input_nml_file + use platform_mod, only: r4_kind, r8_kind, i4_kind, i8_kind + + !-------------------------------------------------------------------- + + implicit none + private + + !--------------------------------------------------------------------- + !----------- version number for this module -------------------------- ! Include variable "version" to be written to log file. #include -!--------------------------------------------------------------------- -!------- interfaces -------- - -public & - astronomy_init, get_period, set_period, & - set_orbital_parameters, get_orbital_parameters, & - set_ref_date_of_ae, get_ref_date_of_ae, & - diurnal_solar, daily_mean_solar, annual_mean_solar, & - astronomy_end, universal_time, orbital_time - -!> @} - -!> @brief Calculates solar information for the given location(lat & lon) and time -!! -!> ~~~~~~~~~~{.f90} -!! call diurnal_solar (lat, lon, time, cosz, fracday, rrsun, dt_time) -!! call diurnal_solar (lat, lon, gmt, time_since_ae, cosz, fracday, rrsun, dt) -!! ~~~~~~~~~~ -!! -!! The first option (used in conjunction with time_manager_mod) -!! generates the real variables gmt and time_since_ae from the -!! time_type input, and then calls diurnal_solar with these real inputs. -!! -!! The time of day is set by -!! ~~~~~~~~~~{.f90} -!! real, intent(in) :: gmt -!! ~~~~~~~~~~ -!! The time of year is set by -!! ~~~~~~~~~~{.f90} -!! real, intent(in) :: time_since_ae -!! ~~~~~~~~~~ -!! with time_type input, both of these are extracted from -!! ~~~~~~~~~~{.f90} -!! type(time_type), intent(in) :: time -!! ~~~~~~~~~~ -!! -!! Separate routines exist within this interface for scalar, -!! 1D or 2D input and output fields: -!! -!! ~~~~~~~~~~{.f90} -!! real, intent(in), dimension(:,:) :: lat, lon -!! real, intent(in), dimension(:) :: lat, lon -!! real, intent(in) :: lat, lon -!! -!! real, intent(out), dimension(:,:) :: cosz, fracday -!! real, intent(out), dimension(:) :: cosz, fracday -!! real, intent(out) :: cosz, fracday -!! ~~~~~~~~~~ -!! -!! One may also average the output fields over the time interval -!! between gmt and gmt + dt by including the optional argument dt (or -!! dt_time). dt is measured in radians and must be less than pi -!! (1/2 day). This average is computed analytically, and should be -!! exact except for the fact that changes in earth-sun distance over -!! the time interval dt are ignored. In the context of a diurnal GCM, -!! this option should always be employed to insure that the total flux -!! at the top of the atmosphere is not modified by time truncation error. -!! -!! ~~~~~~~~~~{.f90} -!! real, intent(in), optional :: dt -!! type(time_type), optional :: dt_time -!! ~~~~~~~~~~ -!! -!! @param [in] Latitudes of model grid points [radians] -!! @param [in] Longitudes of model grid points [radians] -!! @param [in] Time of day at longitude 0.0; midnight = 0.0, one day = 2 * pi [radians] -!! @param [in] Time of year; autumnal equinox = 0.0, one year = 2 * pi [radians] -!! @param [in]