简体   繁体   中英

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?

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
  2. the firstprivate object is constructed by calling its copy constructor with the master thread's copy of the variable as its argument

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.

You're good to go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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