Asynchronous Input/Output

You can specify asynchronous READ and WRITE data transfer statements to initiate asynchronous data transfer. Execution continues after the asynchronous I/O statement, without waiting for the data transfer to complete.

Executing a matching WAIT statement with the same ID= value that was returned to the ID= variable in the data transfer statement detects that the data transfer statement is complete, or waits for that data transfer statement to complete.

The data transfer of an I/O item in an asynchronous I/O statement can complete:
  • During the execution of the asynchronous data transfer statement
  • At any time before the execution of the matching WAIT statement
  • During the matching WAIT statement

For information on situations where data transfer must complete during the asynchronous data transfer statement, see Implementation details of XL Fortran Input/Output in the XL Fortran Optimization and Programming Guide.

If an error occurs during the execution of an asynchronous data transfer statement, the variable associated with the ID= specifier remains undefined. The IOSTAT= specifier indicates the status of the I/O operation and control is transferred to the statement specified by the ERR= specifier.

You must not reference, define, or undefine variables or items associated with a variable appearing in an I/O list for an asynchronous data transfer statement, until the execution of the matching WAIT statement.

Any deallocation of allocatable objects and pointers and changing association status of pointers are disallowed between an asynchronous data transfer statement and the matching WAIT statement.

Fortran 2003 begins Multiple outstanding data transfer operations on the same unit can be both READ and WRITE. A WAIT statement will perform a wait operation for all pending data transfers for the specified unit if the ID= specifier is omitted. Fortran 2003 ends

In the case of direct access, an asynchronous WRITE statement must not specify both the same unit and record number as any asynchronous WRITE statement for which the matching WAIT statement has not been executed. For stream access, an asynchronous WRITE statement must not specify either the same unit and location within a file as any asynchronous WRITE statement for which the matching WAIT statement has not been executed.

In the portion of the program that executes between the asynchronous data transfer statement and the matching WAIT statement, you must not reference, define, or undefine variables or items associated with the integer_variable in the NUM= specifier of that data transfer statement.

Using Asynchronous I/O
SUBROUTINE COMPARE(ISTART, IEND, ISIZE, A)
INTEGER, DIMENSION(ISIZE) :: A
INTEGER I, ISTART, IEND, ISIZE
DO I = ISTART, IEND
  IF (A (I) /= I) THEN
    PRINT *, "Expected ", I, ", got ", A(I)
  END IF
END DO
END SUBROUTINE COMPARE

PROGRAM SAMPLE
INTEGER, PARAMETER :: ISIZE = 1000000
INTEGER, PARAMETER :: SECT1 = (ISIZE/2) - 1, SECT2 = ISIZE - 1
INTEGER, DIMENSION(ISIZE), STATIC :: A
INTEGER IDVAR

OPEN(10, STATUS="OLD", ACCESS="DIRECT", ASYNCH="YES", RECL=(ISIZE/2)*4)
A = 0

! Reads in the first part of the array.

READ(10, REC=1) A(1:SECT1)

! Starts asynchronous read of the second part of the array.

READ(10,ID=IDVAR, REC=2) A(SECT1+1:SECT2)

! While the second asynchronous read is being performed,
! do some processing here.

CALL COMPARE(1, SECT1, ISIZE, A)

WAIT(ID=IDVAR)

CALL COMPARE(SECT1+1, SECT2, ISIZE, A)
END


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us