I came across a possible bug when using OpenACC’s unstructured data inside conditionals.
I coded something like this:
if (something.gt.something_else) then
!$acc enter data create(a)
!$acc kernels present(a,b)
!$acc end kernels
!$acc host_data use_device(a)
!$acc end host_data
!$acc exit data delete(a)
I tried to run the code in the case where “something” was less than “something_else” so that the whole above block should not have been executed.
When I compiled with -O3 the code seg faulted.
Using the (amazing) pgdbg, it turns out the code was calling the “!$acc exit data” even though it correctly did not call anything else in the “if”.
When I compiled with -g, the code ran fine.
Is it possible that the -O3 is reordering things and is not being careful enough about the data clauses?
We have had issues in the past where the compiler incorrectly hoists invariants out of if statements without guarding them. However, it’s something we’ve fixed and I haven’t seen any problems for many years. Also, it’s strange that it would only hoist out the exit data.
My guess is something else is happening, but I’m not sure what.
Do you have a small reproducer you could post?
It turns out I had an error in my MPI call.
(I was calling MPI_Waitall() on 4 requests but failing to give it the number 4 and also failing to give it a scaler status variable. I fixed the request number and switched to MPI_STATUSES_IGNORE.)
For some reason, messing this up showed up in the pgi debugger as a false “free” on my exit data. My mistake also caused seg faults in the openaccx86 compilation and GNU, but there, the debuggers claimed the seg fault was in an entirely different routine!
Oh to have seg faults give useful error messages… :)
Everything is working fine now, thanks!