简体   繁体   English

OpenMP并行节的firstpriv中允许使用非POD数据类型吗?

[英]Non-POD datatypes allowed in firstprivate of OpenMP parallel section?

Can we specify a std::vector object in the firstprivate clause of a openmp task pragma? 我们可以在openmp任务编译指示的firstprivate子句中指定std :: vector对象吗?

Is is possible to make a vector object firstprivate? 可以使向量对象成为第一个私有对象吗?

It compiles and runs correctly... It is always threadsafe? 它可以编译并正确运行...它始终是线程安全的吗?

Yes you can 是的你可以

  1. The firstprivate variable is initialized once per thread 每个线程将firstprivate变量初始化一次
  2. the firstprivate object is constructed by calling its copy constructor with the master thread's copy of the variable as its argument 通过使用其主线程的变量副本作为参数调用其副本构造函数来构造firstprivate对象

So basically as long as 所以基本上只要

  • the copy constructor and assignment operator for the class are accessible 该类的复制构造函数和赋值运算符可访问
  • they provide deep copy (value) semantics 它们提供了深层复制 (值)语义

Note that the STL containers satisfy these criteria but you may alter the semantics by doing a container of (non-shared) pointer elements, etc. 请注意 ,STL容器满足这些条件,但是您可以通过对(非共享的)指针元素进行容器化等来更改语义。

You're good to go 你很好去

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

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