Global pointer to fixed size array does not work

The global pointer like

    #define DIM 3
    double (*p)[DIM];

does not work well. The memory error as

Failing in Thread:1
call to cuStreamSynchronize returned error 700: Illegal address during kernel execution

arises when the double array is accessed after memory allocation.
The whole code for the error is as follows;

include
include

using namespace std;

define DIM 3

static double (*Position)[DIM];
#pragma acc declare create(Position)

const int N=10;
const int W=3;

static void allocatePosition( void ){
Position=(double (*)[DIM])malloc(sizeof(double [DIM])*N);
#pragma acc enter data create(Position[0:N][0:DIM])
}

static void calculatePosition( void ){
#pragma acc kernels
#pragma acc loop independent
for(int iP=0;iP<N;++iP){
Position[iP][0]=iP/W;
Position[iP][1]=iP%W;
Position[iP][2]=0;
}
}

static void outputPosition( void ){
#pragma acc update host(Position[0:N][0:DIM])
for(int iP=0;iP<N;++iP){
printf(“%d: %e %e %e\n”,iP,Position[iP][0],Position[iP][1],Position[iP][2]);
}
}

int main(int argc, char *argv){
allocatePosition();
calculatePosition();
outputPosition();
return 0;
}

This looks to be a duplicate of Pointer to fixed size array does not work.

Same answer in that you’re missing the attach.

static void allocatePosition( void ){
Position=(double (*)[DIM])malloc(sizeof(double [DIM])*N);
#pragma acc enter data create(Position[0:N][0:DIM]) attach(Position)
}

-Mat

Sorry for the duplication. With the bracket <> after #include, this post was temporally hidden. So, I’ve post another one.
With the directive “attach”, the memory error was removed.
Thank you.