File already opened in another unit Program aborted.
<p>Here is the program I wrote to test multiple-thread reading a file independently:</p>

<pre><code>program he
    use omp_lib

    implicit none
    integer :: i, a(20), funit

    open(unit=2, file='dat/he', status='replace')
    write(2, '(i2/, i2/, i2/, i2)') 1, 3, 5, 7
    close(2)

    !$omp parallel do num_threads(20) private(funit)
    do i = 1, 20
        funit=100+omp_get_thread_num()
        open(funit, file='dat/he', status='old')
        read(funit,'(i2)') a(i)
    end do
    !$omp end parallel do

    print *, a
end program he
</code></pre>

<p>I compiled it by gfortran compiler without getting any errors: <code>gfortran -fopenmp -o exe a.f90</code>, and run <code>./exe</code>, but got different errors each time I ran <code>./exe</code>. However, I also compiled it using ifort: <code>ifort -qopenmp -o exe a.f90</code>, and ran it, <code>./exe</code>, successfully.</p>

<p>One of the errors from gfortran in runtime is</p>

<pre><code>At line 15 of file fortran_learning_book.f90 (unit = 102)
Fortran runtime error: File already opened in another unit

Program aborted. Backtrace:

Program aborted. Backtrace:
#0  0x10c30aff2
#0  0x10c30aff2

Program aborted.
</code></pre>