omp single在循环10次后不起作用?

时间:2015-06-23 21:01:33

标签: openmp

我正在学习如何使用!$ omp single in openmp。在下面的程序中,当wwwno逐个从10变为0时,我希望"区域1"由我使用OMP SINGLE为每个wwwno执行一个线程。当wwwno从10更改为2时也是如此,但是当wwwno更改为1时,所有4个线程都执行了语句' print *,"区域1?...."'这是在OMP SINGLE内部(见下面的输出)。任何人都可以告诉我为什么!$ OMP SINGLE在我的情况下失败了吗?非常感谢你。

program test
use omp_lib
implicit none
integer:: t, wwwno, wwwno_init, updown, thread
real(8) :: Lnfactor, end_Lnfactor
logical :: His_flag, Right_flag

end_Lnfactor = 1.d-8
print *, "                 wwwno    thread   Lnfactor"

!$omp parallel private(wwwno, Right_flag, t, thread)

thread = omp_get_thread_num()

Do wwwno = 10, 0, -1

    !$omp barrier                   
    !$omp single
        print *, "region 1? ", wwwno, thread, Lnfactor
        Lnfactor = 1.d0
        Lnfactor = 2.d0 * Lnfactor
    !$omp end single
    !$omp barrier

    DO While(Lnfactor>end_Lnfactor)

    !$omp barrier
    !$omp single
        His_flag=.false.
        Lnfactor = 5.d-1 * Lnfactor     
    !$omp end single

        t=0

        DO While(His_flag .eqv. .false.)

            t=t+1           

            if (mod(t,1000)==0) then
            !$omp critical
                His_flag = .true.
            !$omp end critical
            endif

        ENDDO

    !$omp barrier
    ENDDO

!$omp barrier
Enddo

print *, "arrived, thread no =", thread
!$omp end parallel

End program

屏幕上的OUPUT:

                  wwwno      thread   Lnfactor
 region 1?           10           3  2.188457805988275E-314
 region 1?            9           2  7.450580596923828E-009
 region 1?            8           1  7.450580596923828E-009
 region 1?            7           2  7.450580596923828E-009
 region 1?            6           1  7.450580596923828E-009
 region 1?            5           2  7.450580596923828E-009
 region 1?            4           0  7.450580596923828E-009
 region 1?            3           1  7.450580596923828E-009
 region 1?            2           2  7.450580596923828E-009
 region 1?            1           2  3.725290298461914E-009
 region 1?            1           0   2.00000000000000
 region 1?            1           1   2.00000000000000
 region 1?            1           3   2.00000000000000
 region 1?            0           2  7.450580596923828E-009
 region 1?            0           3   2.00000000000000
 region 1?            0           1   2.00000000000000
 region 1?            0           0   2.00000000000000
 arrived, thread no =           2
 arrived, thread no =           3
 arrived, thread no =           1
 arrived, thread no =           0

0 个答案:

没有答案