【问题标题】:What does OpenMP structured-block mean in fortran?OpenMP 结构化块在 fortran 中是什么意思?
【发布时间】:2020-12-04 06:09:17
【问题描述】:

openMP 结构化块在 fortran 中是什么意思?

sections construct 为例:

!$omp sections
   !$omp section 
      structured-block 
   !$omp section 
      structured-block 
   ... 
!$omp end sections

我可以像这样在每个部分下有多个命令吗?

!$omp sections
  !$omp section
    command 1
    command 2
    command 3
  !$omp section
    command 4
    command 5
    command 6
  ...
!$omp end sections

这是对 section 结构的正确使用,更具体地说是“结构化块”吗?

【问题讨论】:

  • OpenMP 在其词汇表中定义了“结构化块”。你能读一下(如果你没有读过的话)然后根据任何特定的困难来完善这个问题吗?
  • 感谢@francescalus 的评论。从glossary 开始,它将结构化块定义为:“对于 Fortran,一个可执行语句块,顶部有一个入口,底部有一个出口,或者是一个 OpenMP 结构。”我对 OpenMP 还很陌生,为了清楚起见,我想举个例子。
  • 谢谢保罗。

标签: syntax fortran openmp


【解决方案1】:

“可执行语句块,顶部有一个入口,底部有一个出口” 意味着您不使用 goto 将控制权转移到块内的标签,并且不要使用 goto 将控制转移到块外的标签。

!$omp section
  call foo()
  bar = baz
  qux = bar
!$omp section
  ...

如果foo() 返回就好了。

!$omp section
  bar = foo()
  if (bar == baz) then
    goto qux
  end if
!$omp section
  ...

qux: ...

不好。

你可以有一个循环,只要它的整个主体都包含在块中,你可以调用函数和子例程,只要它们返回。

【讨论】:

  • 谢谢。那么在一个部分中可以使用多个命令吗?
  • 是的,这就是为什么它在 OpenMP 5.1 中被称为结构化块 sequence
  • openmp.org/spec-html/5.1/openmpsu2.html#x9-80001.2.2 有定义,如果他们有帮助的话:-)
  • 感谢吉姆考尼。这很有帮助
猜你喜欢
  • 2020-07-17
  • 2011-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-25
  • 2011-12-02
  • 1970-01-01
  • 2015-10-31
相关资源
最近更新 更多