# Atomic region and expression problem

Hello. I want to use atomic expression to update the values of the array res.

here is the code.

``````#pragma acc atomic update
if(floor(TFpoint[j][i].x) ==TFpoint[j][i].x && floor(TFpoint[j][i].y) ==TFpoint[j][i].y){

res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)TFpoint[j][i].x]][F[j][i]]=res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)TFpoint[j][i].x]][F[j][i]]+1;
}
else if(floor(TFpoint[j][i].x) ==TFpoint[j][i].x){

res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)TFpoint[j][i].x]][F[j][i]]=res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)TFpoint[j][i].x]][F[j][i]]+(ceil(TFpoint[j][i].y)-TFpoint[j][i].y);

res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)TFpoint[j][i].x]][F[j][i]]=res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)TFpoint[j][i].x]][F[j][i]]+(TFpoint[j][i].y-floor(TFpoint[j][i].y));

}
else if(floor(TFpoint[j][i].y) ==TFpoint[j][i].y){

res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]+(ceil(TFpoint[j][i].x)-TFpoint[j][i].x);
res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)TFpoint[j][i].y][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]+(TFpoint[j][i].x-floor(TFpoint[j][i].x));

}
else{

res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]+(ceil(TFpoint[j][i].y)-TFpoint[j][i].y)*(ceil(TFpoint[j][i].x)-TFpoint[j][i].x);
res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)floor(TFpoint[j][i].y)][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]+(ceil(TFpoint[j][i].y)-TFpoint[j][i].y)*(TFpoint[j][i].x-floor(TFpoint[j][i].x));
res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)floor(TFpoint[j][i].x)]][F[j][i]]+(TFpoint[j][i].y-floor(TFpoint[j][i].y))*(ceil(TFpoint[j][i].x)-TFpoint[j][i].x);
res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]=res[R[(unsigned int)ceil(TFpoint[j][i].y)][(unsigned int)ceil(TFpoint[j][i].x)]][F[j][i]]+(TFpoint[j][i].x-floor(TFpoint[j][i].x))*(TFpoint[j][i].y-floor(TFpoint[j][i].y));

}
``````

When I compile I get this message:

PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 390)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 394)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 403)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 404)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 412)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 413)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 414)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 415)

where each line corresponds to all updates of res, except from the first one. What could be the problem?

Hi kspan,

An If statement isn’t a valid spot for the atomic pragma. Try putting an atomic pragma before each of the “res” updated.

• Mat

I did as you said but I got more errors of the same sort

PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 403)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic region. (main_array_new_acc.cpp: 403)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 408)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic region. (main_array_new_acc.cpp: 408)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 417)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 340)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 245)
PGCC-S-0155-Invalid atomic region. (main_array_new_acc.cpp: 417)
PGCC-S-0155-Invalid atomic expression (main_array_new_acc.cpp: 420)
PGCC-F-0008-Error limit exceeded (main_array_new_acc.cpp: 420)

Again, only the update at the first if has no error

I’m wondering if the use of ceil or floor in the expression, ex. "+(ceil(TFpoint[j].y)-TFpoint[j].y)" is causing the problem. Can you try assigning these expressions to a scalar and then adding scalar to the res array?

If that’s not it, I’m not sure. Can you post a small reproducing example?

Thanks,
Mat

Well I did as you said and I discovered the following:

1)In the case where I had more than one atomic updates in the same code area (that is everywhere except the first if), I 've put in comments one of them and when I compiled the code, I got the same mistakes. Then I realized that the number of the atomic updated in the same area didn’t matter. Something else was in hand
2)I replaced the "+(ceil(TFpoint[j].y)-TFpoint[j].y)" with a number and it caused the same problem. That meant that the ceil/floor, at least as I used them hear created many problems. I’try to do what you said.

I did as you said and your speculation is correct. Ceil and floor present the big problem in atomic update.

if you try

#pragma acc atomic
x=floor(y)

you get the error I mentioned earlier. Is there a way to solve this problem?

Unfortunately you can have function/subroutine calls in atomic operations.