Is OpenMP vectoring guaranteed?

Does the OpenMP standard #pragma omp simd make it work, i.e. if compilation fails, if the compiler cannot vectorize the code?

#include <cstdint> void foo(uint32_t r[8], uint16_t* ptr) { const uint32_t C = 1000; #pragma omp simd for (int j = 0; j < 8; ++j) if (r[j] < C) r[j] = *(ptr++); } 

gcc and clang cannot vectorize this, but don't complain at all (unless you use -fopt-info-vec-optimized-missed , etc.).

+5
source share
1 answer

No, this is not guaranteed. Relevant parts of OpenMP 4.5 standard that I could find (my selection):

(1.3) When a thread encounters a simd construct, loop iterations associated with the construct can be performed simultaneously using the SIMD bands available for the flow.

(2.8.1) The simd construct can be applied to a loop to indicate that the loop can be converted to a SIMD loop (that is, several iterations of a loop can be performed simultaneously using SIMD).

(Appendix C) The number of iterations performed simultaneously at any given time is determined by the implementation.

Specific implementation

(1.2.7): The behavior that should be documented by the implementation, and may vary depending on different compatible implementations. Implementations are allowed to define this behavior as unspecified.

+4
source

Source: https://habr.com/ru/post/1274642/


All Articles