PPQSort offers an effective implementation of the parallel quicksort algorithm utilizing only C++20 features. It ensures ease of use with a user-friendly API and a comprehensive test suite for reliability. Its optimized performance is backed by efficient benchmarks, making it a valuable tool for developers seeking robust sorting solutions.
PPQSort, short for Parallel Pattern Quicksort, is an efficient implementation of the parallel quicksort algorithm developed exclusively using C++20 features, without relying on third-party libraries such as Intel TBB. This project combines insights from notable sorting algorithms like pdqsort, BlockQuicksort, and cpp11sort, integrating additional optimizations for enhanced performance.
PPQSort is designed as a header-only library. The complete source files are located in the include directory. Users can incorporate PPQSort into existing CMake projects effortlessly using CPM.cmake like so:
include(cmake/CPM.cmake)
CPMAddPackage(
NAME PPQSort
GITHUB_REPOSITORY GabTux/PPQSort
VERSION 1.0.4
)
target_link_libraries(YOUR_TARGET PPQSort::PPQSort)
Alternatively, FetchContent can be used, or developers can simply clone the repository and add the include directory to their linker flags.
PPQSort offers an API similar to std::sort, where execution policies can be specified:
// Run sorting in parallel
ppqsort::sort(ppqsort::execution::par, input.begin(), input.end());
// Specify the number of threads
ppqsort::sort(ppqsort::execution::par, input.begin(), input.end(), 16);
// Use custom comparator
ppqsort::sort(ppqsort::execution::par, input.begin(), input.end(), cmp);
// Enforce branchless sorting variant
ppqsort::sort(ppqsort::execution::par_force_branchless, input_str.begin(), input_str.end(), cmp);
By default, PPQSort utilizes C++ threads. For those who prefer, it can also be linked with OpenMP as a parallel backend while still enforcing the use of C++ threads by defining FORCE_CPP before including the header:
#define FORCE_CPP
#include <ppqsort.h>
// ... rest of code ...
Performance evaluations reveal that PPQSort ranks as one of the swiftest parallel sorting algorithms across diverse datasets and systems. The results showcase the algorithm's efficiency and robustness:
| Name | Algorithm | Memory Usage | Dependencies | Notable Features |
|---|---|---|---|---|
| PPQSort | Quicksort | In-place | None | Focused on performance and usability |
| GCC BQS | Quicksort | In-place | OpenMP | Allocates threads proportionally to subtask sizes |
| cpp11sort | Quicksort | In-place | None | Header-only, C++11 compliant |
| oneTBB parallel_sort | Quicksort | Out-place | oneTBB | Splits input into smaller tasks |
| ... (and others) |
PPQSort has demonstrated impressive performance on ARM architecture, such as the Fujitsu A64FX CPU with a NUMA setup. For example, benchmarks with an input size of 2 billion integers have shown:
| Algorithm | Random Time | Ascending Time | Descending Time |
|---|---|---|---|
| PPQSort | 5.84s | 1.84s | 4.55s |
| Others | ... | ... | ... |
PPQSort also plays a role in the Tracy project as a reliable sorting solution.
Further details on implementation and benchmarks can be found through the following links:
For applications necessitating a high-speed, dependency-free parallel sorting solution, PPQSort is a strong candidate.
No comments yet.
Sign in to be the first to comment.