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
|
<!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_sort Template Function">
<meta name="DC.subject" content="parallel_sort Template Function">
<meta name="keywords" content="parallel_sort Template Function">
<meta name="DC.Relation" scheme="URI" content="../../reference/algorithms.htm">
<meta name="DC.Relation" scheme="URI" content="../task_scheduler/task_scheduler_init_cls.htm">
<meta name="DC.Format" content="XHTML">
<meta name="DC.Identifier" content="parallel_sort_func">
<meta name="DC.Language" content="en-US">
<link rel="stylesheet" type="text/css" href="../../intel_css_styles.css">
<title>parallel_sort 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_sort_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_sort_func"><!-- --></a>
<h1 class="topictitle1">parallel_sort Template Function</h1>
<div>
<div class="section"><h2 class="sectiontitle">Summary</h2> Sort a sequence. </div>
<div class="section"><h2 class="sectiontitle">Header</h2>
<pre>#include "tbb/parallel_sort.h"</pre>
</div>
<div class="section"><h2 class="sectiontitle">Syntax</h2>
<pre>template<typename RandomAccessIterator>
void parallel_sort(RandomAccessIterator begin, RandomAccessIterator end);
template<typename RandomAccessIterator, typename Compare>
void parallel_sort(RandomAccessIterator begin,
RandomAccessIterator end,
const Compare& comp );
</pre></div>
<div class="section"><h2 class="sectiontitle">Description</h2> <p> Performs an <em>unstable</em> sort of sequence [<em>begin1</em>, <em>end1</em>). An unstable sort
might not preserve the relative ordering of elements with equal keys. The sort is deterministic;
sorting the same sequence will produce the same result each time. The requirements on the
iterator and sequence are the same as for<samp class="codeph"> std::sort</samp> . Specifically,
<samp class="codeph">RandomAccessIterator</samp> must be a random access iterator, and its value type
<em>T</em> must model the requirements in the table below.</p>
<div class="tablenoborder"><table cellpadding="4" summary="" width="100%" frame="hsides" border="1" rules="all"><caption><span class="tablecap">Requirements on Value Type T of RandomAccessIterator
for parallel_sort</span></caption>
<thead align="left">
<tr>
<th class="cellrowborder" valign="top" id="d8660e85">
<p>Pseudo-Signature
</p>
</th>
<th class="row-nocellborder" valign="top" id="d8660e91">
<p>Semantics
</p>
</th>
</tr>
</thead>
<tbody>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d8660e85 ">
<p><samp class="codeph"> void swap( T& x, T& y )</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d8660e91 ">
<p> Swap <samp class="codeph">x</samp> and <samp class="codeph">y</samp> .</p>
</td>
</tr>
<tr valign="top">
<td class="cellrowborder" valign="top" headers="d8660e85 ">
<p><samp class="codeph"> bool Compare::operator()(
const T& x, const T& y
)</samp>
</p>
</td>
<td class="row-nocellborder" valign="top" headers="d8660e91 ">
<p> True if <samp class="codeph">x</samp> comes before <samp class="codeph">y</samp> ; false
otherwise.</p>
</td>
</tr>
</tbody>
</table>
</div>
<p>A call <samp class="codeph">parallel_sort(i,j,comp)</samp> sorts the <samp class="codeph">sequence [i,j)</samp> using
the argument <samp class="codeph">comp</samp> to determine relative orderings. If
<samp class="codeph">comp(x,y)</samp> returns <samp class="codeph">true</samp> then <samp class="codeph">x</samp> appears before <samp class="codeph">y</samp> in the sorted
sequence.</p>
<p>A call <samp class="codeph">parallel_sort(i,j)</samp> is equivalent to
<samp class="codeph">parallel_sort(i,j,std::less<T>)</samp>.</p>
<p> <strong>Complexity</strong></p>
<p><samp class="codeph"> parallel_sort</samp> is comparison sort with an average time complexity of <em>O(N
log (N))</em>, where <em>N</em> is the number of elements in the sequence. When
worker threads are available, <samp class="codeph">parallel_sort</samp> creates subtasks that may be
executed concurrently, leading to improved execution times.</p>
<p><strong>Example</strong></p>
<p>The following example shows two sorts. The sort of array <samp class="codeph">a</samp> uses the default
comparison, which sorts in ascending order. The sort of array <samp class="codeph">b</samp> sorts in descending order by
using <samp class="codeph">std::greater<float></samp> for comparison.</p>
<pre>#include "tbb/parallel_sort.h"
#include <math.h>
using namespace tbb;
const int N = 100000;
float a[N];
float b[N];
void SortExample() {
for( int i = 0; i < N; i++ ) {
a[i] = sin((double)i);
b[i] = cos((double)i);
}
parallel_sort(a, a + N);
parallel_sort(b, b + N, std::greater<float>());
}
</pre></div>
</div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="../../reference/algorithms.htm">Algorithms</a></div>
</div>
<div class="See Also">
<h2>See Also</h2>
<div class="linklist">
<div><a href="../task_scheduler/task_scheduler_init_cls.htm">task_scheduler_init
class</a></div></div>
</div>
</body>
</html>
|