Will if-else inside of an openacc regime affect dependencies?


I am using PGI/18.
Thanks for Mat’s previous support, my OpenACC run all right days ago.
However, when I want to add an if-else segment inside of the OpenACC regime, the dependency relationship become strange and prevent parallelism.

I will try to explain the question simply:
!$acc data
!$acc parallel loop
Do el=1:N

A(el)=B(el)+C(el) !it runs in parallel all right
end do
!$acc end data

Now, I add an if-else segment. And here comes the issue:

!$acc data
!$acc parallel loop
Do el=1,N
if (domain(el)==1) then !new added

A(el)=B(el)+C(el) !it still runs in parallel all right
A(el)=B(el)+C(el) ! same commend, but it says the reuse of A prevent the parallelization
D(el)=D(el)+E(el) ! Here the D also prevents parallelization. But as each thread are with different el, I am sure it should be independent. It seems not suitable for reduction clause here as it is matrix.
end if
end do
!$acc end data

I have two type of problem. Both prevent me for parallelization. Do you have any suggestion about that?



Hi Wending,

Do you have a small reproducing example you can share? The if statement itself wouldn’t prevent parallization so there’s probably something specific to your code.

Using what you have posted I wrote the following example, and as you can see that there’s no issue.


% cat test.f90

subroutine foo(A,B,C,D,E,domain,N)

real, dimension(:) :: A,B,C,D,E
integer, dimension(:) :: domain
integer, value :: N
integer :: el

!$acc data copyin(C,B,E,domain) copyout(A) copy(D)
!$acc parallel loop
do el=1,N
   if (domain(el) == 1) then
      A(el) = B(el)+C(el)
      A(el) = B(el)+C(el)
      D(el) = D(el)+E(el)
!$acc end data

end subroutine foo

% nvfortran -c test.f90 -acc -Minfo=accel
      9, Generating copyin(b(:)) [if not already present]
         Generating copyout(a(:)) [if not already present]
         Generating copyin(e(:),domain(:)) [if not already present]
         Generating copy(d(:)) [if not already present]
         Generating copyin(c(:)) [if not already present]
     10, Generating Tesla code
         11, !$acc loop gang, vector(128) ! blockidx%x threadidx%x