Task scheduling points of OpenMP tasks

自闭症网瘾萝莉.ら 提交于 2020-01-06 08:29:08

问题


I have the following code:

#pragma omp parallel
{
    #pragma omp single
    {
        for(node* p = head; p; p = p->next)
        {
            preprocess(p);

            #pragma omp task
            process(p);
        }
    }
}

I would like to know when do the threads start computing the tasks. As soon as the task is created with #pragma omp task or only after all tasks are created?

Edit:

int* array = (int*)malloc...
#pragma omp parallel
{
    #pragma omp single
    {
        while(...){
            preprocess(array);

            #pragma omp task firstprivate(array)
            process(array);
        }
    }
}

回答1:


In your example, the worker threads can start executing the created tasks as soon as they have been created. There's no need to wait for the completion of the creation of all tasks before the first task is executed.

So, basically, after the first task has been created by the producer, one worker will pick it up and start executing the task. However, be advised that the OpenMP runtime and compiler have certain freedom in this. They might defer execution a bit or even execute some of the tasks in place.

If you want to read up the details, you will need to dig through the OpenMP specification at www.openmp.org. It's a bit hard to read, but it is the definitive source of information.

Cheers, -michael



来源:https://stackoverflow.com/questions/23012199/task-scheduling-points-of-openmp-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!