<ASYNCHRONOUS Example Program>
Program asynchronous_attribute_example Real,Asynchronous :: a(100,2) Logical finished Open (17,File='Results',Form='Unformatted',) Do Call produce_results(a(:,1),finished) Call write_results(a(:,1)) If (finished) Exit Call produce_results(a(:,2),finished) Call write_results(a(:,2)) If (finished) Exit End Do Contains Subroutine produce_results(vector,finished) Real,Intent(Out) :: vector(:) Logical,Intent(Out) :: finished Call Random_Number(vector) finished = vector(1)<0.1 End Subroutine Subroutine write_results(vector) Real,Asynchronous,Intent(In) :: vector(:) Write (17,) vector End Subroutine End Program
<Comments>
The use of the ASYNCHRONOUS attribute allows the overlap of the writing of one set of results while computing the next. The WAIT statement in WRITE_RESULTS waits for the previous output to unit 17 to finish, thus ensuring that the previous VECTOR can be re-used for computation.
The ASYNCHRONOUS attribute is needed to tell the compiler that A is subject to asynchronous input/output; this information prevents unsafe optimisations.