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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
|
<!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="blocked_range Template Class">
<meta name="DC.subject" content="blocked_range Template Class">
<meta name="keywords" content="blocked_range Template Class">
<meta name="DC.Relation" scheme="URI" content="../../../reference/algorithms/range_concept.htm">
<meta name="DC.Relation" scheme="URI" content="../../../reference/algorithms/range_concept/blocked_range_cls/blocked_range.htm">
<meta name="DC.Relation" scheme="URI" content="../../../reference/algorithms/range_concept/blocked_range_cls/blocked_range_1.htm">
<meta name="DC.Relation" scheme="URI" content="../parallel_for_func.htm#parallel_for_func">
<meta name="DC.Relation" scheme="URI" content="../parallel_reduce_func.htm#parallel_reduce_func">
<meta name="DC.Relation" scheme="URI" content="../parallel_scan_func.htm#parallel_scan_func">
<meta name="DC.Relation" scheme="URI" content="../../environment/enabling_debugging_features.htm#enabling_debugging_features">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="blocked_range_cls">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../../intel_css_styles.css">
<title>blocked_range Template Class</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="blocked_range_cls">
<!-- ==============(Start:NavScript)================= -->
<script src="..\..\..\NavScript.js" language="JavaScript1.2" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript">WriteNavLink(3);</script>
<!-- ==============(End:NavScript)================= -->
<a name="blocked_range_cls"><!-- --></a>
<h1 class="topictitle1">blocked_range Template Class</h1>
<div>
<div class="section"><h2 class="sectiontitle">Summary</h2>
Template class for a recursively divisible
half-open interval.
</div>
<div class="section"><h2 class="sectiontitle">Header</h2>
<p>
<pre>#include "tbb/blocked_range.h"</pre>
</p>
</div>
<div class="section"><h2 class="sectiontitle">Syntax</h2>
<pre>template<typename Value> class blocked_range;</pre>
</div>
<div class="section"><h2 class="sectiontitle">Description</h2>
<p>A
<samp class="codeph">blocked_range<Value></samp> represents a half-open
range [<em>i</em>,<em>j</em>) that can be recursively split. The types of
<em>i</em> and
<em>j</em> must model the requirements in the following table. In the
table, type
<samp class="codeph">D</samp> is the type of the expression
<samp class="codeph">"j-i"</samp>. It can be any integral type that is convertible
to
<samp class="codeph">size_t</samp>. Examples that model the Value requirements are
integral types, pointers, and STL random-access iterators whose difference can
be implicitly converted to a
<samp class="codeph">size_t</samp>.
</p>
<p>A
<samp class="codeph">blocked_range</samp> models the Range concept.
</p>
<div class="tablenoborder"><table cellpadding="4" summary="" width="100%" frame="hsides" border="1" rules="all"><caption><span class="tablecap">Value Concept for blocked_range</span></caption>
<thead align="left">
<tr>
<th class="cellrowborder" valign="top" id="d14709e109">
<p>Pseudo-Signature
</p>
</th>
<th class="row-nocellborder" valign="top" id="d14709e115">
<p>Semantics
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> Value::Value( const Value&
)</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p> Copy constructor.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> Value::~Value()</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p> Destructor.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> void operator=( const Value&
)</samp>
<div class="Note"><h3 class="NoteTipHead">
Note</h3>
<p> The return type
<samp class="codeph">void</samp> in the pseudo-signature denotes that
<samp class="codeph">operator=</samp> is not required to return a
value. The actual
<samp class="codeph">operator=</samp> can return a value, which will
be ignored by
<samp class="codeph">blocked_range</samp> .
</p>
</div>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p> Assignment
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> bool operator<( const
Value& i, const Value& j )</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p> Value
<em>i</em> precedes value<em> j</em>.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> D operator-( const Value& i,
const Value& j )</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p> Number of values in range
<samp class="codeph">[i,j)</samp>.
</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d14709e109 ">
<p><samp class="codeph"> Value operator+( const Value&
i, D k )</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d14709e115 ">
<p><em>k</em>th value after
<em>i</em>.
</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>A
<samp class="codeph">blocked_range<Value></samp> specifies a
<em>grainsize</em> of type
<samp class="codeph">size_t</samp>. A
<samp class="codeph">blocked_range</samp> is splittable into two subranges if the
size of the range exceeds
<em>grain size</em>. The ideal grain size depends upon the context of the
<samp class="codeph">blocked_range<Value></samp>, which is typically as the
range argument to the loop templates
<samp class="codeph">parallel_for</samp>,
<samp class="codeph">parallel_reduce</samp>, or
<samp class="codeph">parallel_scan</samp>. A too small grainsize may cause
scheduling overhead within the loop templates to swamp speedup gained from
parallelism. A too large grainsize may unnecessarily limit parallelism. For
example, if the grain size is so large that the range can be split only once,
then the maximum possible parallelism is two.
</p>
<p>Here is a suggested procedure for choosing
<em>grainsize</em>:
</p>
<ol>
<li>Set the grainsize parameter to 10,000. This
value is high enough to amortize scheduler overhead sufficiently for
practically all loop bodies, but may be unnecessarily limit parallelism.
</li>
<li>Run your algorithm on
<em>one</em> processor.
</li>
<li>Start halving the grainsize parameter and see
how much the algorithm slows down as the value decreases.
</li>
</ol>
<p>A slowdown of about 5-10% is a good setting for
most purposes.
</p>
<div class="Note"><h3 class="NoteTipHead">
Tip</h3>
<p>For a
<samp class="codeph">blocked_range [i,j)</samp> where<samp class="codeph"> j<i</samp>,
not all methods have specified behavior. However, enough methods do have
specified behavior that
<samp class="codeph">parallel_for</samp>,
<samp class="codeph">parallel_reduce</samp>, and
<samp class="codeph">parallel_scan</samp> iterate over the same iteration space
as the serial loop
<samp class="codeph">for( Value index=i; index<j; ++index )...</samp>, even
when
<samp class="codeph">j<i</samp>. If
<samp class="codeph">TBB_USE_ASSERT</samp> is nonzero, methods with unspecified
behavior raise an assertion failure.
</p>
</div>
<p><strong>Example</strong>
</p>
<p>A
<samp class="codeph">blocked_range<Value></samp> typically appears as a
range argument to a loop template. See the examples for
<samp class="codeph">parallel_for</samp>,<samp class="codeph"> parallel_reduce</samp>, and
<samp class="codeph">parallel_scan</samp>.
</p>
</div>
<div class="section"><h2 class="sectiontitle">Members</h2>
<pre>
namespace tbb {
template<typename Value>
class blocked_range {
public:
// types
typedef size_t size_type;
typedef Value const_iterator;
// constructors
blocked_range( Value begin, Value end,
size_type grainsize=1 );
blocked_range( blocked_range& r, split );
// capacity
size_type size() const;
bool empty() const;
// access
size_type grainsize() const;
bool is_divisible() const;
// iterators
const_iterator begin() const;
const_iterator end() const;
};
}
</pre>
<div class="tablenoborder"><table cellpadding="4" summary="" frame="border" border="1" cellspacing="0" rules="all"><span class="tabledesc">The following table provides additional information on the
members of this template class.
</span><thead align="left">
<tr>
<th class="cellrowborder" valign="top" width="33.89830508474576%" id="d14709e390">Member
</th>
<th class="cellrowborder" valign="top" width="66.10169491525423%" id="d14709e393">Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">size_type
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p>The type for measuring the size of a
<samp class="codeph">blocked_range</samp>. The type is always a
<samp class="codeph">size_t</samp>.
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">const_iterator</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">The type of a value in the range. Despite
its name, the type
<samp class="codeph">const_iterator</samp> is not necessarily an STL
iterator; it merely needs to meet the Value requirements in the table above.
However, it is convenient to call it
<samp class="codeph">const_iterator</samp> so that if it is a
const_iterator, then the<samp class="codeph"> blocked_range</samp> behaves like a
read-only STL container.
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">blocked_range( Value begin, Value
end, size_t grainsize=1 )
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 "><a href="blocked_range_cls/blocked_range.htm">More Info</a>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">blocked_range( blocked_range&
range, split )
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 "><a href="blocked_range_cls/blocked_range_1.htm">More Info</a>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">size_type size() const
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Requirements</strong> :<samp class="codeph"> end()<begin()</samp> is
false.
</p>
<p><strong>Effects</strong>: Determines size of range.
</p>
<p><strong>Returns</strong>
</p>
<p><samp class="codeph"> end()-begin()</samp>
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">bool empty() const
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Effects</strong>: Determines if range is empty.
</p>
<p><strong>Returns</strong>:
<samp class="codeph">!(begin()<end())</samp>
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">size_type grainsize() const
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Returns</strong>: Grain size of range.
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">bool is_divisible() const
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Requirements</strong>:
<samp class="codeph"> !(end()<begin())</samp>
</p>
<p><strong>Effects</strong>: Determines if range can be split into
subranges.
</p>
<p><strong>Returns</strong>: True if
<samp class="codeph">size()>grainsize();</samp> false otherwise.
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">const_iterator begin()
const</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Returns</strong>: Inclusive lower bound on range.
</p>
</td>
</tr>
<tr>
<td class="cellrowborder" valign="top" width="33.89830508474576%" headers="d14709e390 "><span class="keyword">const_iterator end() const
</span>
</td>
<td class="cellrowborder" valign="top" width="66.10169491525423%" headers="d14709e393 ">
<p><strong>Returns</strong>: Exclusive upper bound on range.
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="../../../reference/algorithms/range_concept.htm">Range Concept</a></div>
</div>
<div class="See Also">
<ul class="ullinks">
<li class="ulchildlink"><a href="../../../reference/algorithms/range_concept/blocked_range_cls/blocked_range.htm">blocked_range( Value begin, Value end, size_t grainsize=1 )</a><br>
</li>
<li class="ulchildlink"><a href="../../../reference/algorithms/range_concept/blocked_range_cls/blocked_range_1.htm">blocked_range( blocked_range& range, split )</a><br>
</li>
</ul>
<h2>See Also</h2>
<div class="linklist">
<div><a href="../parallel_for_func.htm#parallel_for_func">parallel_for Template Function
</a></div>
<div><a href="../parallel_reduce_func.htm#parallel_reduce_func">parallel_reduce Template Function
</a></div>
<div><a href="../parallel_scan_func.htm#parallel_scan_func">parallel_scan Template Function
</a></div>
<div><a href="../../environment/enabling_debugging_features.htm#enabling_debugging_features">TBB_USE_ASSERT Macro
</a></div></div>
</div>
</body>
</html>
|