Advertisement

Applying Sorting Networks to Synthesize Optimized Sorting Libraries

  • Michael Codish
  • Luís Cruz-FilipeEmail author
  • Markus Nebel
  • Peter Schneider-Kamp
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 9527)

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.

Keywords

Base Case Sorting Algorithm Program Transformation Sorting Network Branch Prediction 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

References

  1. 1.
    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) CrossRefGoogle Scholar
  2. 2.
    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 2014Google Scholar
  3. 3.
    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)Google Scholar
  4. 4.
    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) Google Scholar
  5. 5.
    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) CrossRefGoogle Scholar
  6. 6.
    Fisher, J.A., Faraboschi, P., Young, C.: Embedded Computing: A VLIW Approach to Architecture, Compilers, and Tools. Morgan Kaufman, San Francisco (2005) zbMATHGoogle Scholar
  7. 7.
    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)Google Scholar
  8. 8.
    Hoare, C.A.R.: Quicksort. Comput. J. 5(1), 10–15 (1962)MathSciNetCrossRefzbMATHGoogle Scholar
  9. 9.
    Knuth, D.E.: The Art of Computer Programming, Volume III: Sorting and Searching. Addison-Wesley, New York (1973) zbMATHGoogle Scholar
  10. 10.
    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)Google Scholar
  11. 11.
    Parberry, I.: A computer-assisted optimal depth lower bound for nine-input sorting networks. Math. Syst. Theor. 24(2), 101–116 (1991)MathSciNetCrossRefzbMATHGoogle Scholar
  12. 12.
    Sedgewick, R.: The analysis of quicksort programs. Acta Inf. 7, 327–355 (1977)MathSciNetCrossRefzbMATHGoogle Scholar
  13. 13.
    Sedgewick, R., Flajolet, P.: An Introduction to the Analysis of Algorithms. Addison-Wesley-Longman, New York (1996) zbMATHGoogle Scholar
  14. 14.
    Sedgewick, R., Wayne, K.: Algorithms, 4th edn. Addison-Wesley, Reading (2011) Google Scholar
  15. 15.
    Silc, J., Robic, B., Ungerer, T.: Processor Architecture: From Dataflow to Superscalar and Beyond. Springer, New York (1999) CrossRefzbMATHGoogle Scholar

Copyright information

© Springer International Publishing Switzerland 2015

Authors and Affiliations

  • Michael Codish
    • 1
  • Luís Cruz-Filipe
    • 2
    Email author
  • Markus Nebel
    • 2
  • Peter Schneider-Kamp
    • 2
  1. 1.Department of Computer ScienceBen-Gurion University of the NegevBeer-ShevaIsrael
  2. 2.Department Mathematics and Computer ScienceUniversity of Southern DenmarkOdenseDenmark

Personalised recommendations