devito icon indicating copy to clipboard operation
devito copied to clipboard

Guard #pragma omp simd with OpenMP version check

Open ggorman opened this issue 8 months ago • 0 comments

Description:

When targeting OpenMP with Devito, we're seeing compilation-time warnings on some older systems:
ignoring #pragma omp simd

This is expected behavior when compiling with an OpenMP version < 4.0, as #pragma omp simd was only introduced in OpenMP 4.0 (released July 2013). In particular, the macro _OPENMP is not sufficient for this use case unless its value is ≥ 201307.

Option 1: We should add a check in the Devito compiler pipeline to conditionally emit #pragma omp simd only if _OPENMP >= 201307.

Option 2: We update the writing out pragma omp simd to include preprocessor guards in the generated code, e.g.:

#if defined(_OPENMP) && _OPENMP >= 201307
#pragma omp simd
#endif

The disadvantage is that this will reduce the readability of the generated code.

Option 3: Alternative considered: Adding -Wno-unknown-pragmas to the compiler flags to silence the warning. However, this is fragile and may suppress legitimate warnings from other unintended or misspelled pragmas.

ggorman avatar Apr 16 '25 09:04 ggorman