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
1.png (43 KB, 下载次数: 205)
欢迎光临 Fortran Coder (http://bbs.fcode.cn/) | Powered by Discuz! X3.2 |