This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Synchronous writing on file


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]