3

非常简单的代码,看不出为什么编译器会抛出关于我使用的错误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;
}

编译器错误:

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

可能与它有关static吗?我无法想象为什么...

如果我pragma omp critical改用,那么它工作正常(没有编译器错误)。

PS我有 #include <omp.h> 所有.h和.cpp。我-fopenmp像往常一样链接到

4

2 回答 2

4

capture子句是在 OpenMP 3.1 中引入的。您需要一个兼容的编译器:

  • 从 v4.7 开始的 GCC
  • 自 v10.1 以来的英特尔编译器
  • 从 v12.3 开始的 Oracle Solaris Studio
  • 许多其他编译器除了...
  • MSVC(所有版本,包括 2012),不支持高于 2.0 的 OpenMP 版本。

GCC 4.4.5 不支持 OpenMP 3.1。它仅支持 OpenMP 3.0。

于 2012-08-08T10:51:35.283 回答
0

如果您使用的是 Microsoft 编译器,它不支持指令的子句。omp atomic

将您的代码更改为 just#pragma omp atomic并且根据 ms 文档,编译器将做正确的事情。让我怀疑。:)

于 2012-08-07T18:40:15.497 回答