module testit contains subroutine test(fname) implicit none character(len=*),intent(in) :: fname logical :: isOpened ! With the critical statements, there is no crash. ! Without the critical statements, a crash is likely of the loop is large. !!$OMP CRITICAL inquire(file=fname,opened=isOpened) !!$OMP END CRITICAL end subroutine test end module testit !================================================== program a use omp_lib use testit implicit none integer :: tid, i character(len=50) :: fname !$OMP PARALLEL PRIVATE(tid,i,fname) tid = OMP_get_thread_num() write(*,*) 'thread = ', tid write(fname,'(A,I2.2,A)') 'file_',tid,'.txt' !$OMP DO SCHEDULE(STATIC) do i = 1,100000 call test(fname) end do !$OMP END DO !$OMP END PARALLEL write(*,*) "FINISHED" end program a