omp with gcc and intel compiler

主宰稳场 提交于 2020-01-06 01:56:50

问题


According to this question, the use of threadprivate with openmp is problematic. Here is a minimum (non-)working example of the problem:

#include"omp.h"
#include<iostream>

extern const int a;
#pragma omp threadprivate(a)

const int a=2;

void my_call(){
    std::cout<<a<<std::endl;
};

int main(){
#pragma omp parallel for
    for(unsigned int i=0;i<8;i++){
        my_call();
    }
}

This codes compiles with intel 15.0.2.164 but not with gcc 4.9.2-10. gcc says:

g++ -std=c++11  -O3 -fopenmp    -O3 -fopenmp  test.cpp   -o test
test.cpp:5:29: error: ‘a’ declared ‘threadprivate’ after first use
#pragma omp threadprivate(a)

I would be very happy to find a way to compile it with gcc.

Note: I know that global variables are a nightmare, but this example is the coming from a code I haven't written and that I need to use... It's >11000 lines and I don't want to rewrite everything.

来源:https://stackoverflow.com/questions/30663476/omp-with-gcc-and-intel-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!