Skip to content

Appease nvhpc#163

Open
K20shores wants to merge 11 commits intomainfrom
appease-nvhpc
Open

Appease nvhpc#163
K20shores wants to merge 11 commits intomainfrom
appease-nvhpc

Conversation

@K20shores
Copy link
Collaborator

@K20shores K20shores commented Feb 12, 2026

Fix all test and build failures with the nvhpc 25.7 compiler.

  • Add nvhpc Docker build and CI workflow
  • Fix self-referential transpose() on allocatable arrays (20 cross sections, 17 quantum yields)
  • Fix array auto-reallocation preserving wrong lbounds for grid mid_/delta_ and profile layer_dens_/mid_val_/delta_val_
  • Fix polymorphic array descriptor corruption in radiator_state_t%accumulate (class → type for non-extended radiator_ptr)
  • Fix stack array corruption in radiator test by making arrays allocatable
  • Fix allocatable function result in la_sr_bands%effxs by using fixed-size array
  • Fix sequence association this%AC(1,I) → this%AC(:,I) in la_sr_bands%calc_params
  • Fix log(exp(38)) roundoff misclassifying ktop boundary in Schumann-Runge bands (both TUV-x and F77 reference code)
  • Fix string corruption in dose_rates constructor by replacing array concatenation [ handles_, key ] with explicit reallocation

peverwhee and others added 10 commits February 13, 2026 11:05
The nvhpc compiler does not correctly handle `x = transpose(x)` on
allocatable arrays when the transpose changes shape. Use a separate
working array for the (wavelength, height) layout, then assign the
transpose to the result variable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…diator polymorphism

- Grid from_config: explicitly allocate mid_/delta_ before assignment from
  array slices to prevent nvhpc from preserving wrong lower bounds
- Profiles (7 files): same fix for mid_val_/delta_val_/layer_dens_ arrays
- Quantum yields (17 files): use separate working arrays for transpose to
  avoid self-referential transpose that nvhpc mishandles
- Radiator: change class(radiator_ptr) to type(radiator_ptr) in accumulate
  to fix polymorphic array descriptor corruption on nvhpc; add explicit
  allocation guard for layer_OD_

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- radiator test: change stack-allocated radiator_ptr arrays to allocatable
  to work around nvhpc bug with stack arrays of derived types containing
  polymorphic pointer components (resulted in corrupted array bounds)
- la_sr_bands effxs: change allocatable function result to fixed-size
  array to avoid nvhpc issues with allocatable function results assigned
  to array sections

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nvhpc

In calc_params, replace this%AC(1,I) and this%BC(1,I) (Fortran 77
sequence association) with this%AC(:,I) and this%BC(:,I) (proper array
sections). nvhpc miscalculates memory offsets when using sequence
association on components of polymorphic (class) objects, causing the
Chebyshev polynomial to evaluate with wrong coefficients (~3% error
in O2 optical depth at certain heights/wavelengths).

Also remove temporary diagnostic output from test_la_srb.F90.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
In schum_OD and schum_xs, the code clamps O2 column to colmin=exp(38)
then checks if log(clamped_value) < 38. With nvhpc's math library,
log(exp(38._dk)) returns a value slightly less than 38.0_dk, causing
all heights at the top of the atmosphere (where O2 column is clamped)
to be misclassified as out-of-range. This resulted in cross sections
being filled with repeated edge values instead of computed values,
producing ~3-67% errors across 5525 height/wavelength/SZA combinations.

Fix: check the unclamped column directly against colmin instead of
comparing log(clamped_column) against 38. This avoids the roundoff
issue entirely and matches the mathematical intent.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Apply the same ktop boundary fix to the F77 test reference code that
was applied to the TUV-x la_sr_bands.F90. Compare unclamped o2col
against EXP(38.) directly instead of checking ALOG(clamped) < 38.0,
which fails on nvhpc where log(exp(38)) rounds to slightly less than
38.0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace Fortran array concatenation `[ handles_, key ]` with explicit
temporary + reallocation for both handles_ and spectral_weights_ arrays.
nvhpc 25.7 doesn't deep-copy allocatable character components in string_t
during array concatenation, causing garbled variable names when writing
dose_rates.nc. This matches the pattern already used in photolysis_rates.F90.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses comprehensive compiler compatibility issues with the NVIDIA nvhpc 25.7 compiler. The changes systematically fix multiple categories of Fortran language features that nvhpc handles differently than other compilers, while maintaining correctness and functionality.

Changes:

  • Added nvhpc 25.7 Docker build environment and CI workflow integration
  • Fixed self-referential transpose operations on allocatable arrays across 37 quantum yield and cross section calculation files
  • Fixed array auto-reallocation issues in profile and grid constructors by adding explicit allocations
  • Resolved polymorphic array descriptor corruption, stack corruption, sequence association violations, and string concatenation issues
  • Fixed numerical precision bug in Schumann-Runge band calculations affecting both TUV-x and F77 reference code

Reviewed changes

Copilot reviewed 67 out of 67 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docker/Dockerfile.nvhpc New nvhpc 25.7 Docker build environment with netcdf dependencies
docker/Dockerfile.intel Minor comment correction
.github/workflows/docker.yml Added nvhpc to CI matrix and disk space cleanup
test/unit/util/io/netcdf.F90 Wrapped string literals with string_t() constructor for nvhpc compatibility
test/unit/tuv_doug/schum.f Fixed log(exp(38)) roundoff error causing ktop boundary misclassification
test/unit/test_utils.F90 Added debug print statements for array size checking
test/unit/radiator/radiator_test.F90 Changed stack arrays to allocatable to prevent stack corruption
src/util/config.F90 Extracted complex logical conditions to temporary variables for nvhpc compatibility
src/radiative_transfer/radiator.F90 Changed class(radiator_ptr) to type(radiator_ptr) to fix descriptor corruption; added allocation check for layer_OD_
src/quantum_yields/*.F90 (17 files) Fixed self-referential transpose using intermediate wrkQuantumYield arrays
src/cross_sections/*.F90 (20 files) Fixed self-referential transpose using intermediate wrkCrossSection arrays
src/profiles/*.F90 (7 files) Added explicit allocation before assignment; renamed finalizers to unique names
src/grids/from_config.F90 Added explicit allocation before assignment for mid_ and delta_
src/grid_warehouse.F90 Renamed finalizer to finalize_grid_warehouse
src/profile_warehouse.F90 Renamed finalizer to finalize_profile_warehouse
src/output.F90 Renamed finalizer to finalize_output_t
src/netcdf.F90 Renamed finalizer to finalize_netcdf
src/heating_rates.F90 Fixed zero-size array allocation; modified labels() function to use explicit loop
src/dose_rates.F90 Replaced array concatenation with explicit reallocation to fix string corruption
src/photolysis_rates.F90 Added allocation check before transpose
src/la_sr_bands.F90 Fixed log(exp(38)) roundoff; changed allocatable to fixed-size array result; fixed sequence association with array sections

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.

3 participants