making a variable static private to each thread using openmp

僤鯓⒐⒋嵵緔 提交于 2019-12-12 01:56:45

问题


I need to make t static to each thread, how can I do that? I tried this but t is not static private to each thread.

#pragma omp Parallel
{
    traceRays();
}
...
...
void traceRays()
{
    static float t = 1;
}

回答1:


if the static variable is not declared in the parallel region, then everytime you attempt to define in the parallel region use: #omp parallel private(t)




回答2:


You can do it by just making t threadprivate:

void traceRays()
{
    static float t = 1;
    #pragma omp threadprivate(t)
}


来源:https://stackoverflow.com/questions/27269170/making-a-variable-static-private-to-each-thread-using-openmp

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