<h1class="title">Intel® Threading Building Blocks.<br>Parallel_preorder sample</h1>
</div>
<p>
Example that uses parallel_do to do parallel preorder traversal of a sparse graph.
<br><br>
Each vertex in the graph is called a "cell".
Each cell has a value.
The value is a matrix.
Some of the cells have operators
that compute the cell's value, using other cell's values as input.
A cell that uses the value of cell x is called a successor of x.
<br><br>
The algorithm works as follows.
<ol>
<li> Compute the set of cells that have no inputs. This set is called <tt>root_set</tt>.
<li> Each cell has an associated field <tt>ref_count</tt> that is an atomic integer.
Initialize <tt>ref_count</tt> to the number of inputs for the Cell.
<li> Update each cell in <tt>root_set</tt>, by applying a <tt>parallel_do</tt> to a <tt>root_set</tt>
<li> After updating a cell, for each of its successors
<ol>
<li> Atomically decrement the successor's <tt>ref_count</tt>
<li> If the count became zero, add the cell to the set of cells to be updated,
by calling <tt>parallel_do_feeder_impl::add</tt>.
</ol>
</ol>
The times printed are for the traversal and update,
and do not include time for computing the root_set.
<br><br>
The example is using custom synchronization via <tt>ref_count</tt> atomic variable.
Correctness checking tools might not take this into account, and report data races
between different tasks that are actually synchronized.
<br><br>
<b>Note:</b> It is important to understand that this example is unlikely to show speedup
if the cell values are changed to type "float". The reason is twofold.
<ul>
<li> The smaller value type causes each Cell to be significantly smaller than a cache line,
which leads to false sharing conflicts.
<li> The time to update the cells becomes very small, and consequently the overhead of
parallel_do swamps the useful work.
</ul>
</p>
<divclass="changes">
<divclass="h3-alike">System Requirements</div>
<inputtype="checkbox">
<divclass="show-hide">
<p>
For the most up to date system requirements, see the <ahref="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a>
</p>
</div>
</div>
<divclass="changes">
<divclass="h3-alike">Files</div>
<inputtype="checkbox"checked="checked">
<divclass="show-hide">
<dl>
<dt><ahref="main.cpp">main.cpp</a>
<dd>Main program which parses command line options and runs the algorithm with different numbers of threads.
<p>For information about the minimum supported version of IDE, see <ahref="http://software.intel.com/en-us/articles/intel-threading-building-blocks-release-notes">release notes.</a></p>
</div>
</div>
<divclass="changes">
<divclass="h3-alike">Build instructions</div>
<inputtype="checkbox"checked="checked">
<divclass="show-hide">
<p>General build directions can be found <ahref="../../index.html">here</a>.</p>
<dd><i>n-of-threads</i> is the number of threads to use; a range of the form <i>low</i>[:<i>high</i>], where low and optional high are non-negative integers or 'auto' for the TBB default.<br>
<i>n-of-nodes</i> is a number of nodes in the graph. Default value is 1000.<br>
<i>n-of-traversals</i> is the number of times to evaluate the graph. Default value is 500.<br>
<i>silent</i> - no output except elapsed time.<br>
<dt>To run a short version of this example, e.g., for use with Intel® Parallel Inspector:
<dd>Build a <i>debug</i> version of the example
(see the <ahref="../../index.html">build instructions</a>).
<br>Run it with the desired number of threads and smaller number of traversals, e.g., <tt>parallel_preorder 4 1000 5</tt>.
</dl>
</div>
</div>
<br>
<ahref="../index.html">Up to parent directory</a>
<hr>
<divclass="changes">
<divclass="h3-alike">Legal Information</div>
<inputtype="checkbox">
<divclass="show-hide">
<p>
Intel and the Intel logo are trademarks of Intel Corporation in the U.S. and/or other countries.
<br>* Other names and brands may be claimed as the property of others.