问题描述
如果我创建了一堆OpenMP任务并且不使用taskwait
,程序将在哪里等待任务完成?考虑以下示例:
If I create a bunch of OpenMP tasks and do not use taskwait
, where does the program wait for that tasks completion? Consider the following example:
#pragma omp parallel
{
#pragma omp single
{
for (int i = 0; i < 1000; i++) {
#pragma omp task
... // e.g., call some independent function
}
// no taskwait here
}
// all the tasks completed now?
}
程序是否在single
块末尾的隐式屏障处等待任务完成?我认为是这样,但是在OpenMP规范中找不到有关此问题的任何信息.
Does the program wait for task completion at the implicit barrier at the end of the single
block? I assume so, but cannot find any information about this issue in the OpenMP Specification.
编辑
来自OpenMP规范中的barrier
描述:
From barrier
description in OpenMP Spec.:
但是,这并没有说明我是负责任务完成还是OpenMP运行时为我完成任务.
This, however, does not says whether I am responsible for task completion or the OpenMP runtime does it for me.
推荐答案
OpenMP中的任务完成是隐式的,不是显式的(1.2.5任务术语)
Task completion in OpenMP is implicit, not explicit (1.2.5 Tasking Terminology)
single
工作共享结构的末尾有一个隐式障碍.如您所述,障碍等待明确的任务.因此,所有任务将在single
块的处完成.
There is an implicit barrier at the end of the single
worksharing construct. As you mentioned, barriers wait for explicit tasks. Therefore all tasks will be completed at the of the single
block.
这篇关于等待OpenMP任务在隐性障碍下完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!