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

OMP PRIVATE variable not initialised #1336

Open
ukmo-ccbunney opened this issue Dec 20, 2024 · 1 comment
Open

OMP PRIVATE variable not initialised #1336

ukmo-ccbunney opened this issue Dec 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ukmo-ccbunney
Copy link
Collaborator

ukmo-ccbunney commented Dec 20, 2024

Describe the bug
In w3wavemd there is a NMIN variable used in an OMP loop that is PRIVATE, but it is not initialised. This could lead to undefined behaviour when running with OMP threading.

Loop is here:

WW3/model/src/w3wavemd.F90

Lines 3668 to 3674 in 488e3c8

NMIN = NSEA
!
#ifdef W3_OMPG
!$OMP PARALLEL PRIVATE (IPROC,NLOC,ISEA,JSEA,ISPROC,IXY,NMIN)
!$OMP DO SCHEDULE (DYNAMIC,1)
#endif
DO IPROC=1, NAPROC

Use of potentially uninitialized value in the above loop is here:

NMIN = MIN ( NMIN , NLOC )

Proposed solution
I believe the problem should be resolved by using FIRSTPRIVATE(NMIN) in the OMP directive for that loop, i.e.:

!$OMP PARALLEL PRIVATE (IPROC,NLOC,ISEA,JSEA,ISPROC,IXY) FIRSTPRIVATE(NMIN) 

Additional context
I have not observed any undefined behaviour in OMP running of the SMC grid, but this is an example something that could catch us out in the future.

There may be other cases where we should be using FIRSTPRIVATE on variables for OMP loops too.

Related: #1017

@ukmo-ccbunney ukmo-ccbunney added the bug Something isn't working label Dec 20, 2024
@ukmo-ccbunney
Copy link
Collaborator Author

I'm raising this as an issue so we can keep track of it as I don't have time to fix this and run the regression tests before I down-tools for Xmas!

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

No branches or pull requests

1 participant