Openacc fortran exit loop early problem

Parallelizing a loop that exits early seems to be a problem for the PGI compiler.

The following test code fails to compile

program test
  implicit none
  integer:: i,count,result
  count = 0 
  result = 1 
!$acc kernels
  do i = 1,10000
     count = count + 1    
     if(count == 5) then
        goto 35
  result = 0 
35 continue
  result = result + 1 
!$acc end kernels

  print*, count, result

end program test

Compilation error with pgf90 v18.3

[18:16 dabdi@hsw213 exp] > pgf90 -acc -Minfo=accel -ta=tesla,cc60,cuda9.0 goto.F90
PGF90-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Missing branch target block (goto.F90: 7)
PGF90-F-0704-Compilation aborted due to previous errors. (goto.F90)

A cpu compile runs and prints results with count=5 and result=2.
How do I modify the code so that it can be compiled with OpenACC code and gives the correct results as the cpu version ?


Hi Daniel,

It’s illegal in OpenACC to have the program branch into or out of a compute region. Hence, there isn’t a way to do this.

Plus, the code is not parallelizable. To be parallel, all iterations of the loop must be independent of the other iterations. But here the iterations depend upon the value of count from the previous iteration.