Reputation: 26
Suppose I would like to run the functions in parallel.
void foo()
{
foo1(args);
foo2(args);
foo3(args);
foo4(args);
}
I want these functions calls run in parallel. How can I run these functions in parallel in OpenMP with C?
Upvotes: 0
Views: 809
Reputation: 2859
Assuming that the code is running serially when you enter foo()
, you have a couple of different options.
Option 1: use sections
void foo()
{
#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
foo1(args);
#pragma omp section
foo2(args);
#pragma omp section
foo3(args);
#pragma omp section
foo4(args);
}
}
}
Option 2: use tasks
void foo()
{
#pragma omp parallel
{
#pragma omp single
{
#pragma omp task
foo1(args);
#pragma omp task
foo2(args);
#pragma omp task
foo3(args);
#pragma omp task
foo4(args);
}
}
}
Tasks are the more modern way of expressing this, and, potentially, allow you more freedom in controlling the execution.
Upvotes: 2