Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions rose-stem/bin/tests/test_basic_psyclone.py
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'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OMPParallelLoopTrans has the privatise_arrays option which will hopefully do away with the need for the 'force_private` - worth a try.

Copy link
Copy Markdown
Contributor

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.)

Copy link
Copy Markdown
Contributor

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_arrays isn't going to work with this transformation :-(

Copy link
Copy Markdown
Contributor Author

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.

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
Loading