Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!brutus.cs.uiuc.edu!ux1.cso.uiuc.edu!hirchert From: hirchert@ux1.cso.uiuc.edu (Kurt Hirchert) Newsgroups: comp.lang.fortran Subject: Re: slow write Message-ID: <1990Mar22.200839.19016@ux1.cso.uiuc.edu> Date: 22 Mar 90 20:08:39 GMT References: <3673.2607e3bb@vax5.cit.cornell.edu> Distribution: comp Organization: University of Illinois at Urbana Lines: 42 In article <3673.2607e3bb@vax5.cit.cornell.edu> h3dy@vax5.cit.cornell.edu writes: >I have a large array (characters) that I read in, process, >then write out to a file. Prior to run time, I dont know >the final number of elements - it is smaller than the original. > > write (10) array > >is fast, but if the array is much smaller, I don't want to >do this. > > write (10) (array(i),i=1,n) > >but an implied do is very very slow! How can I get the >combine the advantages whilst avoiding the disadvantages? >My array is about 15000000 characters long initially. 1. The implied DO is slow only on some machine. Some compilers are smart enough to recognize that the implied DO is transferring consecutive storage and use the same kind of fast I/O as for the whole array transfer. 2. On machines where the compiler is not that good, the following trick will usually work: Replace the WRITE statement above with CALL WRITCH(10, ARRAY, N) where the subroutine WRITCH is defined as follows: SUBROUTINE WRITCH (IUNIT, ARRAY, N) CHARACTER ARRAY(N) WRITE(IUNIT) ARRAY END The subroutine uses the whole array notation (and thus the fast I/O call), but the size of the array is determined at run time. The added procedure call overhead makes this slower than just a write of a whole array of equivalent size (and thus slower than the implied DO if the compiler does a good job of optimization), but faster than transferring each character separately (which is typically what you get if the compiler _doesn't_ do a good job of optimizing the implied DO). [If the original ARRAY is declared something other than CHARACTER, adjust the declaration in the subroutine accordingly.] -- Kurt W. Hirchert hirchert@ncsa.uiuc.edu National Center for Supercomputing Applications