OpenMP Parallel Sections

suggest change

This 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 is printed before the parallel region and end after it. The three words can appear in any order, and their characters can also interleave, because the stream insertions are not synchronized.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents