OpenMP:是局部变量自动私有吗? [英] OpenMP: are local variables automatically private?

查看:488
本文介绍了OpenMP:是局部变量自动私有吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#pragma omp parallel
{
    int x; // private to each thread ?
}

#pragma omp parallel for
for (int i=0; i<1000; ++i)
{
    int x; // private to each thread ?
}

谢谢!

PS如果局部变量自动为私有,使用 private 子句的意义是什么?

P.S. If local variables are automatically private, what is the point of using private clause?

推荐答案


PS如果局部变量是自动私有的,使用private子句的意义是什么?

P.S. If local variables are automatically private, what is the point of using private clause?

需要在函数开始处声明所有变量,这仍然是主流风格。

The point is presumably that in earlier versions of C you needed to declare all variables at the beginning of the function, and this is still the prevailing style.

也就是说,代码如下:

#pragma omp parallel
{
    int x;
}

是C ++的首选方式。有些版本的C不能使用这段代码,你需要使用 private 子句。

is the preferred way in C++. But in some versions of C you cannot use this code, you need to use the private clause.

这篇关于OpenMP:是局部变量自动私有吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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