Next: , Previous: Aliasing Assumed To Work, Up: Working Programs


14.4.8 Output Assumed To Flush

For several versions prior to 0.5.20, g77 configured its version of the libf2c run-time library so that one of its configuration macros, ALWAYS_FLUSH, was defined.

This was done as a result of a belief that many programs expected output to be flushed to the operating system (under UNIX, via the fflush() library call) with the result that errors, such as disk full, would be immediately flagged via the relevant ERR= and IOSTAT= mechanism.

Because of the adverse effects this approach had on the performance of many programs, g77 no longer configures libf2c (now named libg2c in its g77 incarnation) to always flush output.

If your program depends on this behavior, either insert the appropriate `CALL FLUSH' statements, or modify the sources to the libg2c, rebuild and reinstall g77, and relink your programs with the modified library.

(Ideally, libg2c would offer the choice at run-time, so that a compile-time option to g77 or f2c could result in generating the appropriate calls to flushing or non-flushing library routines.)

Some Fortran programs require output (writes) to be flushed to the operating system (under UNIX, via the fflush() library call) so that errors, such as disk full, are immediately flagged via the relevant ERR= and IOSTAT= mechanism, instead of such errors being flagged later as subsequent writes occur, forcing the previously written data to disk, or when the file is closed.

Essentially, the difference can be viewed as synchronous error reporting (immediate flagging of errors during writes) versus asynchronous, or, more precisely, buffered error reporting (detection of errors might be delayed).

libg2c supports flagging write errors immediately when it is built with the ALWAYS_FLUSH macro defined. This results in a libg2c that runs slower, sometimes quite a bit slower, under certain circumstances—for example, accessing files via the networked file system NFS—but the effect can be more reliable, robust file I/O.

If you know that Fortran programs requiring this level of precision of error reporting are to be compiled using the version of g77 you are building, you might wish to modify the g77 source tree so that the version of libg2c is built with the ALWAYS_FLUSH macro defined, enabling this behavior.

To do this, find this line in gcc/libf2c/f2c.h in your g77 source tree:

     /* #define ALWAYS_FLUSH */

Remove the leading `/* ', so the line begins with `#define', and the trailing ` */'.

Then build or rebuild g77 as appropriate.