Skip to content

openfoam: add 'precision' easyconfig param (DP/SP/SPDP) - #4189

Draft
hmeiland wants to merge 1 commit into
easybuilders:developfrom
hmeiland:openfoam-precision-param
Draft

openfoam: add 'precision' easyconfig param (DP/SP/SPDP)#4189
hmeiland wants to merge 1 commit into
easybuilders:developfrom
hmeiland:openfoam-precision-param

Conversation

@hmeiland

Copy link
Copy Markdown

What

Adds a custom precision easyconfig parameter to the OpenFOAM easyblock, so single-precision (SP) and mixed-precision (SPDP) OpenFOAM modules can be built directly from an easyconfig instead of a manual WM_PRECISION_OPTION override.

'precision': ['DP', "Floating-point precision: DP, SP, or SPDP", CUSTOM],

Why

OpenFOAM's etc/bashrc sets WM_PRECISION_OPTION=DP unconditionally, so simply exporting the env var is clobbered the moment Allwmake sources bashrc. The sanctioned override point is etc/prefs.sh (sourced after the DP default and before WM_OPTIONS is computed).

For non-DP builds the easyblock now:

  • writes WM_PRECISION_OPTION=<prec> into the install's etc/prefs.sh (idempotent — only if not already present),
  • sets the build-time env var,
  • threads the precision into the platform subdir name (linux64Gcc<PREC>Int32Opt),
  • exports WM_PRECISION_OPTION in the generated module.

The concrete motivation is the petsc4Foam (OpenFOAM external-solver) adapter linked against a single-precision PETSc (--with-precision=single), which requires PetscScalar == Foam::solveScalar == float, i.e. an SP OpenFOAM.

Backward compatibility

The parameter defaults to 'DP', which reproduces the previous behaviour exactly:

  • self.wm_precision != 'DP' is false → no prefs.sh is written,
  • the subdir string resolves to the same ...DP... as the prior hardcoded literal,
  • the new WM_PRECISION_OPTION=DP env/module export matches what OpenFOAM's own bashrc already sets.

So existing OpenFOAM easyconfigs (which never mention precision) build unchanged.

Testing

  • python -m py_compile clean.
  • Used in practice to build an SP OpenFOAM v2506 (foss/2025a) module on AMD gfx1101, consumed by a single-precision petsc4Foam adapter; DP builds verified to produce byte-identical psubdir/module env vs. the stock easyblock.

Draft: opening for early feedback on the approach (custom param + prefs.sh write) before adding an SP easyconfig that exercises it.

Add a custom 'precision' easyconfig parameter (default 'DP') to the
OpenFOAM easyblock so single- and mixed-precision builds can be produced
from an easyconfig instead of a manual WM_PRECISION_OPTION override.

OpenFOAM's etc/bashrc sets WM_PRECISION_OPTION=DP unconditionally, so a
plain env var is clobbered when Allwmake sources bashrc. For SP/SPDP the
easyblock now writes the sanctioned etc/prefs.sh override (sourced after
the DP default and before WM_OPTIONS is computed), sets the build-time
env var, threads the precision into the platform subdir name
(linux64Gcc<PREC>Int32Opt), and exports WM_PRECISION_OPTION in the module.

Default 'DP' reproduces the previous behaviour exactly: no prefs.sh is
written, and the subdir/env values are identical to the prior hardcoded
'DP', so existing easyconfigs build unchanged.
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