mirror of
https://github.com/autc04/Retro68.git
synced 2024-11-30 19:53:46 +00:00
67 lines
18 KiB
HTML
67 lines
18 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|||
|
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Using</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"/><meta name="keywords" content=" C++ , library , parallel "/><meta name="keywords" content=" ISO C++ , library "/><meta name="keywords" content=" ISO C++ , runtime , library "/><link rel="home" href="../index.html" title="The GNU C++ Library"/><link rel="up" href="parallel_mode.html" title="Chapter 18. Parallel Mode"/><link rel="prev" href="bk01pt03ch18s02.html" title="Semantics"/><link rel="next" href="bk01pt03ch18s04.html" title="Design"/></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Using</th></tr><tr><td align="left"><a accesskey="p" href="bk01pt03ch18s02.html">Prev</a> </td><th width="60%" align="center">Chapter 18. Parallel Mode</th><td align="right"> <a accesskey="n" href="bk01pt03ch18s04.html">Next</a></td></tr></table><hr/></div><div class="section" title="Using"><div class="titlepage"><div><div><h2 class="title"><a id="manual.ext.parallel_mode.using"/>Using</h2></div></div></div><div class="section" title="Prerequisite Compiler Flags"><div class="titlepage"><div><div><h3 class="title"><a id="parallel_mode.using.prereq_flags"/>Prerequisite Compiler Flags</h3></div></div></div><p>
|
|||
|
Any use of parallel functionality requires additional compiler
|
|||
|
and runtime support, in particular support for OpenMP. Adding this support is
|
|||
|
not difficult: just compile your application with the compiler
|
|||
|
flag <code class="literal">-fopenmp</code>. This will link
|
|||
|
in <code class="code">libgomp</code>, the
|
|||
|
OpenMP <a class="link" href="http://gcc.gnu.org/onlinedocs/libgomp/">GNU implementation</a>,
|
|||
|
whose presence is mandatory.
|
|||
|
</p><p>
|
|||
|
In addition, hardware that supports atomic operations and a compiler
|
|||
|
capable of producing atomic operations is mandatory: GCC defaults to no
|
|||
|
support for atomic operations on some common hardware
|
|||
|
architectures. Activating atomic operations may require explicit
|
|||
|
compiler flags on some targets (like sparc and x86), such
|
|||
|
as <code class="literal">-march=i686</code>,
|
|||
|
<code class="literal">-march=native</code> or <code class="literal">-mcpu=v9</code>. See
|
|||
|
the GCC manual for more information.
|
|||
|
</p></div><div class="section" title="Using Parallel Mode"><div class="titlepage"><div><div><h3 class="title"><a id="parallel_mode.using.parallel_mode"/>Using Parallel Mode</h3></div></div></div><p>
|
|||
|
To use the libstdc++ parallel mode, compile your application with
|
|||
|
the prerequisite flags as detailed above, and in addition
|
|||
|
add <code class="constant">-D_GLIBCXX_PARALLEL</code>. This will convert all
|
|||
|
use of the standard (sequential) algorithms to the appropriate parallel
|
|||
|
equivalents. Please note that this doesn't necessarily mean that
|
|||
|
everything will end up being executed in a parallel manner, but
|
|||
|
rather that the heuristics and settings coded into the parallel
|
|||
|
versions will be used to determine if all, some, or no algorithms
|
|||
|
will be executed using parallel variants.
|
|||
|
</p><p>Note that the <code class="constant">_GLIBCXX_PARALLEL</code> define may change the
|
|||
|
sizes and behavior of standard class templates such as
|
|||
|
<code class="function">std::search</code>, and therefore one can only link code
|
|||
|
compiled with parallel mode and code compiled without parallel mode
|
|||
|
if no instantiation of a container is passed between the two
|
|||
|
translation units. Parallel mode functionality has distinct linkage,
|
|||
|
and cannot be confused with normal mode symbols.
|
|||
|
</p></div><div class="section" title="Using Specific Parallel Components"><div class="titlepage"><div><div><h3 class="title"><a id="parallel_mode.using.specific"/>Using Specific Parallel Components</h3></div></div></div><p>When it is not feasible to recompile your entire application, or
|
|||
|
only specific algorithms need to be parallel-aware, individual
|
|||
|
parallel algorithms can be made available explicitly. These
|
|||
|
parallel algorithms are functionally equivalent to the standard
|
|||
|
drop-in algorithms used in parallel mode, but they are available in
|
|||
|
a separate namespace as GNU extensions and may be used in programs
|
|||
|
compiled with either release mode or with parallel mode.
|
|||
|
</p><p>An example of using a parallel version
|
|||
|
of <code class="function">std::sort</code>, but no other parallel algorithms, is:
|
|||
|
</p><pre class="programlisting">
|
|||
|
#include <vector>
|
|||
|
#include <parallel/algorithm>
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
std::vector<int> v(100);
|
|||
|
|
|||
|
// ...
|
|||
|
|
|||
|
// Explicitly force a call to parallel sort.
|
|||
|
__gnu_parallel::sort(v.begin(), v.end());
|
|||
|
return 0;
|
|||
|
}
|
|||
|
</pre><p>
|
|||
|
Then compile this code with the prerequisite compiler flags
|
|||
|
(<code class="literal">-fopenmp</code> and any necessary architecture-specific
|
|||
|
flags for atomic operations.)
|
|||
|
</p><p> The following table provides the names and headers of all the
|
|||
|
parallel algorithms that can be used in a similar manner:
|
|||
|
</p><div class="table"><a id="id508844"/><p class="title"><strong>Table 18.1. Parallel Algorithms</strong></p><div class="table-contents"><table summary="Parallel Algorithms" border="1"><colgroup><col style="text-align: left" class="c1"/><col style="text-align: left" class="c2"/><col style="text-align: left" class="c3"/><col style="text-align: left" class="c4"/></colgroup><thead><tr><th style="text-align: left">Algorithm</th><th style="text-align: left">Header</th><th style="text-align: left">Parallel algorithm</th><th style="text-align: left">Parallel header</th></tr></thead><tbody><tr><td style="text-align: left"><code class="function">std::accumulate</code></td><td style="text-align: left"><code class="filename">numeric</code></td><td style="text-align: left"><code class="function">__gnu_parallel::accumulate</code></td><td style="text-align: left"><code class="filename">parallel/numeric</code></td></tr><tr><td style="text-align: left"><code class="function">std::adjacent_difference</code></td><td style="text-align: left"><code class="filename">numeric</code></td><td style="text-align: left"><code class="function">__gnu_parallel::adjacent_difference</code></td><td style="text-align: left"><code class="filename">parallel/numeric</code></td></tr><tr><td style="text-align: left"><code class="function">std::inner_product</code></td><td style="text-align: left"><code class="filename">numeric</code></td><td style="text-align: left"><code class="function">__gnu_parallel::inner_product</code></td><td style="text-align: left"><code class="filename">parallel/numeric</code></td></tr><tr><td style="text-align: left"><code class="function">std::partial_sum</code></td><td style="text-align: left"><code class="filename">numeric</code></td><td style="text-align: left"><code class="function">__gnu_parallel::partial_sum</code></td><td style="text-align: left"><code class="filename">parallel/numeric</code></td></tr><tr><td style="text-align: left"><code class="function">std::adjacent_find</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::adjacent_find</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::count</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::count</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::count_if</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::count_if</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::equal</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::equal</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::find</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::find</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::find_if</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class="function">__gnu_parallel::find_if</code></td><td style="text-align: left"><code class="filename">parallel/algorithm</code></td></tr><tr><td style="text-align: left"><code class="function">std::find_first_of</code></td><td style="text-align: left"><code class="filename">algorithm</code></td><td style="text-align: left"><code class
|