Hello everyone,
I’m trying to implement some plasma physics codes on GPUs. However, I have a problem of the following type:
I have two classes: base and derived. The derived class contains an additional pointer that points to a member array of the base class. When I compile the code, there is no problem. However, the following error
FATAL ERROR: variable in data clause is partially present on the device: name=fderived
appears at runtime. I do understand why it occurs: it is due to the member vals1D_
of the derived class (see the code below). My question is how to correctly create vals1D_
on the device, or attach it to vals_
of the base class? In other words, I want to attach the pointer vals1D_
of the derived class to vals_
of the base class on GPU. I have tried different ways, and all led to the mentioned error.
Here is the code
#include <iostream>
#include <vector>
#include <iomanip>
template <typename U, typename T>
class base
{
public:
U size_;
T *vals_;
base(U size): size_{size}
{
vals_ = new T [size_];
#ifdef _OPENACC
#pragma acc enter data copyin(this)
#pragma acc enter data create(vals_[0:size_])
#endif
}
/* Update self */
void updateSelf()
{
#ifdef _OPENACC
#pragma acc update self(vals_[0:size_])
#endif
}
/* Update device */
void updateDevice()
{
#ifdef _OPENACC
#pragma acc update device(vals_[0:size_])
#endif
}
#ifdef _OPENACC
#pragma acc routine seq
#endif
inline T& operator() (U i)
{
return vals_[i];
}
/* Destructor */
~base()
{
#ifdef _OPENACC
#pragma acc exit data delete(vals_[0:size_])
#endif
if(vals_ != nullptr)
delete [] vals_;
}
};
template <typename U, typename T>
class derived : public base<U, T>
{
public:
T *vals1D_;
derived(U size) : base<U, T>(size)
{
vals1D_ = base<U, T>::vals_;
#ifdef _OPENACC
#endif
}
~derived()
{
}
};
int main()
{
unsigned int s = 10;
derived<unsigned int, double> fderived(s);
for(unsigned int i = 0; i < s; i++)
fderived.vals_[i] = i * i;
fderived.updateDevice();
#pragma acc parallel loop present(fderived)
for(unsigned int i = 0; i < s; i++)
fderived.vals_[i] = 5;
return 0;
}