Abstract
This paper presents an application of the theory of sorting networks to facilitate the synthesis of optimized general-purpose sorting libraries. Standard sorting libraries are often based on combinations of the classic Quicksort algorithm with insertion sort applied as base case for small, fixed, numbers of inputs. Unrolling the code for the base case by ignoring loop conditions eliminates branching, resulting in code equivalent to a sorting network. This enables further program transformations based on sorting network optimizations, and eventually the synthesis of code from sorting networks. We show that, if considering the number of comparisons and swaps, the theory predicts no real advantage of this approach. However, significant speed-ups are obtained when taking advantage of instruction level parallelism and non-branching conditional assignment instructions, both of which are common in modern CPU architectures. We provide empirical evidence that using code synthesized from efficient sorting networks as the base case for Quicksort libraries results in significant real-world speed-ups.
Supported by the Israel Science Foundation, grant 182/13 and by the Danish Council for Independent Research, Natural Sciences.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
- 2.
- 3.
References
Bundala, D., Závodný, J.: Optimal sorting networks. In: Dediu, A.-H., Martín-Vide, C., Sierra-Rodríguez, J.-L., Truthe, B. (eds.) LATA 2014. LNCS, vol. 8370, pp. 236–247. Springer, Heidelberg (2014)
Codish, M., Cruz-Filipe, L., Frank, M., Schneider-Kamp, P.: Twenty-five comparators is optimal when sorting nine inputs (and twenty-nine for ten). In: ICTAI 2014, pp. 186–193. IEEE, December 2014
Codish, M., Cruz-Filipe, L., Schneider-Kamp, P.: The quest for optimal sorting networks: efficient generation of two-layer prefixes. In: Winkler, F., Negru, V., Ida, T., Jebelan, T., Petcu, D., Watt, S.M., Zaharie, D., (eds.) SYNASC 2014, pp. 359–366. IEEE (2015)
Codish, M., Cruz-Filipe, L., Schneider-Kamp, P.: Sorting networks: the end game. In: Dediu, A.-H., Formenti, E., Martín-Vide, C., Truthe, B. (eds.) LATA 2015. LNCS, vol. 8977, pp. 664–675. Springer, Heidelberg (2015)
Ehlers, T., Müller, M.: New bounds on optimal sorting networks. In: Beckmann, A., Mitrana, V., Soskova, M. (eds.) CiE 2015. LNCS, vol. 9136, pp. 167–176. Springer, Heidelberg (2015)
Fisher, J.A., Faraboschi, P., Young, C.: Embedded Computing: A VLIW Approach to Architecture, Compilers, and Tools. Morgan Kaufman, San Francisco (2005)
Furtak, T., Amaral, J.N., Niewiadomski, R.: Using SIMD registers and instructions to enable instruction-level parallelism in sorting algorithms. In: SPAA 2007, pp. 348–357. ACM (2007)
Hoare, C.A.R.: Quicksort. Comput. J. 5(1), 10–15 (1962)
Knuth, D.E.: The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley, New York (1973)
Lopez, B., Cruz-Cortes, N.: On the usage of sorting networks to big data. In: Arabnia, H.R., Yang, M.Q., Jandieri, G., Park, J.J., Solo, A.M.G., Tinetti, F.G., (eds.) Advances in Big Data Analytics: The 2014 WorldComp International Conference Proceedings. Mercury Learning and Information (2014)
Parberry, I.: A computer-assisted optimal depth lower bound for nine-input sorting networks. Math. Syst. Theor. 24(2), 101–116 (1991)
Sedgewick, R.: The analysis of quicksort programs. Acta Inf. 7, 327–355 (1977)
Sedgewick, R., Flajolet, P.: An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman, New York (1996)
Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley, Reading (2011)
Silc, J., Robic, B., Ungerer, T.: Processor Architecture: From Dataflow to Superscalar and Beyond. Springer, New York (1999)
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2015 Springer International Publishing Switzerland
About this paper
Cite this paper
Codish, M., Cruz-Filipe, L., Nebel, M., Schneider-Kamp, P. (2015). Applying Sorting Networks to Synthesize Optimized Sorting Libraries. In: Falaschi, M. (eds) Logic-Based Program Synthesis and Transformation. LOPSTR 2015. Lecture Notes in Computer Science(), vol 9527. Springer, Cham. https://doi.org/10.1007/978-3-319-27436-2_8
Download citation
DOI: https://doi.org/10.1007/978-3-319-27436-2_8
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-27435-5
Online ISBN: 978-3-319-27436-2
eBook Packages: Computer ScienceComputer Science (R0)