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

Undefined behavior in LB halo communication #4077

Closed
jngrad opened this issue Dec 29, 2020 · 0 comments · Fixed by #4078
Closed

Undefined behavior in LB halo communication #4077

jngrad opened this issue Dec 29, 2020 · 0 comments · Fixed by #4078
Assignees

Comments

@jngrad
Copy link
Member

jngrad commented Dec 29, 2020

The LB halo communication framework relies on undefined behavior to calculate the length of strides. The use of int to calculate a pointer offset leads to an integer overflow for LB grids of size 9x9x9 or larger. UBSAN report:

/work/jgrad/espresso/src/core/grid_based_algorithms/halo.cpp:112:19: runtime error: signed integer overflow: 10648 * 202232 cannot be represented in type 'int'
    #0 in halo_dtset(char*, int, _Fieldtype*) /work/jgrad/espresso/src/core/grid_based_algorithms/halo.cpp:112:19
    #1 in halo_communication(HaloCommunicator const*, char*) /work/jgrad/espresso/src/core/grid_based_algorithms/halo.cpp:307:7
    #2 in lb_lbfluid_on_integration_start() /work/jgrad/espresso/src/core/grid_based_algorithms/lb_interface.cpp:128:5
    #3 in on_integration_start() /work/jgrad/espresso/src/core/event.cpp:109:3
    #4 in integrate(int, int) /work/jgrad/espresso/src/core/integrate.cpp:188:3
    #5 in mpi_integrate_local(int, int) /work/jgrad/espresso/src/core/integrate.cpp:405:3

MWE: compile ESPResSo with UBSAN and run the integration test lb_poiseuille_cylinder.py with the following change:

diff --git a/testsuite/python/lb_poiseuille_cylinder.py b/testsuite/python/lb_poiseuille_cylinder.py
index f0dee7984..981c0c23e 100644
--- a/testsuite/python/lb_poiseuille_cylinder.py
+++ b/testsuite/python/lb_poiseuille_cylinder.py
@@ -90,4 +90,6 @@ class LBPoiseuilleCommon:
 
         """
+        # disable periodicity except in the flow direction
+        self.system.periodicity = np.logical_not(self.params['axis'])
         local_lb_params = LB_PARAMS.copy()
         local_lb_params['ext_force_density'] = np.array(

This was never caught in CI because the part of the code in question is not covered by tests.

@jngrad jngrad added this to the Espresso 4.2 milestone Dec 29, 2020
@jngrad jngrad self-assigned this Dec 29, 2020
@kodiakhq kodiakhq bot closed this as completed in #4078 Jan 8, 2021
kodiakhq bot added a commit that referenced this issue Jan 8, 2021
Fixes #4077

Description of changes:
- improve testing of halo communication
- fix undefined behavior in halo communication
- fix mixed type expressions flagged as alerts by LGTM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant