练习OpenMP在Fortran中的应用,主要是代码中Single那一部分,传入的a值应该是0,为什么运行后a值变成1了?谢谢各位。
[Fortran] 纯文本查看 复制代码 program test17
use omp_lib
implicit none
integer tid,cpus
integer a
call omp_set_num_threads(3)
!$omp parallel private(a,tid)
tid=omp_get_thread_num()
a=tid
write(*,*) 'a=',a,'tid=',tid,' before single'
!$omp single
write(*,*)
cpus=omp_get_num_threads()
tid=omp_get_thread_num()
a=a+2**tid
write(*,*) 'single threads:', cpus
write(*,*) 'a=',a,'tid=',tid,' during single'
write(*,*)
!$omp end single copyprivate(a)
tid=omp_get_thread_num()
write(*,*) 'a=',a,'tid=',tid,'after single'
!$omp end parallel
read(*,*)
end program test17 |