error with pgf 12.2 64 bit linux

I have a short snipped of code that works fine with older version of pgf95 and does not work correctly with pgf12.2. Here is the reproducer code :

      integer ,allocatable,dimension(:) :: refimax,refjmax,refkmax
      open(11,file='test.grid.in',status='new',form='unformatted')
      write(11) 2
      write(11) 1,2,3,4,5,6
      close(11)
      open(11,file='test.grid.in',status='old',form='unformatted')
      allocate(refimax(1),refjmax(1),refkmax(1))
      ng=1
      read(11,err=7)refimax(1),refjmax(1),refkmax(1)
      write(*,*) '   single grid format detected'
      goto 8
    7 continue
         write(*,*) '   multiple grid format detected'
         rewind(11)
         deallocate(refimax,refjmax,refkmax)
         read(11)ng
         allocate(refimax(ng),refjmax(ng),refkmax(ng))
         read(11)(refimax(ig),refjmax(ig),refkmax(ig),ig=1,ng)
    8 continue

      stop
      end

This type of code is very common in CFD codes reading grid files.

When I run this code with 12.2 I get :

multiple grid format detected
PGFIO-F-219/unformatted read/unit=11/attempt to read/write past end of record.
File name = test.grid.in unformatted, sequential access record = 1
In source file testit2.f, at line number 17

Thanx,
Bernie

Thanks Bernie. I’ve sent a problem report (TPR#18647) to our compiler engineers for further investigation.

  • Mat

I get the same error you do for any Fortran compiler. The reason is the way you are writing and then reading the file.

Remember, Fortran assumes each write to an unformatted file (default access is sequential here) is a record. As such, it appends the record length at the beginning and end of the record, typically this adds 4 bytes on either side of the data written.

So the first write of “2” stores 12 bytes: 4 bytes for the number 2, 4 bytes as the record length field on either side. Then you write out “1,2,3,4,5,6”. This creates another 4-byte record length field, then the 24 bytes for the data, and another 4 bytes at the end.

The problem arises when you read back data. You read three integers at once. But the record length fields surrounding that first integer you wrote are telling the system that you should only have one integer in the record.

Basically, for unformatted and sequential access files you must read back the data in the same order it was written.

Here is a version that will always compile and run correctly:

      program tester
      integer,allocatable,dimension(:) :: refimax,refjmax,refkmax 
      integer :: i,j,k
      open(11,file='test.grid.in',status='new',form='unformatted') 
      write(11) 2 
      write(11) 1,2,3,4,5,6 
      close(11) 
      open(11,file='test.grid.in',status='old',form='unformatted') 
      allocate(refimax(1),refjmax(1),refkmax(1)) 
      ng=1 
      read(11) ng
      read(11,err=7)refimax(1),refjmax(1),refkmax(1),i,j,k
      write(*,*) '   single grid format detected' 

      go to 8 

7     continue 
         write(*,*) '   multiple grid format detected' 
         rewind(11) 
         deallocate(refimax,refjmax,refkmax) 
         read(11)ng 
         allocate(refimax(ng),refjmax(ng),refkmax(ng)) 
         read(11)(refimax(ig),refjmax(ig),refkmax(ig),ig=1,ng) 
         close(11)
8     continue 

      stop 
      end program tester

Hi Bernie,

FYI, TPR#18687 has been fix with the fix available in the 12.5 compiler. Thanks again for the report.

  • Mat

thanx mat!!!

Bernie