I have been chasing wrong results compared with the cpu version of my code and it turned out to be an issue with a scalar variable that I assumed would be copied to the device whenever entering the kernel (which was generated with the openacc kernels construct).
I have a for loop decorated with a kernels and loop independent statement within a member function. Within the for loop I need to access a scalar (int) variable, which is a data member of the same class.
The data member gets initialized in the class’ constructor, i.e. set to 0, and is later changed to another value in some setup member function. This setup member function gets called before the first launch of the kernel(the kernel gets launched many times).
To my surprise, the value of the scalar data member is always 0 in the kernel and not the one that got set in the setup member function.
Is this the expected behavior according to the standard or the PGI implementation?
Is there a difference between scalar data members and scalar local variables when it comes to the behavior of implicit/automatic copying in? I have read about the handling of global variables using the declare statement and understand that those might get copied to the device upon acc initialization and that an update directive is needed if a later assigned value is needed.
I am a bit concerned about this automatic copy behavior because it seems to work as expected most of the times, but this is the second time I am tracing wrong results due to an issue with the automatic copying of scalar variables . It seems that I haven’t fully understood what is happening behind the scenes.
Could you please shed some light on this issue.
PS1: pcopyin(this[0:1]) is used at several locations that are passed before the kernel launch and also before the setup member function. So maybe the scalar member gets copied to the device at the first instance of such a pcopyin statement?
PS2: I have also searched in the forum but haven’t found a recent post explaining it in detail. There seemed to be some confusion about the private clause, but no mention of local scalars vs. scalar members.