Document Open Access Logo

Fast and Robust Vectorized In-Place Sorting of Primitive Types

Authors Mark Blacher, Joachim Giesen, Lars Kühne

Thumbnail PDF


  • Filesize: 0.99 MB
  • 16 pages

Document Identifiers

Author Details

Mark Blacher
  • Institute for Theoretical Computer Science, Friedrich Schiller Universität Jena, Germany
Joachim Giesen
  • Institute for Theoretical Computer Science, Friedrich Schiller Universität Jena, Germany
Lars Kühne
  • German Aerospace Center (DLR), Jena, Germany

Cite AsGet BibTex

Mark Blacher, Joachim Giesen, and Lars Kühne. Fast and Robust Vectorized In-Place Sorting of Primitive Types. In 19th International Symposium on Experimental Algorithms (SEA 2021). Leibniz International Proceedings in Informatics (LIPIcs), Volume 190, pp. 3:1-3:16, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2021)


Modern CPUs provide single instruction-multiple data (SIMD) instructions. SIMD instructions process several elements of a primitive data type simultaneously in fixed-size vectors. Classical sorting algorithms are not directly expressible in SIMD instructions. Accelerating sorting algorithms with SIMD instruction is therefore a creative endeavor. A promising approach for sorting with SIMD instructions is to use sorting networks for small arrays and Quicksort for large arrays. In this paper we improve vectorization techniques for sorting networks and Quicksort. In particular, we show how to use the full capacity of vector registers in sorting networks and how to make vectorized Quicksort robust with respect to different key distributions. To demonstrate the performance of our techniques we implement an in-place hybrid sorting algorithm for the data type int with AVX2 intrinsics. Our implementation is at least 30% faster than state-of-the-art high-performance sorting alternatives.

Subject Classification

ACM Subject Classification
  • Theory of computation → Sorting and searching
  • Quicksort
  • Sorting Networks
  • Vectorization
  • SIMD
  • AVX2


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Michael Axtmann, Sascha Witt, Daniel Ferizovic, and Peter Sanders. In-Place Parallel Super Scalar Samplesort (IPSSSSo). In 25th Annual European Symposium on Algorithms (ESA 2017), volume 87 of Leibniz International Proceedings in Informatics (LIPIcs), pages 9:1-9:14. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2017. URL:
  2. Jakob Andreas Bærentzen, Jens Gravesen, François Anton, and Henrik Aanæs. Guide to Computational Geometry Processing. Springer, 2012. URL:
  3. Kenneth E. Batcher. Sorting networks and their applications. In Proceedings of the April 30-May 2, 1968, Spring Joint Computer Conference, pages 307-314. ACM, 1968. URL:
  4. BLAS. Basic linear algebra subprograms. URL:
  5. Berenger Bramas. A novel hybrid quicksort algorithm vectorized using avx-512 on intel skylake. International Journal of Advanced Computer Science and Applications, 8(10), 2017. URL:
  6. Randal Bryant. Computer Systems: A Programmer’s Perspective. Pearson, 3rd edition, 2016. Google Scholar
  7. Shi-Kuo Chang. Data Structures and Algorithms. World Scientific, 2003. Google Scholar
  8. Jatin Chhugani, Anthony D. Nguyen, Victor W. Lee, William Macy, Mostafa Hagog, Yen-Kuang Chen, Akram Baransi, Sanjeev Kumar, and Pradeep Dubey. Efficient implementation of sorting on multi-core simd cpu architecture. Proceedings of the VLDB Endowment, 1(2):1313-1324, 2008. URL:
  9. Michael Codish, Luís Cruz-Filipe, Thorsten Ehlers, Mike Müller, and Peter Schneider-Kamp. Sorting networks: To the end and back again. Journal of Computer and System Sciences, 2016. URL:
  10. Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms. MIT press, 3rd edition, 2009. Google Scholar
  11. Amjad M. Daoud, Hussein Abdel-jaber, and Jafar Ababneh. Efficient non-quadratic quick sort (nqquicksort). In Ezendu Ariwa and Eyas El-Qawasmeh, editors, Digital Enterprise and Information Systems, pages 667-675. Springer, 2011. Google Scholar
  12. Developer Zone. Intelsuperscript registered Software Developer Zone, 2008. URL:
  13. Jay Devore and Kenneth Berk. Modern Mathematical Statistics With Applications. Springer, 2012. Google Scholar
  14. Jack J. Dongarra, Fred G. Gustavson, and Alan H. Karp. Implementing linear algebra algorithms for dense matrices on a vector pipeline machine. SIAM Review, 26(1):91-112, 1984. URL:
  15. Michael Griebel. Numerical Simulation in Molecular Dynamics: Numerics, Algorithms, Parallelization, Applications. Springer, 2007. Google Scholar
  16. Shay Gueron and Vlad Krasnov. Fast quicksort implementation using avx instructions. The Computer Journal, 59(1):83-90, 2016. URL:
  17. David R. Helman, David A. Bader, and Joseph JáJá. A randomized parallel sorting algorithm with an experimental study. Journal of Parallel and Distributed Computing, 52(1):1-23, 1998. URL:
  18. Michael Herf. Radix tricks, 2001. URL:
  19. Hiroshi Inoue, Takao Moriyama, Hideaki Komatsu, and Toshio Nakatani. Aa-sort: A new parallel sorting algorithm for multi-core simd processors. In 16th International Conference on Parallel Architecture and Compilation Techniques (PACT 2007), pages 189-198, 2007. URL:
  20. Hiroshi Inoue and Kenjiro Taura. Simd- and cache-friendly algorithm for sorting an array of structures. Proceedings of the VLDB Endowment, 8(11):1274-1285, 2015. URL:
  21. Intel Corporation. Developer Reference for Intelsuperscript registered Integrated Performance Primitives. URL:
  22. Intel Corporation. Intelsuperscript registered 64 and IA-32 Architectures Software Developer’s Manual, 2016. Google Scholar
  23. Intel Corporation. Intelsuperscriptregistered Integrated Performance Primitives Cryptography: Developer Guide, 2020. URL:
  24. Intrinsics Guide. Intel intrinsics guide. URL:
  25. Adrian Kaehler and Gary Bradski. Learning OpenCV 3: Computer Vision in C++ With the OpenCV Library. O'Reilly Media, 2016. Google Scholar
  26. Ronald Kneusel. Random Numbers and Computers. Springer, 1st edition, 2018. Google Scholar
  27. Donald E. Knuth. The Art of Computer Programming: Volume 3: Sorting and Searching. Addison-Wesley, 2nd edition, 1998. Google Scholar
  28. Bernhard Korte and Jens Vygen. Combinatorial Optimization: Theory and Algorithms. Springer, 2006. Google Scholar
  29. Ibrahim Küçük. Astrophysics. IntechOpen, 2012. Google Scholar
  30. Tapio Lahdenmäki and Michael Leach. Relational Database Index Design and the Optimizers. John Wiley & Sons, 2005. Google Scholar
  31. Stewart A. Levin. A fully vectorized quicksort. Parallel Computing, 16:369-373, 1990. URL:
  32. Peng Li, David J. Lilja, Weikang Qian, Kia Bazargan, and Marc D. Riedel. Computation on stochastic bit streams digital image processing case studies. IEEE Transactions on Very Large Scale Integration (VLSI) Systems, 22(3):449-462, 2014. URL:
  33. Michal Ozery-Flato and Ron Shamir. Sorting by translocations via reversals theory. In Comparative Genomics, pages 87-98. Springer, 2006. URL:
  34. Ian Parberry. The pairwise sorting network. Parallel Processing Letters, 2:205-211, 1992. URL:
  35. Steven Ross. Boost.sort. URL:
  36. Robert Sedgewick and Kevin Wayne. Algorithms. Addison-Wesley, 4th edition, 2011. Google Scholar
  37. Howard Jay Siegel. The universality of various types of simd machine interconnection networks. SIGARCH Comput. Archit. News, 5(7):70-79, 1977. URL:
  38. Harold S. Stone. Sorting on star. IEEE Transactions on Software Engineering, SE-4(2):138-146, 1978. URL:
  39. Martin Weisser. Essential Programming for Linguistics. Edinburgh University Press, 2009. Google Scholar
  40. Zekun Yin, Tianyu Zhang, André Müller, Hui Liu, Yanjie Wei, Bertil Schmidt, and Weiguo Liu. Efficient parallel sort on avx-512-based multi-core and many-core architectures. In 2019 IEEE 21st International Conference on High Performance Computing and Communications; IEEE 17th International Conference on Smart City; IEEE 5th International Conference on Data Science and Systems (HPCC/SmartCity/DSS), pages 168-176. IEEE, 2019. URL:
  41. Marco Zagha and Guy E. Blelloch. Radix sort for vector multiprocessors. In Proceedings of the 1991 ACM/IEEE conference on Supercomputing, pages 712-721. ACM, 1991. URL:
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail