Abhishek
Abhishek

Reputation: 87

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?

Upvotes: 0

Views: 170

Answers (1)

sehe
sehe

Reputation: 393467

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

Upvotes: 1

Related Questions