Repository navigation
Add a basic PSyclone test to catch PSyclone issues early for Transmute #795
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
Merged
James Bruten (james-bruten-mo)
merged 5 commits into
MetOffice:main
from
MetBenjaminWent:psyclone-test
Oct 22, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2cde39b
Add a basic PSyclone test to catch force_privates and ignore_depende…
MetBenjaminWent 8ace361
Check the failure state, and update the comments with the test
MetBenjaminWent 37acc33
remove debugging prints
MetBenjaminWent f29b5b9
Merge branch 'main' into psyclone-test
MetBenjaminWent 109ab41
Merge branch 'main' into psyclone-test
james-bruten-mo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import pytest | ||
| import warnings | ||
| with warnings.catch_warnings(): | ||
| from pyparsing.exceptions import PyparsingDeprecationWarning | ||
| warnings.filterwarnings("ignore", category=PyparsingDeprecationWarning) | ||
| from psyclone.psyir.backend.fortran import FortranWriter | ||
| from psyclone.psyir.frontend.fortran import FortranReader | ||
| from psyclone.psyir.nodes import ( | ||
| Loop) | ||
| from psyclone.transformations import OMPParallelLoopTrans | ||
|
|
||
|
|
||
| def test_omplooptrans_force_private(): | ||
| ''' | ||
| Test to assist with catching common errors with applying Transmute to | ||
| physics source. Passing 'force_private' and 'ignore_dependencies_for' to | ||
| a transformation is a common pattern and fail point. | ||
| Apply OMPParallelLoopTrans and OMPLoopTrans on a nested loop structure, | ||
| which contains a LHS RHS assignment and a single dimension array on the | ||
| inner loop. | ||
| The LHS RHS assignment, PSyclone will fail safely on assuming it is unsafe | ||
| in a parallel section. | ||
| The single dimension array, psyclone will assume it's shared currently, | ||
| however as its only for the inner loop, and parallelised around the outer, | ||
| it needs to be private. | ||
| ''' | ||
| fread = FortranReader() | ||
| # Example of looping structure with LHS RHS which PSyclone may perceive as | ||
| # a false dependency, and an array which has a single dimension on the, | ||
| # inner loop | ||
| psyir = fread.psyir_from_source(''' | ||
| module my_mod | ||
| contains | ||
| subroutine my_subroutine() | ||
| integer :: ji, jj, jk, jpkm1, jpjm1, jpim1 | ||
| real, dimension(10, 10, 10) :: array1, array2 | ||
| do jk = 2, jpkm1, 1 | ||
| do jj = 2, jpjm1, 1 | ||
| do ji = 2, jpim1, 1 | ||
| array2(ji) = array2(ji) + 1 | ||
| array1(ji) = array2(ji) | ||
| enddo | ||
| enddo | ||
| enddo | ||
| end subroutine | ||
| end module my_mod''') | ||
| omplooptrans = OMPParallelLoopTrans() | ||
| loop = psyir.walk(Loop)[0] | ||
| omplooptrans.apply(loop, force_private=['array1','array2'], ignore_dependencies_for=['array1','array2']) | ||
| expected = '''\ | ||
| !$omp parallel do default(shared) private(array1,array2,ji,jj,jk) schedule(auto) | ||
| do jk = 2, jpkm1, 1 | ||
| do jj = 2, jpjm1, 1 | ||
| do ji = 2, jpim1, 1 | ||
| array2(ji) = array2(ji) + 1 | ||
| array1(ji) = array2(ji) | ||
| enddo | ||
| enddo | ||
| enddo | ||
| !$omp end parallel do\n''' | ||
|
|
||
| fwrite = FortranWriter() | ||
| gen = fwrite(psyir) | ||
| assert expected in gen | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMPParallelLoopTrans has the
privatise_arraysoption which will hopefully do away with the need for the 'force_private` - worth a try.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I've just realised this doesn't show up in our docs so I'm talking to LonelyCat124 (@LonelyCat124) about that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussing with LonelyCat124 (@LonelyCat124), I realise I was wrong -
privatise_arraysisn't going to work with this transformation :-(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to keep this test mirroring what is in the majority of the Transmute scripts currently on trunk as a means to catch when there is a change in the PSyclone repo that affects the scripts, as an early waning system basically. We also don't have any Transmute testing coverage really, so this needs to act as that till we have a better solution.
If we align this test now with the PSyclone repo, this test will not serve it's purpose.
Many thanks for the info tho.