在 OpenMP 中使用 if 子句
Use of if clause in OpenMP
无法理解以下代码中 if (0) 子句的用法,因为还存在 #pragma omp single 子句。有什么想法吗?
首先是来自 Specification 的定义(我假设你知道):
When an if clause is present on a task construct, and the if clause expression evaluates to false, an undeferred task is generated, and the encountering thread must suspend the current task region, for which execution cannot be resumed until the generated task is completed.
未延迟任务定义为:
A task for which execution is not deferred with respect to its generating task region. That is, its generating task region is suspended until execution of the undeferred task is completed.
从一般任务描述:
The encountering thread may immediately execute the task, or defer its execution. In the latter case, any thread in the team may be assigned the task.
这通常让我得出结论,正如您所说,结果与不使用 if(0)
的结果相同。但据我了解 undeferred
的意思是生成的任务由创建它的线程立即调用。
在此上下文中,通过将任务分配给先前空闲的线程,确保在 "one" 步骤中创建任务 A() 到 C(),无需上下文切换或介于两者之间。
无法理解以下代码中 if (0) 子句的用法,因为还存在 #pragma omp single 子句。有什么想法吗?
首先是来自 Specification 的定义(我假设你知道):
When an if clause is present on a task construct, and the if clause expression evaluates to false, an undeferred task is generated, and the encountering thread must suspend the current task region, for which execution cannot be resumed until the generated task is completed.
未延迟任务定义为:
A task for which execution is not deferred with respect to its generating task region. That is, its generating task region is suspended until execution of the undeferred task is completed.
从一般任务描述:
The encountering thread may immediately execute the task, or defer its execution. In the latter case, any thread in the team may be assigned the task.
这通常让我得出结论,正如您所说,结果与不使用 if(0)
的结果相同。但据我了解 undeferred
的意思是生成的任务由创建它的线程立即调用。
在此上下文中,通过将任务分配给先前空闲的线程,确保在 "one" 步骤中创建任务 A() 到 C(),无需上下文切换或介于两者之间。