Problem allocating a zero-length array on the device

Hello,

I am trying to allocate an array on the device which can have zero length.

integer :: i
real, device, allocatable :: arr(:)

i = 0
allocate(arr(i))
deallocate (arr)

The compilation returns no errors; however, when I run the code I get the following message:

0 : ALLOCATE: 0 bytes requested; statu = 0 (no error)

and the program stops.

I tryed adding stat = istat to the allocation, e.g. allocate(arr(0), stat = istat). This time the program runs but istat = 1, denoting an error in the allocation.

Can anyone tell me what’s going on? Allocating zero-length arrays on the host has never been a problem.

Regards,

Riccardo

% pgfortran -V
pgfortran 17.10-0 64-bit target on x86-64 Linux -tp nehalem
% pgaccelinfo

CUDA Driver Version: 8000
NVRM version: NVIDIA UNIX x86_64 Kernel Module 375.39 Tue Jan 31 20:47:00 PST 2017

Device Number: 0
Device Name: Tesla K20c
Device Revision Number: 3.5
… and so on

% more test_dev.f90
program alloc_null
integer :: i ,istat

real, device, allocatable :: arr(:)
! real, allocatable :: arr(:)
! allocate a small array
i=100
allocate (arr(i), stat=istat)
print *,“istat for arr(100) is”,istat
deallocate (arr)
! allocate a zero length array

i = 0
allocate(arr(i),stat=istat)
print *,“istat for arr(0) is”,istat
deallocate (arr)

i = 0
print *,“allocating without status”
allocate(arr(i))
deallocate (arr)
end

% pgfortran -Mcuda -ta=tesla,cuda8.0 -o test_dev test_dev.f90
% test_dev
istat for arr(100) is 0
istat for arr(0) is 0
allocating without status

I am not seeing the failures. Do you with 17.10?
dave

Hi,

I am using PGI Visual Fortran 17.10 with a CUDA driver version 9000. I tried to run your example but I got the same error:

istat for arr(100) is 0
istat for arr(0) is 1
allocating without status
0: ALLOCATE: 0 bytes requested; status = 0(no error)

Note that I compiled the code using the Visual Studio interface (I created a simple empty project). The compilation command used in the background is:

-g -Bstatic -Mbackslash -Mcuda -I"c:\program files\pgi\win64\17.10\include" -I"C:\Program Files\PGI\Microsoft Open Tools 14\include" -I"C:\Program Files (x86)\Windows Kits\10\Include\shared" -I"C:\Program Files (x86)\Windows Kits\10\Include\um" -Minform=warn

Regards,

Riccardo