Efficient Use of Record Buffers and Disk I/O

Records being read or written are transferred between the user's program buffers and one or more disk block I/O buffers, which are established when the file is opened by the Compaq Fortran run-time system. Unless very large records are being read or written, multiple logical records can reside in the disk block I/O buffer when it is written to disk or read from disk, minimizing physical disk I/O.

You can specify the size of the disk block I/O buffer by using the OPEN Statement BLOCKSIZE specifier. If you omit the BLOCKSIZE specifier in the OPEN statement, it is set for optimal I/O use with the type of device the file resides on.

The default for BUFFERCOUNT is 1. Any experiments to improve I/O performance should increase the BUFFERCOUNT value and not the BLOCKSIZE value, to increase the amount of data read by each disk I/O.

If the OPEN statement includes the BUFFERCOUNT and BLOCKSIZE specifiers, their product is the size in bytes of the internal buffer. If these are not specified, the default size is 1024 bytes if /fpscomp:general (or /fpscomp:all) was specified and 8192 bytes if it was omitted. This internal buffer will grow to hold the largest single record but will never shrink.

For disk writes, the OPEN statement BUFFERED specifier, the /assume:buffered_io option, or the FORT_BUFFERED run-time environment variable lets you control whether records written are written (flushed) to disk as each record is written (default) or accumulated in the buffer.

Unless you set the FORT_BUFFERED environment variable to TRUE, the default is BUFFERED='NO' and /assume:nobuffered_io for all I/O, in which case, the Fortran run-time system empties its internal buffer for each WRITE (or similar record output statement).

If you specify BUFFERED='YES', specify /assume:buffered_io, or at run-time set the FORT_BUFFERED environment variable to TRUE, for disk devices the internal buffer will be filled, possibly by many record output statements (WRITE), before it is written to disk.

The OPEN statement BUFFERED specifier takes precedence over the /assume:[no]buffered_io option. If neither are set (default), the FORT_BUFFERED environment variable is tested at run-time.

The OPEN statement BUFFERED specifier applies to a specific logical unit. In contrast, the /assume:[no]buffered_io option and the FORT_BUFFERED environment variable apply to all Fortran units.

Using buffered writes usually makes disk I/O more efficient by writing larger blocks of data to the disk less often. However, a system failure when using buffered writes can cause records to be lost, since they might not yet have been written to disk (such records would have written to disk with the default unbuffered writes).