Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29488 Discussions

Why are unformatted writes broken into 512k chunks?

crtierney42
New Contributor I
963 Views
I have a test code that writes then subsequently reads a large file (in this case 512MB) in several different records. What I see from strace is that the write are broken into 512KB chunks, while the reads are read in as the size of the record.

Why is this? I tested with both 9.1.036 and 10.1.012.

Thanks,
Craig

program testfortranio


implicit none

integer maxsize,reccnt
parameter(maxsize=32*1024*1024,reccnt=4)

integer i
integer ar(maxsize),ar2(maxsize)
integer lun


lun=11

do i=1,maxsize
ar(i)=i
enddo
open(lun,file="/tg2/jetmgmt/ctierney/myfile.fort",form="unformatted", status="unknown")

do i=1,reccnt
write(lun) ar
enddo

close (lun)


open(lun,file="/tg2/jetmgmt/ctierney/myfile.fort", form="unformatted", status="old")
do i=1,reccnt
read(lun) ar2
enddo
close(lun)

do i=1,maxsize
if (ar(i) .ne. ar2(i)) then
write(*,*) 'The two arrays dont match at ', i
endif
enddo

stop
end

0 Kudos
2 Replies
TimP
Honored Contributor III
963 Views
Documentation for the current compilers specifies that you must specify BLOCKSIZE in OPEN if you want other than the filesystem default. BLOCKSIZE was not fully supported in 9.1.
0 Kudos
crtierney42
New Contributor I
963 Views
I tried blocksize, but I only tried it under 9.1 and saw no difference, so I didn't bother trying it with 10.1.

So why is there even such a setting? Since the data are already allocated, and the
call to the glibc write command takes a pointer, why bother breaking the data up?

Craig
0 Kudos
Reply