OMP Single for output subroutine
<p>I have a code to compute a dynamic process for a duration, i.e. <code>it = 1, itlast</code>, and within this duration, I want to print certain result in every <code>itsprint</code> interval. Below is the code:</p>

<pre><code>!$OMP PARALLEL DEFAULT (none) SHARED(w) &amp;
!$OMP&amp; SHARED(itlast)                       &amp;
!$OMP&amp; SHARED(itprint, itsprint)            &amp;
!$OMP&amp; PRIVATE(i, j, it)                    &amp;
!$OMP&amp; PRIVATE(ntprint, mtprint)
do it = 1, itlast
    !..... ALL COMPUTATIONS .....!

    !$OMP SINGLE        
    mtprint = it/itsprint
    if (itsprint*mtprint .ne. it) goto 20
        call timser(it)
20  continue
    !$OMP END SINGLE
end do
!$OMP PARALLEL END
</code></pre>

<p>And the <code>subroutine timser</code> is displayed as follow.</p>

<pre><code>subroutine timser(it)
    use tuna_params
    implicit none

    integer :: it, k
    real :: time_s, hour

    time_s = it*delt
    hour = time_s/3600.0

    write(16,89) hour, (w(nxwtser(k),nywtser(k),2), k = 1, ntser, 1)

89  format(f10.4, 999f10.4)
end subroutine timser
</code></pre>

<p>Doing this, I allow all threads to work on computation. For every <code>it</code>, at the end of computation, only one single thread will check the <code>if</code> statement and get into <code>subroutine timser</code> for output printing. This code works just fine when using</p>

<ul>
<li><code>gfortran (GNU Fortran (Ubuntu 4.8.4.-2ubuntu1~14.04) 4.8.4)</code>: <code>gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out</code></li>
<li><code>ifort (Intel Compiler 16.0 Update 1)</code>: <code>ifort mycode.f90 -openmp -CB -o mycode.exe</code></li>
</ul>

<p>However, if I compile and run this code in a cluster using <code>gfortran (GNU Fortran (GCC) 4.1.2 20080704 (Red Hat 4.1.2-50))</code>: <code>gfortran mycode.f90 -fopenmp -fbounds-check -o mycode.out</code>, all threads can get into <code>subroutine timser</code> and write on output file. I have no idea to debug this problem, please guide me to fix this problem. Thanks.</p>