简体   繁体   English

在OpenMP中将数组声明为firstprivate-C

[英]Declaring arrays as firstprivate in OpenMP - C

I'm beginning to dive into OpenMP and I'm not sure I fully understand how firstprivate would deal with arrays. 我开始研究OpenMP,但不确定我是否完全了解firstprivate将如何处理阵列。

If I had code such as: 如果我有如下代码:

int array[5] = {0, 1, 2, 3, 4};
int i;    
#pragma omp parallel for firstprivate(array)
for (i=0; i<SOME_LENGTH; i++) {
  // something using array as a right hand operand
}

Would the array be copied to each thread? 将数组复制到每个线程吗? What if it was a more complex structure and not a simple int ? 如果它是一个更复杂的结构而不是一个简单的int呢?

Is the memory itself copied or the values? 存储器本身是复制的还是值?

Also if you can point me in the direction of more documentation I would really appreciate it. 另外,如果您可以向我介绍更多文档,我将不胜感激。

Thanks! 谢谢!

Yes, each thread gets its own instance of the variable, initialized to the value of that variable. 是的,每个线程都有自己的变量实例,并初始化为该变量的值。

Documentation seems to be a bit sparse beside the original documentation and some basic tutorials. 文档似乎比原始文档和一些基本教程稀疏。

As per 2.15.3.4 of OpenMP 4.5 , the elements are copied: 根据OpenMP 4.5的 2.15.3.4,复制元素:

For an array of elements of non-array type, each element is initialized as if by assignment from an element of the original array to the corresponding element of the new array. 对于非数组类型的元素数组,每个元素都被初始化,就好像是通过从原始数组的元素到新数组的相应元素的赋值一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM