为什么人们在openmp的循环之前声明迭代值? [英] why do people declare iterated values before loop for openmp?
本文介绍了为什么人们在openmp的循环之前声明迭代值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以从我的理解,这些都是正确的所有版本的openmp:
So from what I understand, either of these are correct in ALL versions of openmp:
//int i declared in loop, explicitly private
#pragma omp parallel for
for (int i = 0; i < NUMEL; i++)
{
foo(i);
}
//int i declared outsize loop, but is the iterated value, implicitly private
int i;
#pragma omp parallel for
for (i = 0; i < NUMEL; i++)
{
foo(i);
}
但是,我通常看到第二个而不是第一个。为什么?
However, I more commonly see the second than the first. Why is that?
推荐答案
因为不是每个人都用C ++编写或者定义一个C99兼容的C编译器。一些人喜欢坚持在块的开始处声明变量的旧C要求,以便代码与旧的(C99之前的)C编译器更加兼容。
Because not everybody writes in C++ or targets a C99-compliant C compiler. Some prefer to stick with the old C requirement of having variables declared at the beginning of a block so that the code would be more compatible with older (pre-C99) C compilers.
这篇关于为什么人们在openmp的循环之前声明迭代值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文