Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in intent and initialisation of spectral arrays #243

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

samhatfield
Copy link
Collaborator

Let's track the PSP arrays through the inverse transform adjoint:

The intent changes from OUT to INOUT!!!

On top of that the packing logic in PRFI1BAD is += even though the spectral arrays are uninitialised. This was triggering compiler-specific failing of the INV_TRANS/AD test in this PR.

This PR resolves the inconsistency in intents and prevents uninitialised array bugs from appearing in PRFI1BAD by changing the packing logic to just =.

@samhatfield samhatfield added the bug Something isn't working label Mar 24, 2025
@samhatfield samhatfield changed the title Fix bug in intent and initialistion of spectral arrays Fix bug in intent and initialisation of spectral arrays Mar 28, 2025
@samhatfield samhatfield added this to the Version 1.6.0 milestone Mar 28, 2025
@marsdeno marsdeno self-assigned this Mar 31, 2025
@@ -88,8 +88,8 @@ SUBROUTINE PRFI1BAD(KM,PIA,PSPEC,KFIELDS,KFLDPTR)
IFLD = KFLDPTR(JFLD)
DO J=1,ILCM
INM = IOFF+(ILCM-J)*2
PSPEC(IFLD,INM ) = PSPEC(IFLD,INM ) + PIA(J+2,IR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would want to be very sure that we're not relying on the += anywhere before changing the code like this. If we are relying on values already in PSPEC in any call to PRFI1BAD, the right fix for this issue might be to zero the 5 arrays (spvor, spdiv, spscalar, spsc2, spsc3b) at the beginning of LTINV_CTLAD ?

REAL(KIND=JPRB) ,OPTIONAL,INTENT(INOUT) :: PSPSC2(:,:)
REAL(KIND=JPRB) ,OPTIONAL,INTENT(INOUT) :: PSPSC3A(:,:,:)
REAL(KIND=JPRB) ,OPTIONAL,INTENT(INOUT) :: PSPSC3B(:,:,:)
REAL(KIND=JPRB) ,OPTIONAL,INTENT(OUT) :: PSPVOR(:,:)
Copy link
Collaborator

Choose a reason for hiding this comment

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

LTINVAD is being called inside a loop in ltinv_ctlad, so intent(out) on these arguments is not conceptually correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants