Minfo=ccff causing incorrect resutls

Hi,

As far as I am aware adding the compile flag Minfo=ccff should not effect the generated code, however that doesn’t seem to be the case.

I have produced the following MWE which reproduces the issue:

program main
    implicit none

    integer, parameter :: ARRAY_SIZE = 4
    integer, parameter :: MAX_ITERS = 100

    integer, dimension(ARRAY_SIZE) :: arr
    integer, dimension(ARRAY_SIZE) :: expected
    logical :: flag
    integer :: i, iteration

    expected = 0

    ! Initialise the array
    do i = 1, ARRAY_SIZE
        arr(i) = i - 1
    end do

    ! Copy array onto device manually with openacc
    !$acc enter data copyin(arr)

    ! Repeat up to the max iters time
    do iteration = 1, MAX_ITERS
        ! Set flag to true
        flag = .true.
        ! Copy the flag to the gpu
        !$acc enter data copyin(flag)

        !$acc kernels
        ! If a value is non-zero, subtract one and set the flag to false.
        do i = 1, ARRAY_SIZE
            if(arr(i) .gt. 0) then
                arr(i) = arr(i) - 1
                !$acc atomic write
                flag = .false.
                !$acc end atomic
            end if
        end do
        !$acc end kernels
        !$acc exit data copyout(flag)

        ! If the flag value has not changed, quit the outer loop.
        if (flag) then
            exit
        end if
    end do
    !$acc exit data copyout(arr)

    ! Check the result.
    if(all(arr .eq. expected)) then
        print *, "Correct array (all 0)"
    else
        print *, "!! Error: Incorrect array"
        print *, arr
    end if

    ! Check the exit iteration is correct
    if(iteration .eq. ARRAY_SIZE) then
        print *, "Correct exit iteration", iteration
    else
        print *, "!! Error: Incorrect exit iteration", iteration
    end if


end program main

When compiled without ccff, the correct result is produced:

pgfortran -ta:tesla -Minfo=accel main.f90
main:
     20, Generating enter data copyin(arr(:))
     27, Generating enter data copyin(flag)
     29, Generating copy(flag)
         Generating copy(arr(:))
     31, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         31, !$acc loop gang, vector(32) ! blockidx%x threadidx%x
     40, Generating exit data copyout(flag)
     47, Generating exit data copyout(arr(:))


./main.exe
 Correct array (all 0)
 Correct exit iteration            4

However when the ccff is added, the generated code does not produce the correct result.

 pgfortran -ta:tesla -Minfo=accel,ccff main.f90
main:
     20, Generating enter data copyin(arr(:))
     27, Generating enter data copyin(flag)
     29, Generating copy(flag)
         Generating copy(arr(:))
     31, Loop is parallelizable
         Accelerator kernel generated
         Generating Tesla code
         31, !$acc loop gang, vector(32) ! blockidx%x threadidx%x
     40, Generating exit data copyout(flag)
     47, Generating exit data copyout(arr(:))

./main.exe
 !! Error: Incorrect array
            0            0            1            2
 !! Error: Incorrect exit iteration            1

This is only an issue when using an accelerator

pgfortran -Minfo=accel,ccff main.f90

 ./main.exe
 Correct array (all 0)
 Correct exit iteration            4

Is this in some way expected or a compiler bug?

pgfortran --version

pgfortran 15.10-0 64-bit target on x86-64 Windows -tp haswell
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.

Thanks
Peter


Hi Peter,

That has to be one of the weirder bugs that I’ve encountered. CCFF shouldn’t effect code generation but in looking at the generated assembly, it definitely is.

I’ve created a problem report (TPR#22269) and sent it off to engineering for further investigation. Hopefully they can determine what’s happening.

Thanks!
Mat