This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Synchronous writing on file
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: giacomo `giotti` mariani <giacomomariani at yahoo dot it>
- Cc: fortran at gcc dot gnu dot org
- Date: Wed, 10 Feb 2010 07:50:35 -0800
- Subject: Re: Synchronous writing on file
- References: <4B72D116.2020202@yahoo.it>
On Wed, Feb 10, 2010 at 04:30:30PM +0100, giacomo `giotti` mariani wrote:
> > program stamp
> > real (8) :: a(3)
> > real (8) :: pi,b
> > integer :: i,j
> > pi=dacos(-1.0d0)
> > a=[pi,-pi,0.0d0]
> > write (*,*) a
> > open (10,file='output.dat',status='unknown')
> > rewind (10)
> > do i=1,1000000
> > do j=1,1000000
> > b=(dfloat(i)*dsin(a(1))*dcos(a(2)))**dfloat(j)
> > end do
> > write (10,*) i,a
flush(10)
> > write (*,*) i,a
> > end do
> > close (10)
> > end
> the output file is updated only after a long time (maybe some buffer
> must be filled?).
Yes, it is buffering.
> Moreover, if the code (or the system) crashes the non written data are
> lost.
> I wonder why is this behavior implemented, knowing that you surely have
> good reasons.
Disk accesses are slow. Getting rid of your inner loop and
reducing the i loop to 100000 to reduce the overall time. I get
Without flush(10) 6.21 real 1.93 user 0.27 sys
With flush(10) 8.70 real 1.98 user 0.76 sys
--
Steve