1 .\" Copyright (c) 1990, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93
33 .\" $FreeBSD: src/lib/libc/stdlib/qsort.3,v 1.17 2007/01/09 00:28:10 imp Exp $
44 .Nd parallel sort functions
52 .Fa "int \*[lp]*compar\*[rp]\*[lp]const void *, const void *\*[rp]"
60 .Fa "int \*[lp]^compar\*[rp]\*[lp]const void *, const void *\*[rp]"
69 .Fa "int \*[lp]*compar\*[rp]\*[lp]void *, const void *, const void *\*[rp]"
81 functions are parallel sort routines that are drop-in compatible with the
86 for a description of the arguments).
87 On multiprocessor machines, multiple threads may be created to simultaneously
88 perform the sort calculations, resulting in an overall faster sort result.
89 Overhead in managing the threads limits the maximum speed improvement to
90 somewhat less that the number of processors available.
91 For example, on a 4-processor machine, a typical sort on a large array might
92 result in 3.2 times faster sorting than a regular
95 Because of the multi-threaded nature of the sort, the comparison function
96 is expected to perform its own synchronization that might be required for
99 the two objects passed to the comparison function.
100 However, no synchronization is required for the two
101 object themselves, unless some third party is also accessing those objects.
103 Additional memory is temporary allocated to deal with the parallel nature
106 Because of the overhead of maintaining multiple threads, the
108 family of routines may choose to just call
110 when there is no advantage to parallelizing (for example, when the number of
111 objects in the array is too small, or only one processor is available).
115 the sort is not stable.
118 #ifdef UNIFDEF_BLOCKS
137 .%J "The Computer Journal"
145 .%J "Communications of the ACM"
152 .%B "The Art of Computer Programming"
154 .%T "Sorting and Searching"
155 .%P pp. 114-123, 145-149
159 .%T "Optimistic Sorting and Information Theoretic Complexity"
160 .%J "Fourth Annual ACM-SIAM Symposium on Discrete Algorithms"
166 .%T "Engineering a Sort Function"
167 .%J "Software--Practice and Experience"