Re: [C/Fortran] writing "big" binary files issue...
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: [C/Fortran] writing "big" binary files issue...         

Group: comp.lang.fortran · Group Profile
Author: Dr Ivan D. Reid
Date: Jul 22, 2008 12:08

On Tue, 22 Jul 2008 16:52:00 +0000 (UTC), Dr Ivan D. Reid
brunel.ac.uk>
wrote in loki.brunel.ac.uk>:
> On Tue, 22 Jul 2008 17:28:50 +0200, fred
> wrote in <87tzeiuedp.fsf@free.fr>:
>
>> fread(&x, 1, sizeof(float), file_in);
>> fwrite(&x, 1, sizeof(float), file_out);

You seem to have got the arguments the wrong way around; you
are reading 4 1-byte items. From man fread:

size_t fread(void *restrict ptr, size_t size, size_t nitems,
FILE *restrict stream);
>> What am I doing wrong in the fortran version ?
>
> Have you tried something like:
> integer :: i, j, k
> integer :: nx, ny, nz
> real :: x(720)
> nx = 600; ny = 800; nz = 720
> open(unit=20, file='input.sep', form='binary')
> open(unit=21, file='a.sep', form='binary')
> do i = 1, nx
> do j = 1, ny
> read(20) x
> write(21) x
> end do
> end do

It's instructive to look at the times from the time command:
real user sys
ifort create file: 12'25" 1'50" 10'02"
icc copy (original): 42" 32" 7"
C copy (1x4-byte): 1'17" 33" 8"
C copy (1x4-byte) -O3: 56" 0.5" 8"
C copy (720x4-byte): 51" 0.5" 8"
C copy (720x4-byte) -O3 54" 0.5" 8"
ifort 9.1 single copy: 14'02" 3'09" 10'26"
ifort array copy: 51" 0.9" 8"

The C copies and the buffered ifort copy appear to be disk-bound,
the user+sys is much less than the real time. The original 4x1-byte copy
user time appears to suffer from its extraneous looping, and the single-item
Fortran reads and writes need much more system and user time, presumably
re-arranging items into and out of disk buffers. Since I only have ifort
9.1, I couldn't test later versions' stream access.

All copied files had the same md5 checksum as the original.

--
Ivan Reid, School of Engineering & Design, _____________ CMS Collaboration,
Brunel University. Ivan.Reid@[brunel.ac.uk|cern.ch] Room 40-1-B12, CERN
KotPT -- "for stupidity above and beyond the call of duty".
no comments
diggit! del.icio.us! reddit!