Skip to content

Commit

Permalink
Fix replicate warning and check in test
Browse files Browse the repository at this point in the history
  • Loading branch information
reuterbal committed Nov 22, 2024
1 parent 843925d commit 2895e0c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion loki/batch/sgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _populate_filegraph(self, sgraph, item_factory, config=None, item_filter=Non
if non_replicate_items:
warning((
f'File {file_item.name} will be replicated but contains items '
f'that are marked as non-replicated: {", ".join(non_replicate_items)}'
f'that are marked as non-replicated: {", ".join(item.name for item in non_replicate_items)}'
))
file_item.config['replicate'] = replicate

Expand Down
33 changes: 27 additions & 6 deletions loki/transformations/build_system/tests/test_file_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from loki.batch import Scheduler, SchedulerConfig
from loki.frontend import available_frontends, OMNI
from loki.logging import log_levels
from loki.transformations.build_system import FileWriteTransformation


Expand Down Expand Up @@ -207,7 +208,8 @@ def test_file_write_module_imports(frontend, tmp_path, enable_imports, import_le


@pytest.mark.parametrize('frontend', available_frontends())
def test_file_write_replicate(tmp_path, frontend):
@pytest.mark.parametrize('have_non_replicate_conflict', [False, True])
def test_file_write_replicate(tmp_path, caplog, frontend, have_non_replicate_conflict):
fcode_a = """
module a_mod
implicit none
Expand All @@ -220,7 +222,11 @@ def test_file_write_replicate(tmp_path, frontend):
integer :: b
end module b_mod
"""
fcode_c = """
if have_non_replicate_conflict:
other_routine = "subroutine not_c()\n end subroutine not_c"
else:
other_routine = ""
fcode_c = f"""
module c_mod
contains
subroutine c(val)
Expand All @@ -229,6 +235,7 @@ def test_file_write_replicate(tmp_path, frontend):
integer, intent(inout) :: val
val = val + a + b
end subroutine c
{other_routine}
end module c_mod
"""
fcode_d = """
Expand All @@ -255,6 +262,9 @@ def test_file_write_replicate(tmp_path, frontend):
# Expected items in the dependency graph
expected_items = {'a_mod', 'b_mod', 'c_mod#c', '#d'}

if have_non_replicate_conflict:
expected_items |= {'c_mod#not_c'}

# Create the Scheduler
config = SchedulerConfig.from_dict({
'default': {
Expand All @@ -267,6 +277,7 @@ def test_file_write_replicate(tmp_path, frontend):
},
'routines': {
'b_mod': {'replicate': False},
'not_c': {'replicate': False},
'd': {'role': 'driver', 'replicate': False},
}
})
Expand All @@ -281,10 +292,20 @@ def test_file_write_replicate(tmp_path, frontend):

# Generate the CMake plan
plan_file = tmp_path/'plan.cmake'
scheduler.write_cmake_plan(
filepath=plan_file, mode=config.default['mode'], buildpath=out_path,
rootpath=tmp_path
)

caplog.clear()
with caplog.at_level(log_levels['WARNING']):
scheduler.write_cmake_plan(
filepath=plan_file, mode=config.default['mode'], buildpath=out_path,
rootpath=tmp_path
)
if have_non_replicate_conflict:
assert len(caplog.records) == 1
assert 'c.f90' in caplog.records[0].message
assert 'c_mod#not_c' in caplog.records[0].message
else:
assert not caplog.records


# Validate the plan file content
plan_pattern = re.compile(r'set\(\s*(\w+)\s*(.*?)\s*\)', re.DOTALL)
Expand Down

0 comments on commit 2895e0c

Please sign in to comment.