在隐式障碍处等待 OpenMP 任务完成?
Waiting for OpenMP task completion at implicit barriers?
如果我创建了一堆 OpenMP 任务并且不使用 taskwait
,程序在哪里等待任务完成?考虑以下示例:
#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 规范中找不到关于此问题的任何信息。
编辑
来自 OpenMP 规范中的 barrier
描述:
All threads of the team executing the binding parallel region must
execute the barrier region and complete execution of all explicit
tasks bound to this parallel region before any are allowed to continue
execution beyond the barrier.
然而,这并没有说明是我负责完成任务还是 OpenMP 运行时为我完成。
OpenMP 中的任务完成是隐式的,而不是显式的(1.2.5 任务术语)
task completion Task completion occurs when the end of the structured block associated with the construct that generated the task is reached.
single
工作共享构造的末尾有一个隐式障碍。正如您提到的,障碍等待明确的任务。因此,所有任务都将在 single
块的那一刻完成。
如果我创建了一堆 OpenMP 任务并且不使用 taskwait
,程序在哪里等待任务完成?考虑以下示例:
#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 规范中找不到关于此问题的任何信息。
编辑
来自 OpenMP 规范中的 barrier
描述:
All threads of the team executing the binding parallel region must execute the barrier region and complete execution of all explicit tasks bound to this parallel region before any are allowed to continue execution beyond the barrier.
然而,这并没有说明是我负责完成任务还是 OpenMP 运行时为我完成。
OpenMP 中的任务完成是隐式的,而不是显式的(1.2.5 任务术语)
task completion Task completion occurs when the end of the structured block associated with the construct that generated the task is reached.
single
工作共享构造的末尾有一个隐式障碍。正如您提到的,障碍等待明确的任务。因此,所有任务都将在 single
块的那一刻完成。