/
ch8.tex
78 lines (66 loc) · 1.94 KB
/
ch8.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
\chapter{OpenMP in {\XMP} Programs}
\label{chap:openmp}
The usage of OpenMP directives in {\XMP} programs is subjected to
the following basic rule.
\begin{itemize}
\item {\XMP} directives and the invocation of an {\XMP}
intrinsic/built-in procedure should be single-threaded, and they
may therefore be placed in the sequential part, or one of
the {\tt single}, {\tt master}, or {\tt critical} regions
that are closely nested inside a {\tt parallel} region whose
parent thread is the initial thread;
\item with the exception that the {\XMP}'s {\tt loop} directive that
controls a loop can be placed immediately inside the OpenMP's
parallel loop directive ({\tt parallel do} for Fortran and
{\tt parallel for} for C), which controls the identical loop.
\end{itemize}
The behavior of coarray references in a {\tt parallel} region is
implemetation-defined.
\subsubsection*{Examples}
\index{Example!OpenMP in XcalableMP programs}
Assume that the following codes are placed in the sequential part of
the program.
\begin{XCexample}
#pragma omp parallel for
for (...){
#pragma xmp barrier // NG because not single-threaded
}
\end{XCexample}
\begin{XCexample}
#pragma omp parallel for
for (...){
#pragma omp single
{
#pragma xmp barrier // OK because single-threaded
// (inside a single region)
}
}
\end{XCexample}
\begin{XCexample}
#pragma omp parallel for
#pragma xmp loop // OK because immediately nested
for (...){
...
}
\end{XCexample}
\begin{XCexample}
#pragma xmp loop // OK because single-threaded (not nested)
#pragma omp parallel for
for (...){
...
}
\end{XCexample}
\begin{XCexample}
#pragma xmp loop // OK because single threaded (not nested)
for (...){
#pragma omp parallel for
for (...) { ... }
}
\end{XCexample}
\begin{XCexample}
#pragma omp parallel for
for (...){
#pragma xmp loop // NG because not immediately nested
for (...) { ... }
}
\end{XCexample}