Skip to content

Commit

Permalink
Merge pull request #313 from ecmwf-ifs/naml-fix-pragma-params-multiline
Browse files Browse the repository at this point in the history
IR: Fix `get_pragma_params` for multiline pragmas
  • Loading branch information
reuterbal authored May 10, 2024
2 parents 5300280 + ddb3e0d commit 61c93b2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 2 additions & 0 deletions loki/ir/pragma_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ def get_pragma_parameters(pragma, starts_with=None, only_loki_pragmas=True):
if only_loki_pragmas and p.keyword.lower() != 'loki':
continue
content = p.content or ''
# Remove any line-continuation markers
content = content.replace('&', '')
if starts_with is not None:
if not content.lower().startswith(starts_with.lower()):
continue
Expand Down
34 changes: 34 additions & 0 deletions loki/ir/tests/test_pragma_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ def test_get_pragma_parameters(content, starts_with, ref):
assert get_pragma_parameters(pragma_list, starts_with=starts_with) == ref


@pytest.mark.parametrize('frontend', available_frontends())
def test_get_pragma_parameters_multiline(frontend):
"""
Test correct extraction of Loki pragma parameters from pragmas
with line-contunation.
"""
fcode = """
subroutine test_pragmas_map(a)
implicit none
real, intent(in) :: a(:,:)
integer :: i, j, k
!$OMP PARALLEL &
!$OMP & PRIVATE(i, j) &
!$OMP & FIRSTPRIVATE( &
!$OMP & n, a, b &
!$OMP & )
end subroutine test_pragmas_map
""".strip()
routine = Subroutine.from_source(fcode, frontend=frontend)
pragmas = FindNodes(Pragma).visit(routine.body)

assert len(pragmas) == 1
assert pragmas[0].keyword == 'OMP'
params = get_pragma_parameters(pragmas[0], only_loki_pragmas=False)
assert len(params) == 3
assert params['PARALLEL'] == None
assert params['PRIVATE'].strip() == 'i, j'
assert params['FIRSTPRIVATE'].strip() == 'n, a, b'

assert fgen(pragmas[0]) == '!$OMP PARALLEL PRIVATE( i, j ) FIRSTPRIVATE( n, a, b )'


@pytest.mark.parametrize('frontend', available_frontends())
def test_tools_pragma_inlining(frontend):
"""
Expand Down
2 changes: 1 addition & 1 deletion scripts/loki_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def convert(
remove_code_trafo = scheduler.config.transformations.get('RemoveCodeTransformation', None)
if not remove_code_trafo:
remove_code_trafo = RemoveCodeTransformation(
remove_marked_regions=True, remove_dead_code=False,
remove_marked_regions=True, remove_dead_code=False, kernel_only=True,
call_names=('ABOR1', 'DR_HOOK'), intrinsic_names=('WRITE(NULOUT',)
)
scheduler.process(transformation=remove_code_trafo)
Expand Down

0 comments on commit 61c93b2

Please sign in to comment.