Re: Question(s) about recursive I/O in f2003
- From: glen herrmannsfeldt <gah@xxxxxxxxxxxxxxxx>
- Date: Thu, 08 Feb 2007 00:55:16 -0800
James Giles wrote:
(snip)
Well, first of all the term is a misnomer. There is no actual
recursion involved. Consider the following write statement:
Write(io_unit(p)) f(x)
Well, reentrant is closely related to recursive. It is
reentrant in the sense that the routine is entered again
before the previous I/O statement has completed.
And suppose IO_UNIT is a function. Suppose further that
there's I/O done within that function. Well, you might think
that the normal way to do this is to call the IO_UNIT function
before you call the I/O library to process the WRITE. And,
you could do that too, but many implementations don't (I'll
talk about what they actually do below).
I believe it is fairly common for the unit to be specified
in the initial call, and reasonably likely the format, too.
As far as I know, the standard doesn't require it.
And suppose that F is a function that also does I/O. Again,
you might think the proper thing to do is call F first and then
call the I/O library to process the WRITE. Again, implementations
could do that, but most don't.
What most implementations do when they process an I/O
statement is begin a sequence of calls to the I/O library.
The first initializes the process: prepares the library for the
type of I/O you're about to do (in this case, unformatted
write). The last step is to finalize the I/O process (which
might actually send any data buffered within the library
itself to the system - no, it's not what FLUSH does - and
maybe even return such internal buffers to the memory
manager). In between, there are several calls to the I/O
library that pass information to be processed next. There
might be a separate call for the unit number, for the format
(in this case, there isn't one, but for formatted I/O there
would be), and a separate call for each I/O list item. Etc.
As far as I know, it is the list items that are usually
the problem.
So, each I/O statement actually turns into a whole sequence(snip)
of procedure calls. And the function references we discussed
above might be made in between some of these I/O calls.
Now, why would an implementation do things like that?
Well consider:
Write(11) (F(i), i = 1, max), (G(j), j = 1, max), ...
Where MAX is some large number. In order to precompute
the whole I/O list before beginning the I/O sequence you have
to make room for huge numbers of temporary values. It's
easier nowdays. But when the usual I/O imlementation
style was invented memory was not so cheap or abundant.
Even so, suppose that F is an array valued function: it could
still add up to a prohibitive amount of memory. By processing
the I/O list incrementally you avoid the need for large amounts
of such temporary storage.
I do remember when the OS/360 Fortran library was changed to
allow an array or implied do as one call, instead of one per
array element. The new library was backward compatible, but
new code was not compatible with the old library.
Note: few I/O implementations don't precompute the I/O control
list items (the stuff in the parenthesis after the statement keyword).
So, "recursive I/O" is probably safe there. But, I see no mention
of it either way in the standard document. Maybe I'm looking in the
wrong places.
As far as I know, not, but I don't know where it says it, either.
-- glen
.
- Follow-Ups:
- Re: Question(s) about recursive I/O in f2003
- From: James Giles
- Re: Question(s) about recursive I/O in f2003
- References:
- Question(s) about recursive I/O in f2003
- From: dominiq
- Re: Question(s) about recursive I/O in f2003
- From: James Giles
- Question(s) about recursive I/O in f2003
- Prev by Date: Re: Integer Coersion
- Next by Date: Re: acquiring standard
- Previous by thread: Re: Question(s) about recursive I/O in f2003
- Next by thread: Re: Question(s) about recursive I/O in f2003
- Index(es):
Relevant Pages
|