-
Notifications
You must be signed in to change notification settings - Fork 254
Description
Environment
- REBOUND Version: [4.4.10] Latest from GitHub (attempting to compile from source with OpenMP support)
- API interface: Python (compiling C extension with OpenMP), pip install rebound seems to work but compiles without openmp support.
- Operating System (including version): Linux (Rocky Linux on HPC cluster)
Describe the bug
Compilation with OpenMP support fails due to invalid return statements within OpenMP parallel regions in src/collision.c. :Line 274, 332. The OpenMP specification prohibits branching out of structured blocks, but the code contains return statements inside #pragma omp parallel for loops that cause GCC to throw compilation errors.
To Reproduce
- Attempt to compile REBOUND from source with OpenMP support using flags like -fopenmp -O3
- The compilation fails with errors:
src/collision.c: In function 'reb_collision_search':
src/collision.c:274:41: error: invalid branch to/from OpenMP structured block
274 | if (reb_sigint > 1) return;
| ^~~~~~
src/collision.c:332:41: error: invalid branch to/from OpenMP structured block
332 | if (reb_sigint > 1) return;
| ^~~~~~
The problematic code pattern occurs at lines 274 and 332:
#pragma omp parallel for schedule(guided)
for (int i=0;i<N;i++){
#ifndef OPENMP
if (reb_sigint > 1) return; // <- This causes the compilation error
#endif // OPENMP
// ... rest of loop
}
Additional context
The code checks #ifndef OPENMP, but GCC with -fopenmp defines _OPENMP (with underscore), not OPENMP, the return statements are always included when compiling with OpenMP which violate the OpenMP specification within structured blocks.
Installing via pip install rebound works fine (but compiles without OpenMP in my case),
Compiler: GCC 11.2.0 on HPC environment (Flatiron/Rusty)
Potential solutions:
Macro fixes maybe to use _OPENMP instead of OPENMP? Also a flag-based early termination check inplace of return statements?
Name/Affiliation
Arpit Arora, University of Washington.