scalar variable live-out from loop

Dear Sir,
When I compiled my code, I got error.

My code is as belows:

      program prog
          
      implicit none
      integer::i,j,nb
          integer::A(10,10),B(10)
          !$acc region
          !$acc do private(i,j)
          do i=1,10
           nb=0
           !$acc do private(nb),independent
            do j=1,20
                  if(j==i)then 
                    nb=nb+1
                        A(nb,i)=j
          end if

                  if(j==i+1)then 
                    nb=nb+1
                        A(nb,i)=j
          end if

                  if(j==i+2)then
                    nb=nb+1
                        A(nb,i)=j
          end if
        end do 
       B(i)=nb
     end do
    !$acc end region
         write(*,*)"B=",B
         do i=1,10
           write(*,*)"i=",i,"A=",A(:,i)
     end do 
         pause

    end program prog

Accelerator restriction: scalar variable live-out from loop: num Accelerator kernel generated
11, !$acc loop vector(128) ! threadidx%x
Loop is parallelizable

I don’t understand it ,please kindly advise me

thanks

Hi Teslalady,

Are you sure you posted the correct example code? The error is complaining about a live-out of the “num” variable, but this example has no variable named “num”.

However, if I comment out the “private(nb),independent” on the inner “j” loop, I do see a live-out message. The message is correct since “nb” is a scalar and being incremented in the loop. The “live-out” means that the compiler can’t tell which thread’s “nb” value should be used for the assignment “B(I)”.

You might have used a reduction on “nb” to solve the “live-out”, but since “nb” is used in the loop, it creates a dependency. Hence, the inner loop is not parallelizable and if you do force the loop to parallelize, you will most likely get wrong answers.

  • Mat