问题描述
#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 ?
}
谢谢!
附言如果局部变量是自动私有的,使用 private 子句有什么意义?
P.S. If local variables are automatically private, what is the point of using private clause?
推荐答案
是的,局部变量是自动私有的.
Yes, local variables are automatically private.
存在 private 子句的原因是 您不必更改代码.
The reason for the existence of the private clause is so that you don't have to change your code.
没有private 子句的唯一并行化以下代码的方法
The only way to parallelize the following code without the private clause
int i,j;
#pragma omp parallel for private(j)
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
//do something
}
}
是更改代码.例如像这样:
is to change the code. For example like this:
int i
#pragma omp parallel for
for(i = 0; i < n; i++) {
int j;
for(j = 0; j < n; j++) {
//do something
}
}
这是完全有效的 C89/C90 代码,但 OpenMP 的目标之一是不必更改您的代码,除非添加可以在编译时启用或禁用的 pragma 语句.
That's perfectly valid C89/C90 code but one of the goals of OpenMP is not have to change your code except to add pragma statements which can be enabled or disabled at compile time.
这篇关于OpenMP:局部变量是否自动私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)