Reputation: 19075
I am testing clang 10.0 on an c++17 & OpenMP project and get errors when #pragma omp parallel for
is used on range-based for.
Release notes for clang 10, in the OpenMP Support in Clang section, say quite clearly:
When I compile a MWE with clang++-10 -fopenmp -std=c++17
(see https://godbolt.org/z/fdTeMo for online compiler):
#include<vector>
#include<iostream>
int main(int argc, char** argv){
std::vector<int> ii{0,11,22,33,44,55,66};
#pragma omp parallel for
for(int& i: ii){
std::cerr<<i<<std::endl;
}
}
I get:
<source>:6:5: error: statement after '#pragma omp parallel for' must be a for loop
for(int& i: ii){
^
1 error generated.
Compiler returned: 1
What's up?
Upvotes: 1
Views: 622
Reputation: 73196
Support for range-based for loops was added to OpenMP 5.0, and, as is also described in the Clang 10 Release Notes that you link to, you need to explicitly use the -fopenmp-version=50
option to activate support for it:
OpenMP Support in Clang
Use
-fopenmp-version=50
option to activate support for OpenMP 5.0.
Thus, if we expand you compilation command to clang++-10 -fopenmp -fopenmp-version=50 -std=c++17
, the OMP pragma accepts the range based for loop that follows it.
DEMO.
Upvotes: 4