Skip to content

Fix crash in dynamics due to Fortran standard violation#1448

Open
kuanchihwang wants to merge 3 commits intoMPAS-Dev:developfrom
kuanchihwang:staging/fix-undefined-pointer-argument
Open

Fix crash in dynamics due to Fortran standard violation#1448
kuanchihwang wants to merge 3 commits intoMPAS-Dev:developfrom
kuanchihwang:staging/fix-undefined-pointer-argument

Conversation

@kuanchihwang
Copy link
Copy Markdown
Contributor

At line 1970 inside the atm_srk3 time stepping subroutine, if the DO_PHYSICS macro is undefined, the diag_physics pointer will not be initialized by the call to mpas_pool_get_subpool, and therefore its pointer association status will remain undefined.

However, at line 2250, this pointer is used as an actual argument to call atm_compute_dyn_tend, which constitutes a Fortran standard violation.

Quoted from Fortran 2023,

15.5.2.4 Argument association
Except in references to intrinsic inquiry functions, a pointer actual argument that corresponds to a nonoptional nonpointer dummy argument shall be pointer associated with a target.

This bug can lead to a runtime crash for models that use MPAS as a dynamical core (e.g., CAM, CAM-SIMA).

Fix this issue by adding the pointer attribute to the diag_physics dummy argument for the atm_compute_dyn_tend subroutine.

In addition, two one-line changes have also been introduced to better conform to the Fortran best practices.

…ciated

At line 1970, if the `DO_PHYSICS` macro is undefined, the `diag_physics` pointer
will not be initialized by the call to `mpas_pool_get_subpool`, and therefore
its pointer association status will remain undefined.

However, at line 2250, this pointer is used as an argument to call `atm_compute_dyn_tend`,
which constitutes a Fortran standard violation.

Quoted from Fortran 2023,

> 15.5.2.4 Argument association
> Except in references to intrinsic inquiry functions, a pointer actual argument that
> corresponds to a nonoptional nonpointer dummy argument shall be pointer associated with
> a target.

This bug can lead to a runtime crash for models that use MPAS as a dynamical core
(e.g., CAM, CAM-SIMA).

Fix this issue by adding the `pointer` attribute to the `diag_physics` dummy argument
for the `atm_compute_dyn_tend` subroutine.
Throughout the `atm_compute_dyn_tend` subroutine, the `tend_physics` pointer
never changes its pointer association status. Add the missing `intent(in)`
attribute for better safety.
In Fortran, explicit initialization of a variable implies the `save` attribute,
which may have surprising result and is not thread-safe.

Avoid doing it to conform to the Fortran best practices.
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