-
Notifications
You must be signed in to change notification settings - Fork 388
Description
I was experimenting using OpenMP with an ideal periodic domain and was getting random instabilities in W right at the start of the second OMP thread. (e.g., at column 451 of 900 grid points). This suggested something being used before getting initialized, and it appears to stem from a thread getting past atm_rk_integration_setup and into atm_compute_moist_coefficients before the other OMP thread. (atm_compute_moist_coefficients uses values that are initialized in atm_rk_integration_setup.)
Two possible solutions (mpas_atm_time_integration.F):
- Don't thread atm_rk_integration_setup at all because the only work is copying arrays, which like does not benefit from threading at all.
- Put an OMP BARRIER at the end of atm_rk_integration_setup to prevent any threads from getting ahead into the next routine. (Or alternatively add a barrier at the beginning of atm_compute_moist_coefficients.)
It doesn't seem to work to put a barrier in the calling routine (atm_srk3) between the two calls because it isn't within a parallel section.
Details: MacOS with gfortran 12.4, openmpi/4.1.2, hdf5/1.10.6, netcdf/4.7.4, pio/2.5.7
Openmp-c libomp from homebrew:
"CFLAGS_OMP = -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/21.1.8/include -L/opt/homebrew/opt/llvm/lib -lomp"
Compile-time options:
Build target: gnu
OpenMP support: yes
OpenACC support: no
Default real precision: single
Compiler flags: optimize
I/O layer: PIO 2.x
Run-time settings:
MPI task count: 1
OpenMP max threads: 2
Note: I have not checked bit-for-bit results with and without omp threading. As I recall, the bug did not show up with normal debug options until I add -O2. I thought that maybe the mpas_timer_stop/start timer calls would sync the threads (act as a barrier), but apparently not?