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

Filter out globals in get_local_arrays #370

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion loki/transformations/tests/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ def test_transform_utilites_find_driver_loops(frontend):
def test_transform_utilites_get_local_arrays(frontend, tmp_path):
""" Test :any:`get_local_arrays` utility. """

fcode_mod = """
module global_var_mod
integer, parameter :: arr_size = 20
real :: myarray(arr_size)
end module global_var_mod
"""

fcode = """
module test_get_local_arrays_mod
implicit none
Expand All @@ -471,6 +478,7 @@ def test_transform_utilites_get_local_arrays(frontend, tmp_path):
contains

subroutine test_get_local_arrays(n, dims, start, end, arr)
use global_var_mod, only: myarray
integer, intent(in) :: n, start, end
type(my_dim), intent(in) :: dims
real, intent(inout) :: arr(dims%a(2))
Expand All @@ -489,7 +497,8 @@ def test_transform_utilites_get_local_arrays(frontend, tmp_path):
end subroutine test_get_local_arrays
end module test_get_local_arrays_mod
"""
module = Module.from_source(fcode, frontend=frontend, xmods=[tmp_path])
global_mod = Module.from_source(fcode_mod, frontend=frontend, xmods=[tmp_path])
module = Module.from_source(fcode, frontend=frontend, xmods=[tmp_path], definitions=(global_mod,))
routine = module['test_get_local_arrays']

locals = get_local_arrays(routine, routine.body, unique=True)
Expand Down
2 changes: 2 additions & 0 deletions loki/transformations/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,14 @@ def get_local_arrays(routine, section, unique=True):
Flag whether to return unique instances of each symbol;
default: ``False``
"""
imported_symbols = routine.imported_symbols
arg_names = tuple(a.lower() for a in routine._dummies)
variables = FindVariables(unique=unique).visit(section)

# Filter all variables by argument name to get local arrays
arrays = [v for v in variables if isinstance(v, sym.Array) and not v.parent]
arrays = [v for v in arrays if str(v.name).lower() not in arg_names]
arrays = [v for v in arrays if v.name not in imported_symbols]

return arrays

Expand Down
Loading