gpt4 book ai didi

c++ omp原子捕获-语法?

转载 作者:太空狗 更新时间:2023-10-29 21:04:12 25 4
gpt4 key购买 nike

非常简单的代码,看不出为什么编译器会抛出关于我使用 omp atomic capture 的错误

//我的类.h

class my_class
{

my_class()
{ }

static int class_int;
static int get_next_int();

};

//我的类.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 , 像往常一样

最佳答案

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

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

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

关于c++ omp原子捕获-语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11850367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com