2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
6 <chapter id="manual.ext.parallel_mode" xreflabel="Parallel Mode">
7 <?dbhtml filename="parallel_mode.html"?>
23 <title>Parallel Mode</title>
25 <para> The libstdc++ parallel mode is an experimental parallel
26 implementation of many algorithms the C++ Standard Library.
30 Several of the standard algorithms, for instance
31 <function>std::sort</function>, are made parallel using OpenMP
32 annotations. These parallel mode constructs and can be invoked by
33 explicit source declaration or by compiling existing sources with a
34 specific compiler flag.
38 <sect1 id="manual.ext.parallel_mode.intro" xreflabel="Intro">
41 <para>The following library components in the include
42 <filename class="headerfile">numeric</filename> are included in the parallel mode:</para>
44 <listitem><para><function>std::accumulate</function></para></listitem>
45 <listitem><para><function>std::adjacent_difference</function></para></listitem>
46 <listitem><para><function>std::inner_product</function></para></listitem>
47 <listitem><para><function>std::partial_sum</function></para></listitem>
50 <para>The following library components in the include
51 <filename class="headerfile">algorithm</filename> are included in the parallel mode:</para>
53 <listitem><para><function>std::adjacent_find</function></para></listitem>
54 <listitem><para><function>std::count</function></para></listitem>
55 <listitem><para><function>std::count_if</function></para></listitem>
56 <listitem><para><function>std::equal</function></para></listitem>
57 <listitem><para><function>std::find</function></para></listitem>
58 <listitem><para><function>std::find_if</function></para></listitem>
59 <listitem><para><function>std::find_first_of</function></para></listitem>
60 <listitem><para><function>std::for_each</function></para></listitem>
61 <listitem><para><function>std::generate</function></para></listitem>
62 <listitem><para><function>std::generate_n</function></para></listitem>
63 <listitem><para><function>std::lexicographical_compare</function></para></listitem>
64 <listitem><para><function>std::mismatch</function></para></listitem>
65 <listitem><para><function>std::search</function></para></listitem>
66 <listitem><para><function>std::search_n</function></para></listitem>
67 <listitem><para><function>std::transform</function></para></listitem>
68 <listitem><para><function>std::replace</function></para></listitem>
69 <listitem><para><function>std::replace_if</function></para></listitem>
70 <listitem><para><function>std::max_element</function></para></listitem>
71 <listitem><para><function>std::merge</function></para></listitem>
72 <listitem><para><function>std::min_element</function></para></listitem>
73 <listitem><para><function>std::nth_element</function></para></listitem>
74 <listitem><para><function>std::partial_sort</function></para></listitem>
75 <listitem><para><function>std::partition</function></para></listitem>
76 <listitem><para><function>std::random_shuffle</function></para></listitem>
77 <listitem><para><function>std::set_union</function></para></listitem>
78 <listitem><para><function>std::set_intersection</function></para></listitem>
79 <listitem><para><function>std::set_symmetric_difference</function></para></listitem>
80 <listitem><para><function>std::set_difference</function></para></listitem>
81 <listitem><para><function>std::sort</function></para></listitem>
82 <listitem><para><function>std::stable_sort</function></para></listitem>
83 <listitem><para><function>std::unique_copy</function></para></listitem>
88 <sect1 id="manual.ext.parallel_mode.semantics" xreflabel="Semantics">
89 <title>Semantics</title>
91 <para> The parallel mode STL algorithms are currently not exception-safe,
92 i.e. user-defined functors must not throw exceptions.
93 Also, the order of execution is not guaranteed for some functions, of course.
94 Therefore, user-defined functors should not have any concurrent side effects.
97 <para> Since the current GCC OpenMP implementation does not support
98 OpenMP parallel regions in concurrent threads,
99 it is not possible to call parallel STL algorithm in
100 concurrent threads, either.
101 It might work with other compilers, though.</para>
105 <sect1 id="manual.ext.parallel_mode.using" xreflabel="Using">
108 <sect2 id="parallel_mode.using.prereq_flags" xreflabel="using.prereq_flags">
109 <title>Prerequisite Compiler Flags</title>
112 Any use of parallel functionality requires additional compiler
113 and runtime support, in particular support for OpenMP. Adding this support is
114 not difficult: just compile your application with the compiler
115 flag <literal>-fopenmp</literal>. This will link
116 in <code>libgomp</code>, the GNU
117 OpenMP <ulink url="http://gcc.gnu.org/onlinedocs/libgomp/">implementation</ulink>,
118 whose presence is mandatory.
122 In addition, hardware that supports atomic operations and a compiler
123 capable of producing atomic operations is mandatory: GCC defaults to no
124 support for atomic operations on some common hardware
125 architectures. Activating atomic operations may require explicit
126 compiler flags on some targets (like sparc and x86), such
127 as <literal>-march=i686</literal>,
128 <literal>-march=native</literal> or <literal>-mcpu=v9</literal>. See
129 the GCC manual for more information.
134 <sect2 id="parallel_mode.using.parallel_mode" xreflabel="using.parallel_mode">
135 <title>Using Parallel Mode</title>
138 To use the libstdc++ parallel mode, compile your application with
139 the prerequisite flags as detailed above, and in addition
140 add <constant>-D_GLIBCXX_PARALLEL</constant>. This will convert all
141 use of the standard (sequential) algorithms to the appropriate parallel
142 equivalents. Please note that this doesn't necessarily mean that
143 everything will end up being executed in a parallel manner, but
144 rather that the heuristics and settings coded into the parallel
145 versions will be used to determine if all, some, or no algorithms
146 will be executed using parallel variants.
149 <para>Note that the <constant>_GLIBCXX_PARALLEL</constant> define may change the
150 sizes and behavior of standard class templates such as
151 <function>std::search</function>, and therefore one can only link code
152 compiled with parallel mode and code compiled without parallel mode
153 if no instantiation of a container is passed between the two
154 translation units. Parallel mode functionality has distinct linkage,
155 and cannot be confused with normal mode symbols.
159 <sect2 id="parallel_mode.using.specific" xreflabel="using.specific">
160 <title>Using Specific Parallel Components</title>
162 <para>When it is not feasible to recompile your entire application, or
163 only specific algorithms need to be parallel-aware, individual
164 parallel algorithms can be made available explicitly. These
165 parallel algorithms are functionally equivalent to the standard
166 drop-in algorithms used in parallel mode, but they are available in
167 a separate namespace as GNU extensions and may be used in programs
168 compiled with either release mode or with parallel mode.
172 <para>An example of using a parallel version
173 of <function>std::sort</function>, but no other parallel algorithms, is:
177 #include <vector>
178 #include <parallel/algorithm>
182 std::vector<int> v(100);
186 // Explicitly force a call to parallel sort.
187 __gnu_parallel::sort(v.begin(), v.end());
193 Then compile this code with the prerequisite compiler flags
194 (<literal>-fopenmp</literal> and any necessary architecture-specific
195 flags for atomic operations.)
198 <para> The following table provides the names and headers of all the
199 parallel algorithms that can be used in a similar manner:
203 <title>Parallel Algorithms</title>
204 <tgroup cols='4' align='left' colsep='1' rowsep='1'>
205 <colspec colname='c1'></colspec>
206 <colspec colname='c2'></colspec>
207 <colspec colname='c3'></colspec>
208 <colspec colname='c4'></colspec>
212 <entry>Algorithm</entry>
213 <entry>Header</entry>
214 <entry>Parallel algorithm</entry>
215 <entry>Parallel header</entry>
221 <entry><function>std::accumulate</function></entry>
222 <entry><filename class="headerfile">numeric</filename></entry>
223 <entry><function>__gnu_parallel::accumulate</function></entry>
224 <entry><filename class="headerfile">parallel/numeric</filename></entry>
227 <entry><function>std::adjacent_difference</function></entry>
228 <entry><filename class="headerfile">numeric</filename></entry>
229 <entry><function>__gnu_parallel::adjacent_difference</function></entry>
230 <entry><filename class="headerfile">parallel/numeric</filename></entry>
233 <entry><function>std::inner_product</function></entry>
234 <entry><filename class="headerfile">numeric</filename></entry>
235 <entry><function>__gnu_parallel::inner_product</function></entry>
236 <entry><filename class="headerfile">parallel/numeric</filename></entry>
239 <entry><function>std::partial_sum</function></entry>
240 <entry><filename class="headerfile">numeric</filename></entry>
241 <entry><function>__gnu_parallel::partial_sum</function></entry>
242 <entry><filename class="headerfile">parallel/numeric</filename></entry>
245 <entry><function>std::adjacent_find</function></entry>
246 <entry><filename class="headerfile">algorithm</filename></entry>
247 <entry><function>__gnu_parallel::adjacent_find</function></entry>
248 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
252 <entry><function>std::count</function></entry>
253 <entry><filename class="headerfile">algorithm</filename></entry>
254 <entry><function>__gnu_parallel::count</function></entry>
255 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
259 <entry><function>std::count_if</function></entry>
260 <entry><filename class="headerfile">algorithm</filename></entry>
261 <entry><function>__gnu_parallel::count_if</function></entry>
262 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
266 <entry><function>std::equal</function></entry>
267 <entry><filename class="headerfile">algorithm</filename></entry>
268 <entry><function>__gnu_parallel::equal</function></entry>
269 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
273 <entry><function>std::find</function></entry>
274 <entry><filename class="headerfile">algorithm</filename></entry>
275 <entry><function>__gnu_parallel::find</function></entry>
276 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
280 <entry><function>std::find_if</function></entry>
281 <entry><filename class="headerfile">algorithm</filename></entry>
282 <entry><function>__gnu_parallel::find_if</function></entry>
283 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
287 <entry><function>std::find_first_of</function></entry>
288 <entry><filename class="headerfile">algorithm</filename></entry>
289 <entry><function>__gnu_parallel::find_first_of</function></entry>
290 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
294 <entry><function>std::for_each</function></entry>
295 <entry><filename class="headerfile">algorithm</filename></entry>
296 <entry><function>__gnu_parallel::for_each</function></entry>
297 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
301 <entry><function>std::generate</function></entry>
302 <entry><filename class="headerfile">algorithm</filename></entry>
303 <entry><function>__gnu_parallel::generate</function></entry>
304 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
308 <entry><function>std::generate_n</function></entry>
309 <entry><filename class="headerfile">algorithm</filename></entry>
310 <entry><function>__gnu_parallel::generate_n</function></entry>
311 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
315 <entry><function>std::lexicographical_compare</function></entry>
316 <entry><filename class="headerfile">algorithm</filename></entry>
317 <entry><function>__gnu_parallel::lexicographical_compare</function></entry>
318 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
322 <entry><function>std::mismatch</function></entry>
323 <entry><filename class="headerfile">algorithm</filename></entry>
324 <entry><function>__gnu_parallel::mismatch</function></entry>
325 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
329 <entry><function>std::search</function></entry>
330 <entry><filename class="headerfile">algorithm</filename></entry>
331 <entry><function>__gnu_parallel::search</function></entry>
332 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
336 <entry><function>std::search_n</function></entry>
337 <entry><filename class="headerfile">algorithm</filename></entry>
338 <entry><function>__gnu_parallel::search_n</function></entry>
339 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
343 <entry><function>std::transform</function></entry>
344 <entry><filename class="headerfile">algorithm</filename></entry>
345 <entry><function>__gnu_parallel::transform</function></entry>
346 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
350 <entry><function>std::replace</function></entry>
351 <entry><filename class="headerfile">algorithm</filename></entry>
352 <entry><function>__gnu_parallel::replace</function></entry>
353 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
357 <entry><function>std::replace_if</function></entry>
358 <entry><filename class="headerfile">algorithm</filename></entry>
359 <entry><function>__gnu_parallel::replace_if</function></entry>
360 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
364 <entry><function>std::max_element</function></entry>
365 <entry><filename class="headerfile">algorithm</filename></entry>
366 <entry><function>__gnu_parallel::max_element</function></entry>
367 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
371 <entry><function>std::merge</function></entry>
372 <entry><filename class="headerfile">algorithm</filename></entry>
373 <entry><function>__gnu_parallel::merge</function></entry>
374 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
378 <entry><function>std::min_element</function></entry>
379 <entry><filename class="headerfile">algorithm</filename></entry>
380 <entry><function>__gnu_parallel::min_element</function></entry>
381 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
385 <entry><function>std::nth_element</function></entry>
386 <entry><filename class="headerfile">algorithm</filename></entry>
387 <entry><function>__gnu_parallel::nth_element</function></entry>
388 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
392 <entry><function>std::partial_sort</function></entry>
393 <entry><filename class="headerfile">algorithm</filename></entry>
394 <entry><function>__gnu_parallel::partial_sort</function></entry>
395 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
399 <entry><function>std::partition</function></entry>
400 <entry><filename class="headerfile">algorithm</filename></entry>
401 <entry><function>__gnu_parallel::partition</function></entry>
402 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
406 <entry><function>std::random_shuffle</function></entry>
407 <entry><filename class="headerfile">algorithm</filename></entry>
408 <entry><function>__gnu_parallel::random_shuffle</function></entry>
409 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
413 <entry><function>std::set_union</function></entry>
414 <entry><filename class="headerfile">algorithm</filename></entry>
415 <entry><function>__gnu_parallel::set_union</function></entry>
416 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
420 <entry><function>std::set_intersection</function></entry>
421 <entry><filename class="headerfile">algorithm</filename></entry>
422 <entry><function>__gnu_parallel::set_intersection</function></entry>
423 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
427 <entry><function>std::set_symmetric_difference</function></entry>
428 <entry><filename class="headerfile">algorithm</filename></entry>
429 <entry><function>__gnu_parallel::set_symmetric_difference</function></entry>
430 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
434 <entry><function>std::set_difference</function></entry>
435 <entry><filename class="headerfile">algorithm</filename></entry>
436 <entry><function>__gnu_parallel::set_difference</function></entry>
437 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
441 <entry><function>std::sort</function></entry>
442 <entry><filename class="headerfile">algorithm</filename></entry>
443 <entry><function>__gnu_parallel::sort</function></entry>
444 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
448 <entry><function>std::stable_sort</function></entry>
449 <entry><filename class="headerfile">algorithm</filename></entry>
450 <entry><function>__gnu_parallel::stable_sort</function></entry>
451 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
455 <entry><function>std::unique_copy</function></entry>
456 <entry><filename class="headerfile">algorithm</filename></entry>
457 <entry><function>__gnu_parallel::unique_copy</function></entry>
458 <entry><filename class="headerfile">parallel/algorithm</filename></entry>
468 <sect1 id="manual.ext.parallel_mode.design" xreflabel="Design">
469 <title>Design</title>
472 <sect2 id="manual.ext.parallel_mode.design.intro" xreflabel="Intro">
473 <title>Interface Basics</title>
476 All parallel algorithms are intended to have signatures that are
477 equivalent to the ISO C++ algorithms replaced. For instance, the
478 <function>std::adjacent_find</function> function is declared as:
483 template<typename _FIter>
485 adjacent_find(_FIter, _FIter);
490 Which means that there should be something equivalent for the parallel
491 version. Indeed, this is the case:
499 template<typename _FIter>
501 adjacent_find(_FIter, _FIter);
508 <para>But.... why the ellipses?
511 <para> The ellipses in the example above represent additional overloads
512 required for the parallel version of the function. These additional
513 overloads are used to dispatch calls from the ISO C++ function
514 signature to the appropriate parallel function (or sequential
515 function, if no parallel functions are deemed worthy), based on either
516 compile-time or run-time conditions.
519 <para> The available signature options are specific for the different
520 algorithms/algorithm classes.</para>
522 <para> The general view of overloads for the parallel algorithms look like this:
525 <listitem><para>ISO C++ signature</para></listitem>
526 <listitem><para>ISO C++ signature + sequential_tag argument</para></listitem>
527 <listitem><para>ISO C++ signature + algorithm-specific tag type
528 (several signatures)</para></listitem>
531 <para> Please note that the implementation may use additional functions
532 (designated with the <code>_switch</code> suffix) to dispatch from the
533 ISO C++ signature to the correct parallel version. Also, some of the
534 algorithms do not have support for run-time conditions, so the last
535 overload is therefore missing.
541 <sect2 id="manual.ext.parallel_mode.design.tuning" xreflabel="Tuning">
542 <title>Configuration and Tuning</title>
545 <sect3 id="parallel_mode.design.tuning.omp" xreflabel="OpenMP Environment">
546 <title>Setting up the OpenMP Environment</title>
549 Several aspects of the overall runtime environment can be manipulated
550 by standard OpenMP function calls.
554 To specify the number of threads to be used for the algorithms globally,
555 use the function <function>omp_set_num_threads</function>. An example:
559 #include <stdlib.h>
560 #include <omp.h>
564 // Explicitly set number of threads.
565 const int threads_wanted = 20;
566 omp_set_dynamic(false);
567 omp_set_num_threads(threads_wanted);
569 // Call parallel mode algorithms.
576 Some algorithms allow the number of threads being set for a particular call,
577 by augmenting the algorithm variant.
578 See the next section for further information.
582 Other parts of the runtime environment able to be manipulated include
583 nested parallelism (<function>omp_set_nested</function>), schedule kind
584 (<function>omp_set_schedule</function>), and others. See the OpenMP
585 documentation for more information.
590 <sect3 id="parallel_mode.design.tuning.compile" xreflabel="Compile Switches">
591 <title>Compile Time Switches</title>
594 To force an algorithm to execute sequentially, even though parallelism
595 is switched on in general via the macro <constant>_GLIBCXX_PARALLEL</constant>,
596 add <classname>__gnu_parallel::sequential_tag()</classname> to the end
597 of the algorithm's argument list.
605 std::sort(v.begin(), v.end(), __gnu_parallel::sequential_tag());
609 Some parallel algorithm variants can be excluded from compilation by
610 preprocessor defines. See the doxygen documentation on
611 <code>compiletime_settings.h</code> and <code>features.h</code> for details.
615 For some algorithms, the desired variant can be chosen at compile-time by
616 appending a tag object. The available options are specific to the particular
621 For the "embarrassingly parallel" algorithms, there is only one "tag object
622 type", the enum _Parallelism.
623 It takes one of the following values,
624 <code>__gnu_parallel::parallel_tag</code>,
625 <code>__gnu_parallel::balanced_tag</code>,
626 <code>__gnu_parallel::unbalanced_tag</code>,
627 <code>__gnu_parallel::omp_loop_tag</code>,
628 <code>__gnu_parallel::omp_loop_static_tag</code>.
629 This means that the actual parallelization strategy is chosen at run-time.
630 (Choosing the variants at compile-time will come soon.)
634 For the following algorithms in general, we have
635 <code>__gnu_parallel::parallel_tag</code> and
636 <code>__gnu_parallel::default_parallel_tag</code>, in addition to
637 <code>__gnu_parallel::sequential_tag</code>.
638 <code>__gnu_parallel::default_parallel_tag</code> chooses the default
639 algorithm at compiletime, as does omitting the tag.
640 <code>__gnu_parallel::parallel_tag</code> postpones the decision to runtime
642 For all tags, the number of threads desired for this call can optionally be
643 passed to the respective tag's constructor.
647 The <code>multiway_merge</code> algorithm comes with the additional choices,
648 <code>__gnu_parallel::exact_tag</code> and
649 <code>__gnu_parallel::sampling_tag</code>.
650 Exact and sampling are the two available splitting strategies.
654 For the <code>sort</code> and <code>stable_sort</code> algorithms, there are
655 several additional choices, namely
656 <code>__gnu_parallel::multiway_mergesort_tag</code>,
657 <code>__gnu_parallel::multiway_mergesort_exact_tag</code>,
658 <code>__gnu_parallel::multiway_mergesort_sampling_tag</code>,
659 <code>__gnu_parallel::quicksort_tag</code>, and
660 <code>__gnu_parallel::balanced_quicksort_tag</code>.
661 Multiway mergesort comes with the two splitting strategies for multi-way
662 merging. The quicksort options cannot be used for <code>stable_sort</code>.
667 <sect3 id="parallel_mode.design.tuning.settings" xreflabel="_Settings">
668 <title>Run Time Settings and Defaults</title>
671 The default parallelization strategy, the choice of specific algorithm
672 strategy, the minimum threshold limits for individual parallel
673 algorithms, and aspects of the underlying hardware can be specified as
674 desired via manipulation
675 of <classname>__gnu_parallel::_Settings</classname> member data.
679 First off, the choice of parallelization strategy: serial, parallel,
680 or heuristically deduced. This corresponds
681 to <code>__gnu_parallel::_Settings::algorithm_strategy</code> and is a
682 value of enum <type>__gnu_parallel::_AlgorithmStrategy</type>
684 include: <type>heuristic</type>, <type>force_sequential</type>,
685 and <type>force_parallel</type>. The default is <type>heuristic</type>.
690 Next, the sub-choices for algorithm variant, if not fixed at compile-time.
691 Specific algorithms like <function>find</function> or <function>sort</function>
692 can be implemented in multiple ways: when this is the case,
693 a <classname>__gnu_parallel::_Settings</classname> member exists to
694 pick the default strategy. For
695 example, <code>__gnu_parallel::_Settings::sort_algorithm</code> can
697 enum <type>__gnu_parallel::_SortAlgorithm</type>: <type>MWMS</type>, <type>QS</type>,
698 or <type>QS_BALANCED</type>.
702 Likewise for setting the minimal threshold for algorithm
703 parallelization. Parallelism always incurs some overhead. Thus, it is
704 not helpful to parallelize operations on very small sets of
705 data. Because of this, measures are taken to avoid parallelizing below
706 a certain, pre-determined threshold. For each algorithm, a minimum
707 problem size is encoded as a variable in the
708 active <classname>__gnu_parallel::_Settings</classname> object. This
709 threshold variable follows the following naming scheme:
710 <code>__gnu_parallel::_Settings::[algorithm]_minimal_n</code>. So,
711 for <function>fill</function>, the threshold variable
712 is <code>__gnu_parallel::_Settings::fill_minimal_n</code>,
716 Finally, hardware details like L1/L2 cache size can be hardwired
717 via <code>__gnu_parallel::_Settings::L1_cache_size</code> and friends.
724 All these configuration variables can be changed by the user, if
726 There exists one global instance of the class <classname>_Settings</classname>,
727 i. e. it is a singleton. It can be read and written by calling
728 <code>__gnu_parallel::_Settings::get</code> and
729 <code>__gnu_parallel::_Settings::set</code>, respectively.
730 Please note that the first call return a const object, so direct manipulation
732 See <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00640.html">
733 <filename class="headerfile">settings.h</filename></ulink>
734 for complete details.
738 A small example of tuning the default:
742 #include <parallel/algorithm>
743 #include <parallel/settings.h>
747 __gnu_parallel::_Settings s;
748 s.algorithm_strategy = __gnu_parallel::force_parallel;
749 __gnu_parallel::_Settings::set(s);
751 // Do work... all algorithms will be parallelized, always.
761 <sect2 id="manual.ext.parallel_mode.design.impl" xreflabel="Impl">
762 <title>Implementation Namespaces</title>
764 <para> One namespace contain versions of code that are always
765 explicitly sequential:
766 <code>__gnu_serial</code>.
769 <para> Two namespaces contain the parallel mode:
770 <code>std::__parallel</code> and <code>__gnu_parallel</code>.
773 <para> Parallel implementations of standard components, including
774 template helpers to select parallelism, are defined in <code>namespace
775 std::__parallel</code>. For instance, <function>std::transform</function> from <filename class="headerfile">algorithm</filename> has a parallel counterpart in
776 <function>std::__parallel::transform</function> from <filename class="headerfile">parallel/algorithm</filename>. In addition, these parallel
777 implementations are injected into <code>namespace
778 __gnu_parallel</code> with using declarations.
781 <para> Support and general infrastructure is in <code>namespace
782 __gnu_parallel</code>.
785 <para> More information, and an organized index of types and functions
786 related to the parallel mode on a per-namespace basis, can be found in
787 the generated source documentation.
794 <sect1 id="manual.ext.parallel_mode.test" xreflabel="Testing">
795 <title>Testing</title>
798 Both the normal conformance and regression tests and the
799 supplemental performance tests work.
803 To run the conformance and regression tests with the parallel mode
808 <userinput>make check-parallel</userinput>
812 The log and summary files for conformance testing are in the
813 <filename class="directory">testsuite/parallel</filename> directory.
817 To run the performance tests with the parallel mode active,
821 <userinput>make check-performance-parallel</userinput>
825 The result file for performance testing are in the
826 <filename class="directory">testsuite</filename> directory, in the file
827 <filename>libstdc++_performance.sum</filename>. In addition, the
828 policy-based containers have their own visualizations, which have
829 additional software dependencies than the usual bare-boned text
830 file, and can be generated by using the <code>make
831 doc-performance</code> rule in the testsuite's Makefile.
835 <bibliography id="parallel_mode.biblio" xreflabel="parallel_mode.biblio">
836 <title>Bibliography</title>
840 Parallelization of Bulk Operations for STL Dictionaries
844 <firstname>Johannes</firstname>
845 <surname>Singler</surname>
848 <firstname>Leonor</firstname>
849 <surname>Frias</surname>
859 Workshop on Highly Parallel Processing on a Chip (HPPC) 2007. (LNCS)
866 The Multi-Core Standard Template Library
870 <firstname>Johannes</firstname>
871 <surname>Singler</surname>
874 <firstname>Peter</firstname>
875 <surname>Sanders</surname>
878 <firstname>Felix</firstname>
879 <surname>Putze</surname>
889 Euro-Par 2007: Parallel Processing. (LNCS 4641)