-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcapture.tex
195 lines (164 loc) · 5.09 KB
/
capture.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
\clause{Captures}
\sclause{Introduction}
\pnum
A spawn capture allows a spawn statement
to make a copy of a variable
prior to the start of asynchronous execution.
\footnote{DFEP:
This corresponds to the
\tcode{firstprivate}
clause of OpenMP.
Cilk has no corresponding feature;
it isn't needed, because only a function-call can be spawned,
and arguments are guaranteed to be evaluated before the spawn happens.
}
A reduction capture allows a task block or parallel loop
to temporarily associate a reduction object
with an existing object,
to simplify parallel computation of a reduction.
\sclause{Spawn captures}
\ssclause*{Syntax}
\begin{bnf}
\nontermdef{spawn-capture}
\br
\terminal{_Copy_in} \terminal{(} spawn-capture-list \terminal{)}
\end{bnf}
\begin{bnf}
\nontermdef{spawn-capture-list}
\br
spawn-capture-item
\br
spawn-capture-list \terminal{,} spawn-capture-item
\end{bnf}
\begin{bnf}
\nontermdef{spawn-capture-item}
\br
identifier
\br
identifier \terminal{=} expression
\end{bnf}
\ssclause*{Constraints}
\pnum
If no expression is present in a spawn capture item,
the identifier shall be a name that is already in scope
at the beginning of the spawn capture item,
and the effective expression is taken to be the same as the identifier.
Otherwise, the effective expression
is the expression in the spawn capture item.
\pnum
The effective expression shall have complete object type.
\ssclause*{Semantics}
\pnum
Each spawn capture item declares a new object
named by the item's identifier,
having automatic storage duration.
The type of the declared object is that of the effective expression.
The scope of the name extends from the end of the spawn capture item
until the end of the spawn statement with which it is associated.
\pnum
The declared object is initialized
with the value of the effective expression.
The initialization of the declared object
occurs before asynchronous execution
of the spawned compound statement.
\pnum
Change the first sentence of paragraph 3 of subclause 6.3.2.1:
\begin{quote}
Except when it
\added{is the effective expression in a spawn capture item, or}
is the operand of the \tcode{sizeof} operator,
the \tcode{_Alignof} operator,
or the unary \tcode{\&} operator,
or is a string literal used to initialize an array,
an expression that has type ``array of type''
is converted to an expression with type ``pointer to type''
that points to the initial element of the array object
and is not an lvalue. ...
\end{quote}
\begin{example}
Consider the following code:
\begin{verbatim}
// Walk a list and call f() on the value of each element.
// Calls to f() can be done in parallel.
_Task _Block {
while (p) {
_Task _Spawn _Copy_in(p) { f(p->value); }
p = p->next;
}
}
\end{verbatim}
Without the \tcode{_Copy_in},
there would be a race on the variable \tcode{p},
because the call to \tcode{f}
is allowed to proceed in parallel with the continuation,
including the update.
\end{example}
\sclause{Reduction captures}
\ssclause*{Syntax}
\begin{bnf}
\nontermdef{reduction-capture}
\br
\terminal{_Reduction} \terminal{(} reduction-capture-list \terminal{)}
\end{bnf}
\begin{bnf}
\nontermdef{reduction-capture-list}
\br
reduction-capture-item
\br
reduction-capture-list \terminal{,} reduction-capture-item
\end{bnf}
\begin{bnf}
\nontermdef{reduction-capture-item}
\br
declaration-specifiers declarator
\br
declaration-specifiers declarator \terminal{:} expression
\end{bnf}
\ssclause*{Constraints}
\pnum
A reduction capture item
shall have some reduction type,
and shall not have static or thread storage duration.
\pnum
If no expression is present in a reduction capture item,
the identifier in the declarator
shall be a name that is already in scope
at the beginning of the reduction capture item,
and the effective expression is taken to be the same as the identifier.
Otherwise, the effective expression
is the expression in the reduction capture item.
\pnum
The effective expression shall be a modifiable lvalue,
and shall have a type that is compatible with the proxied type
of the item's reduction type.
\ssclause*{Semantics}
\pnum
Each reduction capture item declares a new object
with reduction type.
The scope of the name extends from the end of the reduction capture item
until the end of the task block or loop with which it is associated.
\pnum
Before execution of the task block or loop,
the new reduction object is initialized
with the value of the object designated by the effective expression.
Upon completion of the task block or loop,
the value of the reduction object is assigned back
to the object designated by the effective expression.
\pnum
Change the first sentence of paragraph 2 of subclause 6.3.2.1:
\begin{quote}
Except when it
\added{is the expression in a reduction capture item, or}
is the operand of the \tcode{sizeof} operator,
the \tcode{_Alignof} operator, the
unary \tcode{\&} operator,
the \tcode{++} operator,
the \tcode{--} operator,
or the left operand of the \tcode{.} operator
or an assignment operator,
an lvalue that does not have array type
is converted to the value stored in the designated object
(and is no longer an lvalue);
this is called
\defn{lvalue conversion}. ...
\end{quote}