omp sections

Defines a region of structured blocks that will be distributed among the threads in a team.


#pragma omp sections [clause,clause , ...]

[!$omp section]


[!$omp section]





Can be one or more of the following clauses:

  • firstprivate(list)

  • lastprivate(list)

  • nowait

  • private(list)

  • reduction(operator:list)


The sections construct encloses a set of structured-block sections that will be run in parallel. The sections constructs are executed once by a thread in a team.

Example: Searching in parallel using three different methods

#include <omp.h>
int found_method1, found_method2, found_method3;

#pragma omp parallel num_threads(3) {
        #pragma omp sections {
                #pragma omp section
                  found_method1 = method1_search();

                  #pragma omp section
                found_method2 = method2_search();

                  #pragma omp section
                  found_method3 = method3_search();
if (found_method1) { printf(“Found with method 1\n”); }
if (found_method2) { printf(“Found with method 2\n”); }
if (found_method3) { printf(“Found with method 3\n”); }
For more complete information about compiler optimizations, see our Optimization Notice.