From fc285c14e31d934235ab6a3ece2c98b59aa1c11f Mon Sep 17 00:00:00 2001 From: markus <markus.holzer@fau.de> Date: Tue, 5 Nov 2019 00:35:32 +0100 Subject: [PATCH] codegen.py fix: bug in the communication of corner directions In the function comm_directions the corner directions were treated wrongly. This fix also generalized comm_directions so it will also work for higher dimensions --- RELEASE-VERSION | 1 + pystencils_walberla/codegen.py | 31 ++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 RELEASE-VERSION diff --git a/RELEASE-VERSION b/RELEASE-VERSION new file mode 100644 index 0000000..14eb02b --- /dev/null +++ b/RELEASE-VERSION @@ -0,0 +1 @@ +0.2.5.dev3+772fdd77df \ No newline at end of file diff --git a/pystencils_walberla/codegen.py b/pystencils_walberla/codegen.py index a0d5331..3a0ea97 100644 --- a/pystencils_walberla/codegen.py +++ b/pystencils_walberla/codegen.py @@ -188,7 +188,7 @@ def generate_pack_info(generation_context, class_name: str, fields_accessed = set() for terms in directions_to_pack_terms.values(): for term in terms: - assert isinstance(term, Field.Access) #and all(e == 0 for e in term.offsets) + assert isinstance(term, Field.Access) # and all(e == 0 for e in term.offsets) fields_accessed.add(term) field_names = {fa.field.name for fa in fields_accessed} @@ -252,7 +252,7 @@ def generate_pack_info(generation_context, class_name: str, def generate_mpidtype_info_from_kernel(generation_context, class_name: str, - assignments: Sequence[Assignment], kind='pull', namespace='pystencils',): + assignments: Sequence[Assignment], kind='pull', namespace='pystencils', ): assert kind in ('push', 'pull') reads = set() writes = set() @@ -345,10 +345,23 @@ def default_create_kernel_parameters(generation_context, params): def comm_directions(direction): - yield direction - for i in range(len(direction)): - if direction[i] != 0: - dir_as_list = list(direction) - dir_as_list[i] = 0 - if not all(e == 0 for e in dir_as_list): - yield tuple(dir_as_list) + if all(e == 0 for e in direction): + yield direction + binary_numbers_list = binary_numbers(len(direction)) + for comm_direction in binary_numbers_list: + for i in range(len(direction)): + if direction[i] == 0: + comm_direction[i] = 0 + if direction[i] == -1 and comm_direction[i] == 1: + comm_direction[i] = -1 + if not all(e == 0 for e in comm_direction): + yield tuple(comm_direction) + + +def binary_numbers(n): + result = list() + for i in range(1 << n): + binary_number = bin(i)[2:] + binary_number = '0' * (n - len(binary_number)) + binary_number + result.append((list(map(int, binary_number)))) + return result -- GitLab