使用openmp使每个线程的静态变量私有 [英] making a variable static private to each thread using openmp

查看:269
本文介绍了使用openmp使每个线程的静态变量私有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使每个线程的t静态,我该怎么做?我试过了,但是t不是每个线程的静态私有变量.

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

解决方案

如果未在并行区域中声明静态变量,则每次尝试在并行区域中定义时,请使用:#omp parallel private(t)

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;
}

解决方案

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)

这篇关于使用openmp使每个线程的静态变量私有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆