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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- saved from url=(0014)about:internet -->
<html xmlns:MSHelp="http://www.microsoft.com/MSHelp/" lang="en-us" xml:lang="en-us"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="DC.Type" content="reference">
<meta name="DC.Title" content="parallel_do Template Function">
<meta name="DC.subject" content="parallel_do Template Function">
<meta name="keywords" content="parallel_do Template Function">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms.htm">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms/parallel_do_func/parallel_do_feeder_cls.htm">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="parallel_do_func">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../intel_css_styles.css">
<title>parallel_do Template Function</title>
<xml>
<MSHelp:Attr Name="DocSet" Value="Intel"></MSHelp:Attr>
<MSHelp:Attr Name="Locale" Value="kbEnglish"></MSHelp:Attr>
<MSHelp:Attr Name="TopicType" Value="kbReference"></MSHelp:Attr>
</xml>
</head>
<body id="parallel_do_func">
<!-- ==============(Start:NavScript)================= -->
<script src="..\..\NavScript.js" language="JavaScript1.2" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript">WriteNavLink(2);</script>
<!-- ==============(End:NavScript)================= -->
<a name="parallel_do_func"><!-- --></a>
<h1 class="topictitle1">parallel_do Template Function</h1>
<div>
<div class="section"><h2 class="sectiontitle">Summary</h2>
Template function that processes work items in
parallel.
</div>
<div class="section"><h2 class="sectiontitle">Header</h2>
<p>
<pre> #include "tbb/parallel_do.h"</pre>
</p>
</div>
<div class="section"><h2 class="sectiontitle">Syntax</h2>
<pre>template<typename InputIterator, typename Body>
void parallel_do( InputIterator first, InputIterator last,
Body body[, task_group_context& group] );
</pre>
</div>
<div class="section"><h2 class="sectiontitle">Description</h2>
<p>A
<samp class="codeph">parallel_do(<em>first,last,body</em>)</samp> applies a function
object body over the half-open interval [<em>first,last</em>). Items may be
processed in parallel. Additional work items can be added by body if it has a
second argument of type<samp class="codeph"> parallel_do_feeder</samp>. The function
terminates when<samp class="codeph"> body(x)</samp> returns for all items x that were in
the input sequence or added to it by method
<samp class="codeph">parallel_do_feeder::add</samp>.
</p>
<p>The requirements for input iterators are specified in Section 24.1 of
the ISO C++ standard. The table below shows the requirements on type Body.
</p>
<div class="tablenoborder"><table cellpadding="4" summary="" width="100%" frame="hsides" border="1" rules="all"><caption><span class="tablecap">parallel_do Requirements for Body B and its
Argument Type T</span></caption>
<thead align="left">
<tr>
<th class="cellrowborder" valign="top" id="d2552e96">
<p>Pseudo-Signature
</p>
</th>
<th class="row-nocellborder" valign="top" id="d2552e102">
<p>Semantics
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d2552e96 ">
<pre>B::operator()(
<em>cv-qualifiers</em> T& item,
parallel_do_feeder<T>& feeder
) const
OR
B::operator()(<em>cv-qualifiers</em> T&
item ) const
</pre>
</td>
<td class="row-nocellborder" valign="top" headers="d2552e102 ">
<p>Process item. Template<samp class="codeph"> parallel_do</samp> may
concurrently invoke operator() for the same
<samp class="codeph">this</samp> but different
<samp class="codeph">item</samp>.
</p>
<p> The signature with feeder permits additional work items to be
added.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d2552e96 ">
<p><samp class="codeph"> T( const T& )
</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d2552e102 ">
<p> Copy a work item.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d2552e96 ">
<p><samp class="codeph"> ~T::T()</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d2552e102 ">
<p> Destroy a work item.
</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>For example, a unary function object, as defined in Section 20.3 of
the C++ standard, models the requirements for B.
</p>
<div class="Note"><h3 class="NoteTipHead">
Caution</h3>
<p>Defining both the one-argument and two-argument forms of
<samp class="codeph">operator()</samp> is not permitted.
</p>
</div>
<div class="Note"><h3 class="NoteTipHead">
Note</h3>
<p>The parallelism in
<samp class="codeph">parallel_do</samp> is not scalable if all of the items come
from an input stream that does not have random access. To achieve scaling, do
one of the following:
</p>
<ul type="disc">
<li>
<p>Use random access iterators to specify the input stream.
</p>
</li>
<li>
<p>Design your algorithm such that the body often adds more than
one piece of work.
</p>
</li>
<li>
<p>Use<samp class="codeph"> parallel_for</samp> instead.
</p>
</li>
</ul>
</div>
<p>To achieve speedup, the grainsize of
<samp class="codeph">B::operator()</samp> needs to be on the order of at least
~100,000 clock cycles. Otherwise, the internal overheads of
<samp class="codeph">parallel_do</samp> swamp the useful work.
</p>
<p>The algorithm can be passed a
<samp class="codeph">task_group_context</samp> object so that its tasks are
executed in this group. By default the algorithm is executed in a bound group
of its own.
</p>
<p><strong>Example</strong>
</p>
<p>The following code sketches a body with the
two-argument form of
<samp class="codeph">operator(</samp>).
</p>
<pre>struct MyBody {
void operator()(item_t item,
parallel_do_feeder<item_t>& feeder ) {
for each new piece of work implied by item do {
item_t new_item = initializer;
feeder.add(new_item);
}
}
};
</pre>
</div>
</div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="../../reference/algorithms.htm">Algorithms</a></div>
</div>
<div>
<ul class="ullinks">
<li class="ulchildlink"><a href="../../reference/algorithms/parallel_do_func/parallel_do_feeder_cls.htm">parallel_do_feeder<item> class</a><br>
</li>
</ul>
</div>
</body>
</html>
|