mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-10 08:22:11 +01:00
implements tickets 180 and 295
This commit is contained in:
parent
959823771a
commit
a89363706a
@ -38,13 +38,15 @@ scope for the compiler to determine that a target binary should be available.
|
|||||||
|
|
||||||
\section{\code{declare} \code{target} Construct for Class Type}
|
\section{\code{declare} \code{target} Construct for Class Type}
|
||||||
|
|
||||||
|
\cppspecificstart
|
||||||
The following example shows how the \code{declare} \code{target} and \code{end}
|
The following example shows how the \code{declare} \code{target} and \code{end}
|
||||||
\code{declare} \code{target} directives are used to enclose the declaration
|
\code{declare} \code{target} directives are used to enclose the declaration
|
||||||
of a variable \plc{varY} with a class type \code{typeY}. The member function \code{typeY::foo()} cannot
|
of a variable \plc{varY} with a class type \code{typeY}. The member function \code{typeY::foo()} cannot
|
||||||
be accessed on a target device because its declaration did not appear between \code{declare}
|
be accessed on a target device because its declaration did not appear between \code{declare}
|
||||||
\code{target} and \code{end} \code{declare} \code{target} directives.
|
\code{target} and \code{end} \code{declare} \code{target} directives.
|
||||||
|
|
||||||
\cexample{declare_target}{2c}
|
\cnexample{declare_target}{2c}
|
||||||
|
\cppspecificend
|
||||||
|
|
||||||
\section{\code{declare} \code{target} and \code{end} \code{declare} \code{target} for Variables}
|
\section{\code{declare} \code{target} and \code{end} \code{declare} \code{target} for Variables}
|
||||||
|
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
|
|
||||||
The following example distinguishes the variables that are affected by the \code{default(none)}
|
The following example distinguishes the variables that are affected by the \code{default(none)}
|
||||||
clause from those that are not.
|
clause from those that are not.
|
||||||
|
Beginning with OpenMP 4.0, variables with \code{const}-qualified type and no mutable member
|
||||||
|
are no longer predetermined shared. Thus, these variables (variable \plc{c} in the example)
|
||||||
|
need to be explicitly listed
|
||||||
|
in data-sharing attribute clauses when the \code{default(none)} clause is specified.
|
||||||
|
|
||||||
\cexample{default_none}{1c}
|
\cexample{default_none}{1c}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Ownership of locks has changed since OpenMP 2.5. In OpenMP 2.5, locks are owned
|
Ownership of locks has changed since OpenMP 2.5. In OpenMP 2.5, locks are owned
|
||||||
by threads; so a lock released by the \code{omp\_unset\_lock} routine must be
|
by threads; so a lock released by the \code{omp\_unset\_lock} routine must be
|
||||||
owned by the same thread executing the routine. With OpenMP 3.0, locks are owned
|
owned by the same thread executing the routine. Beginning with OpenMP 3.0, locks are owned
|
||||||
by task regions; so a lock released by the \code{omp\_unset\_lock} routine in
|
by task regions; so a lock released by the \code{omp\_unset\_lock} routine in
|
||||||
a task region must be owned by the same task region.
|
a task region must be owned by the same task region.
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ This change in ownership requires extra care when using locks. The following pro
|
|||||||
is conforming in OpenMP 2.5 because the thread that releases the lock \code{lck}
|
is conforming in OpenMP 2.5 because the thread that releases the lock \code{lck}
|
||||||
in the parallel region is the same thread that acquired the lock in the sequential
|
in the parallel region is the same thread that acquired the lock in the sequential
|
||||||
part of the program (master thread of parallel region and the initial thread are
|
part of the program (master thread of parallel region and the initial thread are
|
||||||
the same). However, it is not conforming in OpenMP 3.0 and 3.1, because the task
|
the same). However, it is not conforming after OpenMP 2.5, because the task
|
||||||
region that releases the lock \code{lck} is different from the task region that
|
region that releases the lock \code{lck} is different from the task region that
|
||||||
acquires the lock.
|
acquires the lock.
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
\pagebreak
|
\pagebreak
|
||||||
\chapter{Parallel Random Access Iterator Loop}
|
\chapter{Parallel Random Access Iterator Loop}
|
||||||
\ccppspecificstart
|
\cppspecificstart
|
||||||
\label{chap:pra_iterator}
|
\label{chap:pra_iterator}
|
||||||
|
|
||||||
The following example shows a parallel random access iterator loop.
|
The following example shows a parallel random access iterator loop.
|
||||||
|
|
||||||
\cnexample{pra_iterator}{1c}
|
\cnexample{pra_iterator}{1c}
|
||||||
\ccppspecificend
|
\cppspecificend
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ The following is an example of the use of \code{threadprivate} for module variab
|
|||||||
\fnexample{threadprivate}{6f}
|
\fnexample{threadprivate}{6f}
|
||||||
\fortranspecificend
|
\fortranspecificend
|
||||||
|
|
||||||
\ccppspecificstart
|
\cppspecificstart
|
||||||
The following example illustrates initialization of \code{threadprivate} variables
|
The following example illustrates initialization of \code{threadprivate} variables
|
||||||
for class-type \code{T}. \code{t1} is default constructed, \code{t2} is constructed
|
for class-type \code{T}. \code{t1} is default constructed, \code{t2} is constructed
|
||||||
taking a constructor accepting one argument of integer type, \code{t3} is copy
|
taking a constructor accepting one argument of integer type, \code{t3} is copy
|
||||||
@ -102,5 +102,5 @@ class members. The \code{threadprivate} directive for a static class member must
|
|||||||
be placed inside the class definition.
|
be placed inside the class definition.
|
||||||
|
|
||||||
\cnexample{threadprivate}{5c}
|
\cnexample{threadprivate}{5c}
|
||||||
\ccppspecificend
|
\cppspecificend
|
||||||
|
|
||||||
|
1
README
1
README
@ -55,6 +55,7 @@ For a brief revision history, please see Changes.log.
|
|||||||
- Language h-rules
|
- Language h-rules
|
||||||
\cspecificbegin, \cspecificend
|
\cspecificbegin, \cspecificend
|
||||||
\cppspecificbegin, \cppspecificend
|
\cppspecificbegin, \cppspecificend
|
||||||
|
\ccppspecificbegin, \ccppspecificend
|
||||||
\fortranspecificbegin, \fortranspecificend
|
\fortranspecificbegin, \fortranspecificend
|
||||||
|
|
||||||
- See openmp.sty for more information
|
- See openmp.sty for more information
|
||||||
|
@ -470,6 +470,12 @@
|
|||||||
\ccppspecificend
|
\ccppspecificend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\newcommand\cppexample[2]{%
|
||||||
|
\needspace{5\baselineskip}\cppspecificstart
|
||||||
|
\cnexample{#1}{#2}
|
||||||
|
\cppspecificend
|
||||||
|
}
|
||||||
|
|
||||||
\newcommand\fexample[2]{%
|
\newcommand\fexample[2]{%
|
||||||
\needspace{5\baselineskip}\fortranspecificstart
|
\needspace{5\baselineskip}\fortranspecificstart
|
||||||
\fnexample{#1}{#2}
|
\fnexample{#1}{#2}
|
||||||
|
@ -13,14 +13,14 @@ void default_none(int a) {
|
|||||||
const int c = 1;
|
const int c = 1;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
#pragma omp parallel default(none) private(a) shared(z)
|
#pragma omp parallel default(none) private(a) shared(z, c)
|
||||||
{
|
{
|
||||||
int j = omp_get_num_threads();
|
int j = omp_get_num_threads();
|
||||||
/* O.K. - j is declared within parallel region */
|
/* O.K. - j is declared within parallel region */
|
||||||
a = z[j]; /* O.K. - a is listed in private clause */
|
a = z[j]; /* O.K. - a is listed in private clause */
|
||||||
/* - z is listed in shared clause */
|
/* - z is listed in shared clause */
|
||||||
x = c; /* O.K. - x is threadprivate */
|
x = c; /* O.K. - x is threadprivate */
|
||||||
/* - c has const-qualified type */
|
/* - c has const-qualified type and is listed in shared */
|
||||||
z[i] = y; /* Error - cannot reference i or y here */
|
z[i] = y; /* Error - cannot reference i or y here */
|
||||||
|
|
||||||
#pragma omp for firstprivate(y)
|
#pragma omp for firstprivate(y)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user