Intel® C++ Compiler 16.0 User and Reference Guide

omp sections

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

Syntax

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

[!$omp section]

structured-block

[!$omp section]

structured-block

...

Arguments

clause

Can be one or more of the following clauses:

firstprivate(list)

Provides a superset of the functionality provided by the private clause. Each private data object is initialized with the value of the original object.

lastprivate(list)

Provides a superset of the functionality provided by the private clause. When exiting the region, the original object is updated with the value of the private copy from the last sequential iteration of the associated loop, or the lexically last section construct.

nowait

Indicates that an implementation may omit the barrier at the end of the worksharing region.

private(list)

Declares variables to be private to each thread in a team.

reduction(operator:list)

Performs a reduction on scalar variables.

Description

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”); }