Skip to content

Adding ability to compile Isca in single-precision at the python-script level - #309

Draft
sit23 wants to merge 10 commits into
ExeClim:masterfrom
sit23:single_prec_2026
Draft

Adding ability to compile Isca in single-precision at the python-script level#309
sit23 wants to merge 10 commits into
ExeClim:masterfrom
sit23:single_prec_2026

Conversation

@sit23

@sit23 sit23 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Supersedes #265.

Adds cb.use_single_precision() — a CodeBase method to compile Isca
with single-precision (4-byte) reals instead of the default double
precision, needed because e.g. Intel's -r8/gfortran's
-fdefault-real-8 must be present for double precision and absent
for single, so a separate mkmf template + env file is selected rather
than just adding a compile flag.

Rebased from the original single_prec branch (#265, April 2024) onto
current master, with two fixes:

  • That branch's first commit accidentally mangled -DINTERNAL_FILE_NML
    to -DINTERNAL_FILE_NM while removing a now-redundant hardcoded
    -DOVERLOAD_C8 from compile.sh - fixed.
  • use_single_precision() needs a src/extra/env/<GFDL_ENV>_single
    file, but none was ever added (not even for Intel/maths2, the
    original target) - added maths2_single, plus a gfortran/
    ubuntu_conda_single variant so this isn't Intel-only anymore.

Also fixes a real, still-present bug in current master: all 4
cloud_simple/*.F90 files call file_exist('input.nml') in their
#else (non-INTERNAL_FILE_NML) branch without importing it -
currently invisible only because compile.sh always hardcodes
-DINTERNAL_FILE_NML.

See SINGLE_PREC_PORT_VALIDATION.md for full validation: trip_test
confirms the default double-precision build is unaffected
(held_suarez, socrates_aquaplanet_cloud - the latter chosen because
it actually exercises the changed cloud_simple/lcl.F90 code at
runtime), and a real 5-day single-vs-double precision run confirms
use_single_precision() compiles, links, and runs to completion with
physically sane output.

sit23 added 7 commits August 26, 2026 14:20
…ses a combination of Iscas in-built macros with overload_c4 etc, whilst maintaining other default flags.

(cherry picked from commit d04d164)
…ountered with the simple cloud fortran files, which had missed a few file-exists imports from fms-mod. Also lcl.f90 explicitly defined variables as double precision, which caused problems when variables were inputted to its functions as single. Now changed to real so that compiler chooses the representation of real.

(cherry picked from commit ec5992a)
… precision, but should not be there for single precision. Do not currently have a dynamic way of editing that mkmf template file, so added feature to choose different mkmf template file for single precision. Format is just same name as current mkmf template file with _simple added at the end.

(cherry picked from commit 8fa14bb)
single_prec's own final commit ("Needs new env file to point to new
mkmf file") never actually delivered one - cb.use_single_precision()
appends '_single' to whatever GFDL_ENV file is loaded, but no
src/extra/env/maths2_single ever existed, so the feature wasn't
actually runnable even on the branch's own target machine (maths2).
Adding it now, mirroring the existing maths2 env file.

Also adding an equivalent ubuntu_conda_single/mkmf.template pair,
needed to exercise this locally on this machine's GFDL_ENV
(ubuntu_conda uses gfortran, which needs the same -fdefault-real-8/
-fdefault-double-8 removal for single precision as maths2's -r8) -
and generically useful given ubuntu_conda is the common dev
environment, not just this machine.
Documents trip_test bit-reproducibility confirmation of the
lcl.F90/cloud_simple changes on the default double-precision build
(held_suarez, and socrates_aquaplanet_cloud which actually exercises
the simple-cloud scheme at runtime), plus a real 5-day held_suarez
run confirming cb.use_single_precision() compiles, links, and runs
to completion with physically sane output.

Companion to PHYSICS_PORT_VALIDATION.md and NUMERICS_PORT_VALIDATION.md
on the unrelated uob_fftw_sit23_*_2026 branches.
sit23 added 3 commits August 26, 2026 17:27
SINGLE_PREC_PORT_VALIDATION.md's content belongs in the PR discussion,
not committed alongside the source.
…rison

Documents cb.use_single_precision(), how to use it, and confirms via
the existing trip_test validation that it doesn't change the default
double-precision build.

Adds a 10-year Held-Suarez comparison (T42L25, 32 cores, single vs
double precision, run sequentially for a fair timing comparison):
single precision was about 21% faster (6558s vs 8255s integration
time), and produced a statistically indistinguishable long-term
climate - zonal-mean T/U plots and grid-point difference statistics
included.
Socrates defines its own real kind (r_def) throughout its radiative
transfer code, independent of the rest of Isca. This is invisible in
the default double-precision build (r_def is also double, so nothing
needs converting at the socrates_interface.F90 boundary), but
use_single_precision() only changes the rest of Isca - Socrates'
r_def stays double, so the interface ends up mixing single- and
double-precision reals in the same argument lists and fails to
compile.

Confirmed empirically: SocratesCodeBase + use_single_precision()
fails with real type-mismatch errors in socrates_interface.o.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant