OpenMP Task和Taskwait构造

时间:2016-07-11 18:00:27

标签: c++ c openmp

我正在为OpenMP的一个非常小的子集实现一个运行时库,并且我遇到了Task和Taskwait结构的语义。

为了便于理解,我在下面创建了代码示例。在其中,系统是否应该进入实时锁定状态?对于'任务2'任务正在等待消耗由'task1'生成的数据。然而,任务' task1'是"任务等待"为了所有孩子的完成?当我使用GOMP和Intel OMP尝试此代码片段时,程序正常完成执行。

#include <stdio.h>
#include <math.h>
#include <omp.h>
#include <time.h>
#include <cstdlib>

int result;

void task2(int* res) {
    printf("Task2... %p\n", res);

}

void task1(int* res) {
    printf("Task1... %p\n", &result);

    #pragma omp task depend(in:result)
    task2(&result);

    #pragma omp taskwait
    printf("Task1 finishing...\n");
}

int main() {
    int res = 0;

    #pragma omp parallel
    #pragma omp single
    {
        printf("Res addr = %p\n", &result);

        #pragma omp task depend(inout:result)
        task1(&result);
    }

    return 0;
}

1 个答案:

答案 0 :(得分:2)

The task depend clauses only apply to sibling tasks. In that case task2 is not a sibling, but a child task of task1.

Quoting the relevant section of OpenMP 4.5:

[2.13.9] For the in dependence-type, if the storage location of at least one of the list items is the same as the storage location of a list item appearing in an out or inout dependence-type list of a task construct from which a sibling task was previously generated, then the generated task will be a dependent task of that sibling task.