Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!sun-barr!newstop!sun!amdahl!key!sjc From: sjc@key.COM (Steve Correll) Newsgroups: comp.lang.fortran Subject: Re: slow write Message-ID: <1550@key.COM> Date: 22 Mar 90 20:07:26 GMT References: <3673.2607e3bb@vax5.cit.cornell.edu> Distribution: comp Organization: Key Computer Labs, Fremont, CA Lines: 46 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! Because the implied-do notation permits you to skip around within an array, selecting non-contiguous elements, a compiler must, in the general case, write the elements out one at a time. Some compilers recognize the special (but frequent) case where the implied-do elements are contiguous in memory, and can thereby economize by writing them out in one big block. Apparently yours doesn't. Try putting the write statement inside a subroutine and passing the array as "character*(*)" or (for a non-character array) using an adjustable-array declaration: subroutine s(c, a, n) character*(*) c real a(n) write(10) c write(11) a end ... call s(c(1:), a, ) end There's no guarantee, but this does make it easier for the compiler to recognize that the elements are contiguous and perform each WRITE statement as a single operation. Incidentally, this illustrates one reason why users may be disappointed in the first generation of Fortran 90 compilers. If experience is a guide, it will be some time before most compilers mature enough to recognize all the special, optimizable cases of the new array constructs. -- ...{sun,pyramid}!pacbell!key!sjc Steve Correll