OpenMP Parallel Sections
suggest changeThis example shows how to execute chunks of code in parallel
std::cout << "begin ";
// Start of parallel sections
#pragma omp parallel sections
{
// Execute these sections in parallel
#pragma omp section
{
... do something ...
std::cout << "hello ";
}
#pragma omp section
{
... do something ...
std::cout << "world ";
}
#pragma omp section
{
... do something ...
std::cout << "forever ";
}
}
// end of parallel sections
std::cout << "end";
Output
- begin hello world forever end
- begin world hello forever end
- begin hello forever world end
- begin forever hello world end
As execution order is not guaranteed, you may observe any of the above output.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents