Chapter 5. System and C I/O

Table of Contents
5.1. System I/O
5.2. C I/O

This chapter describes systems calls used by the I/O library to perform asynchronous or synchronous I/O. This chapter also describes Fortran callable entry points to several C library routines and describes C I/O on UNICOS/mk systems.

5.1. System I/O

The I/O library and programs use the system calls described in this chapter to perform synchronous and asynchronous I/O, to queue a list of distinct I/O requests, and to perform unbuffered I/O without system buffering. For more information about the system calls described in this chapter, see the UNICOS System Calls Reference Manual or the individual man pages.

5.1.1. Synchronous I/O

With synchronous I/O, an executing program relinquishes control during the I/O operation until the operation is complete. An operation is not complete until all data is moved.

The read(2) and write(2) system calls perform synchronous reads and writes. The READ and WRITE(3F) functions provide a Fortran interface to the read and write system calls. The read system call reads a specified number of bytes from a file into a specified buffer. The write system call writes from a buffer to a file.

5.1.2. Asynchronous I/O

Asynchronous I/O lets the program use the time that an I/O operation is in progress to perform some other operations that do not involve the data in the I/O operation. In asynchronous I/O operations, control is returned to the calling program after the I/O is initiated. The program may perform calculations unrelated to the previous I/O request or it may issue another unrelated I/O request while waiting for the first I/O request to complete.

The asynchronous I/O routines provide functions that let a program wait for a particular I/O request to complete. The asynchronous form of BUFFER IN and BUFFER OUT statements used with UNIT and LENGTH routines provide this type of I/O.

On UNICOS and UNICOS/mk systems, the READA and WRITEA(3F) functions provide a Fortran interface to the reada(2) and writea(2) system calls. The reada system call reads a specified number of bytes from a file into a specified buffer. The system call returns immediately, even if the data cannot be delivered until later. The writea system call writes from a buffer to a file as specified.

5.1.3. listio I/O

Use the listio(2) system call to initiate a list of distinct I/O requests and, optionally, wait for all of them to complete. No subroutine or function interface to listio exists in Fortran. The AQIO package provides an indirect Fortran interface to listio.

5.1.4. Unbuffered I/O

The open(2) system call opens a file for reading or writing. If the I/O request is well-formed and the O_RAW flag is set, the read(3F) or write(3F) system call reads or writes whole blocks of data directly into user space, bypassing system cache. On UNICOS and UNICOS/mk systems, doing asynchronous system buffered I/O (for example, not using O_RAW) can cause performance problems because system caching can cause performance problems.