You can do I/O in a loop that executes in parallel, provided that:
It does not matter that the output from different threads is interleaved (program output is nondeterministic.)
You can ensure the safety of executing the loop in parallel.
Example: I/O statement in loop
!$OMP PARALLEL DO PRIVATE(k) do i = 1, 10 ! Parallelized k = i call show ( k ) end do end subroutine show( j ) write(6,1) j 1 format(’Line number ’, i3, ’.’) end demo% f95 -openmp t13.f demo% setenv PARALLEL 4 demo% a.out |
Line number 9. Line number 4. Line number 5. Line number 6. Line number 1. Line number 2. Line number 3. Line number 7. Line number 8. |
However, I/O that is recursive, where an I/O statement contains a call to a function that itself does I/O, will cause a runtime error.