Blocking during binary reads

I have the following code

program readit
    implicit none

    Integer :: istat
    Integer :: LUNIT=20
    INTEGER :: RECLEN=132120576
    INTEGER :: S_time,E_time
    real  :: rate
    CHARACTER(100) :: DIRFIL1="some_binary_file.unf"
    CHARACTER(100) :: DIRFIL2="some_binary_file.unf.cr"


    INTEGER(2),dimension(3,21,1024,1024):: traject
    INTEGER(2),dimension(1024,1024,3,21) :: traject2


!---least effeince way to prcess but fastest to read
 call system_clock(s_time,rate)
        OPEN (LUNIT, FILE=TRIM(DIRFIL1),  IOSTAT=ISTAT, &
                     FORM='UNFORMATTED', ACCESS='DIRECT', RECL=RECLEN)
	           IF (ISTAT .EQ. 0) THEN
	              READ(LUNIT, REC=1, IOSTAT=ISTAT) TRaject2(:,:,:,:)
	           ENDIF
         close(lunit)
   call system_clock(e_time)
     print*,"total time",(e_time-s_time)/rate
 print*,"--------",traject2(10,430:432,1,1)



!--- most effeince way to prcess slowest to read the way it should be used
 call system_clock(s_time)
        OPEN (LUNIT, FILE=TRIM(DIRFIL2)',  IOSTAT=ISTAT, &
                     FORM='UNFORMATTED', ACCESS='DIRECT', RECL=RECLEN)
	           IF (ISTAT .EQ. 0) THEN
	              READ(LUNIT, REC=1, IOSTAT=ISTAT) TRaject(:,:,:,:)
	           ENDIF
         close(lunit)
   call system_clock(e_time)
     print*,"total time",(e_time-s_time)/rate
 print*,"--------",traject(1,1,10,430:432)
end program

When run I get an output of:

total time 0.1880170
-------- 1721 1691 1662
total time 1.755034
-------- 1721 1691 1662

The two files have exactly the same data it is they are just structured differently for the way I want them to be processed. I was wondering why it takes almost 10x longer for the binary read for one compared to the other?

Thanks

I was wondering why it takes almost 10x longer for the binary read for one compared to the other?

Most likely buffering. The array with a leading dimension of 1024 will have a larger buffer then the on with 3.

  • Mat