Fortran:openmp笔记18

!.. 1. sections指令在大多数情况下与一个独立的parallel指令一起使用,因此openmp提供了一个指令!$parallel sections来方便编程人员编程
!.. 2. 一个程序中可以定义多个sections结构,每个sections结构中又可以定义多个section
!.. 3. 同一个sections中section之间处于并行状态,sections与其他sections之间处于串行状态
!.. 4. section内部不允许出现能够到达section之外的跳转语句,也不允许有外部的跳转语句到达section内部
Program multi_sections
  use omp_lib
  implicit none
  integer :: tid, nthreads

  call omp_set_num_threads(6)
  write(*,'(1x,a)') "Section No.    section no.    nthreads    id"
  write(*,'(1x,a)') "Sections A "

  !$omp parallel private(tid, nthreads)
  !$omp sections
  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 1: ", nthreads, tid 

  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 2: ", nthreads, tid 

  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 3: ", nthreads, tid 
  !$omp end sections
  !$omp end parallel

  write(*,'(1x,a)') "Sections B "
  !$omp parallel private(tid, nthreads)
  !$omp sections
  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 4: ", nthreads, tid 

  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 5: ", nthreads, tid 

  !$omp section
  tid      = omp_get_thread_num()
  nthreads = omp_get_num_threads()
  write(*,'(1x,a,i8,i8)') "                section 6: ", nthreads, tid 
  !$omp end sections
  !$omp end parallel

End program multi_sections

!.. 总结
!.. 1. 程序定义了两个sections并行域。每个sections并行域有三个section,sections并行域中执行section的三个子进程号各不相同
!.. 2. sections A与sections B的并行域在程序中处于串行状态
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值