Very simple code, cannot see why compiler throws an error about my use of omp atomic capture
// my_class.h
class my_class
{
my_class()
{ }
static int class_int;
static int get_next_int();
};
// my_class.cpp
int my_class::get_next_int()
{
int next_int;
#pragma omp atomic capture
next_int = class_int++;
return next_int;
}
Compiler error:
my_class.cpp: In static member function 'static int
my_class::get_next_int()':
my_class.cpp:2069: error: expected end of line before 'capture'
my_class.cpp:2070: error: invalid operator for '#pragma omp atomic' before '=' token
Might it have something to do with static? I can’t imagine why…
If I use pragma omp critical instead, then it works fine (no compiler error).
PS I have #include <omp.h> in all .h and .cpp. And I link with -fopenmp , as usual
The
captureclause was introduced in OpenMP 3.1. You need a compliant compiler:GCC 4.4.5 does not support OpenMP 3.1. It only supports OpenMP 3.0.