Taskloop
Taskloop is a directive in OpenMP, introduced with OpenMP 5.0, that converts the iterations of a loop into tasks that are scheduled by the runtime. It is designed to provide scalable parallelism for loops where the cost of each iteration varies or is not known ahead of time. By grouping iterations into tasks (controlled by grainsize and related options), taskloop aims to balance overhead and load distribution more effectively than creating a separate task for every iteration.
How it works: When a loop is preceded by a taskloop directive, the iterations are partitioned into
Usage example: In C/C++, a typical pattern is:
- This is a hypothetical example; exact syntax may vary by compiler:
{
#pragma omp taskloop grainsize(64)
}
}
This converts the loop into tasks that may be executed by different threads.
Limitations and considerations: All iterations should be independent to avoid data races. The overhead of task