bob.sacamento
bob.sacamento

Reputation: 6651

With an OpenACC loop, does each thread get private copies of scalars?

I have a pretty simple code fragment:

$acc data copy(a(:),b(:))
$acc kernels
$acc loop vector
do i=1,1000
  x = a(i)
  b(i) = sqrt(x)
enddo
$acc end kernels
$acc end data

And of course, I could dispense with x easily, but this is an example and x is the point of my question, which is: Does every thread here get its own copy of x automatically, or should I declare it private to keep the various threads from clobbering it?

Upvotes: 2

Views: 714

Answers (1)

Mat Colgrove
Mat Colgrove

Reputation: 5646

In OpenACC, scalars are firstprivate by default so typically there's no need to put them in a "private" clause. The only times you really need to use the "private" clause is for arrays or when a scalar "escapes" the compute region, such as being passed by reference to a device routine or it's value is used outside of the compute region.

Upvotes: 3

Related Questions