Next: Restrictions Up: Explicit Parallel I/O Previous: OPEN statement
The READ, WRITE, CLOSE, INQUIRE, BACKSPACE, ENDFILE, REWIND statements can be used to access distributed files; there are no changes in the syntax or semantics of these statements.
PREAD and PWRITE statements are added to allow efficient input or output of distributed arrays. The PREAD and PWRITE statements have the same syntax as unformatted I/O statements with READ or WRITE, respectively; they are semantically different. The data representation created on a file by a PWRITE statement may be different from the data representation that obtains if PWRITE is replaced by WRITE. In particular, whereas an unformatted WRITE statement will create a single record (stored on one I/O node), a PWRITE statement may create multiple records, possibly on multiple I/O nodes. Whereas an unformatted READ statement accesses a unique record, a PREAD statement may access multiple records.
If a PWRITE statement was used to write a list of output items on a file, then a PREAD that starts at the same point in the file, and has a compatible list of input items, will return the values that were written. Two lists of items are compatible if the corresponding items in each list occupy the same number of storage units and have compatible mappings (informally, if the distribution of entries onto abstract processors is the same).
The following program exchanges the values of arrays A and B. The exchange is legal because the arrays are compatible.
REAL, DIMENSION(1000,1000) :: A, B !HPF ALIGN WITH B :: A OPEN(UNIT = 15, ACTION = READWRITE) PWRITE (UNIT = 15) A, B BACKSPACE (UNIT = 15) PREAD (UNIT = 15) B, A The behavior of the following program is undefined, since the two arrays A and B don't have compatible distributions.
REAL, DIMENSION(1000,1000) :: A, B !HPF DISTRIBUTE B(CYCLIC, CYCLIC) ... OPEN(UNIT = 15, ACTION = READWRITE) PWRITE (UNIT = 15) A, B REWIND (UNIT = 15) PREAD (UNIT = 15) B, A Data written by a WRITE statement cannot be read with PREAD, and data written with PWRITE cannot be read with READ, or by a PREAD that does not start at exactly the same point in the file (otherwise the program outcome is undefined).
PREAD and PWRITE can be used both for sequential access and for direct access. In the latter case, the REC specifier indicates the position in the file where from the transfer starts. It is still the case that a transfer may involve several records.