---
name: "psort"
section: "3"
platform: "macos"
package: "Libc"
version: "1752.120.2"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/psort/3"
---

# psort(3)

parallel sort functions

## NAME

**psort**, #ifdef UNIFDEF\_BLOCKS **psort\_b**, #endif **psort\_r** – parallel sort functions

## SYNOPSIS

**#include \<stdlib.h\>**

*void*\

**psort**(*void \*base*, *size\_t nel*, *size\_t width*, *int \*comparconst void \*, const void \**);

\#ifdef UNIFDEF\_BLOCKS

*void*\

**psort\_b**(*void \*base*, *size\_t nel*, *size\_t width*, *int ^comparconst void \*, const void \**);

\#endif

*void*\

**psort\_r**(*void \*base*, *size\_t nel*, *size\_t width*, *void \*thunk*, *int \*comparvoid \*, const void \*, const void \**);

## DESCRIPTION

The #ifdef UNIFDEF\_BLOCKS **psort**(), **psort\_b**(), #else **psort**() #endif and **psort\_r**() functions are parallel sort routines that are drop-in compatible with the corresponding **qsort**() function (see [qsort(3)](/qsort/3.md) for a description of the arguments). On multiprocessor machines, multiple threads may be created to simultaneously perform the sort calculations, resulting in an overall faster sort result. Overhead in managing the threads limits the maximum speed improvement to somewhat less that the number of processors available. For example, on a 4-processor machine, a typical sort on a large array might result in 3.2 times faster sorting than a regular **qsort**().

## RESTRICTIONS

Because of the multi-threaded nature of the sort, the comparison function is expected to perform its own synchronization that might be required for data physically *outside* the two objects passed to the comparison function. However, no synchronization is required for the two object themselves, unless some third party is also accessing those objects.

Additional memory is temporary allocated to deal with the parallel nature of the computation.

Because of the overhead of maintaining multiple threads, the **psort**() family of routines may choose to just call [qsort(3)](/qsort/3.md) when there is no advantage to parallelizing (for example, when the number of objects in the array is too small, or only one processor is available).

Like [qsort(3)](/qsort/3.md), the sort is not stable.

## RETURN VALUES

The #ifdef UNIFDEF\_BLOCKS **psort**(), **psort\_b**() #else **psort**() #endif and **psort\_r**() functions return no value.

## SEE ALSO

[qsort(3)](/qsort/3.md)

## SEE ALSO

[sort(1)](/sort/1.md), [radixsort(3)](/radixsort/3.md) Hoare, C.A.R., “Quicksort”, *The Computer Journal*, 5:1, pp. 10-15, 1962. Williams, J.W.J, “Heapsort”, *Communications of the ACM*, 7:1, pp. 347-348, 1964. Knuth, D.E., “Sorting and Searching”, *The Art of Computer Programming*, Vol. 3, pp. 114-123, 145-149, 1968. McIlroy, P.M., “Optimistic Sorting and Information Theoretic Complexity”, *Fourth Annual ACM-SIAM Symposium on Discrete Algorithms*, January 1992. Bentley, J.L. and McIlroy, M.D., “Engineering a Sort Function”, *Software--Practice and Experience*, Vol. 23(11), pp. 1249-1265, November 1993.

## STANDARDS

The **qsort**() function conforms to ISO/IEC 9899:1990 (“ISO C90”).
