mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-04 05:41:33 +01:00
25 lines
1.1 KiB
TeX
25 lines
1.1 KiB
TeX
\pagebreak
|
|
\section{\kcode{firstprivate} Clause and \kcode{sections} Construct}
|
|
\label{sec:fpriv_sections}
|
|
\index{constructs!sections@\kcode{sections}}
|
|
\index{sections construct@\kcode{sections} construct}
|
|
\index{constructs!section@\kcode{section}}
|
|
\index{section construct@\kcode{section} construct}
|
|
\index{clauses!firstprivate@\kcode{firstprivate}}
|
|
\index{firstprivate clause@\kcode{firstprivate} clause}
|
|
|
|
In the following example of the \kcode{sections} construct the \kcode{firstprivate}
|
|
clause is used to initialize the private copy of \ucode{section_count} of each
|
|
thread. The problem is that the \kcode{section} constructs modify \ucode{section_count},
|
|
which breaks the independence of the \kcode{section} constructs. When different
|
|
threads execute each section, both sections will print the value 1. When the same
|
|
thread executes the two sections, one section will print the value 1 and the other
|
|
will print the value 2. Since the order of execution of the two sections in this
|
|
case is unspecified, it is unspecified which section prints which value.
|
|
|
|
\cexample{fpriv_sections}{1}
|
|
|
|
\ffreeexample{fpriv_sections}{1}
|
|
|
|
|