Automatic Vectorization for MATLAB

Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10136)


Dynamic array-based languages such as MATLAB provide a wide range of built-in operations which can be efficiently applied to all elements of an array. Historically, MATLAB and Octave programmers have been advised to manually transform loops to equivalent “vectorized” computations in order to maximize performance. In this paper we present the techniques and tools to perform automatic vectorization, including handling for loops with calls to user-defined functions. We evaluate the technique on 9 benchmarks using two interpreters and two JIT-based platforms and show that automatic vectorization is extremely effective for the interpreters on most benchmarks, and moderately effective on some benchmarks in the JIT context.


Vectorization Promoted shape analysis MATLAB Elementwise functions Vectorizing user-defined functions 



We would like to thank the McLAB group for providing the analysis framework, Tamer. This work was supported, in part, by NSERC.


  1. 1.
    Allen, R., Kennedy, K.: Automatic translation of Fortran programs to vector form. ACM Trans. Program. Lang. Syst. 9(4), 491–542 (1987)CrossRefzbMATHGoogle Scholar
  2. 2.
    Birkbeck, N., Levesque, J., Amaral, J.N.: A dimension abstraction approach to vectorization in Matlab. In: CGO, pp. 115–130 (2007)Google Scholar
  3. 3.
    Chauhan, A., Kennedy, K.: Reducing and vectorizing procedures for telescoping languages. Int. J. Parallel Prog. 30(4), 291–315 (2002)CrossRefzbMATHGoogle Scholar
  4. 4.
    Dubrau, A.W., Hendren, L.J.: Taming MATLAB. In: OOPSLA, pp. 503–522 (2012)Google Scholar
  5. 5.
    Klemm, M., Duran, A., Tian, X., Saito, H., Caballero, D., Martorell, X.: Extending OpenMP* with vector constructs for modern multicore SIMD architectures. In: Chapman, B.M., Massaioli, F., Müller, M.S., Rorro, M. (eds.) IWOMP 2012. LNCS, vol. 7312, pp. 59–72. Springer, Heidelberg (2012). doi: 10.1007/978-3-642-30961-8_5 CrossRefGoogle Scholar
  6. 6.
    Li, X., Hendren, L.J.: Mc2FOR: A tool for automatically translating MATLAB to FORTRAN 95. In: CSMR-WCRE, pp. 234–243 (2014)Google Scholar
  7. 7.
    Maleki, S., Gao, Y., Garzarán, M.J., Wong, T., Padua, D.A.: An evaluation of vectorizing compilers. In: PACT, pp. 372–382 (2011)Google Scholar
  8. 8.
    MathWorks: MATLAB.
  9. 9.
    McLAB: The McLAB tools for compiling MATLAB (2016).
  10. 10.
    Menon, V., Pingali, K.: A case for source-level transformations in MATLAB. In: DSL, pp. 53–65 (1999)Google Scholar
  11. 11.
    Muraoka, Y.: Parallelism exposure and exploitation in programs. Ph.D. thesis, Univ. of Ill. at Urbana-Champaign, Dept. of Comp. Sci. UMI(71–21189), February 1971Google Scholar
  12. 12.
  13. 13.
    Tarjan, R.E.: Depth-first search and linear graph algorithms. SIAM J. Comput. 1(2), 146–160 (1972)MathSciNetCrossRefzbMATHGoogle Scholar
  14. 14.
    Tian, X., Saito, H., Girkar, M., Preis, S., Kozhukhov, S., Cherkasov, A.G., Nelson, C., Panchenko, N., Geva, R.: Compiling C/C++ SIMD extensions for function and loop vectorizaion on multicore-simd processors. In: IPDPS, pp. 2349–2358 (2012)Google Scholar
  15. 15.
    Wang, H., Padua, D.A., Wu, P.: Vectorization of apply to reduce interpretation overhead of R. In: OOPSLA, pp. 400–415 (2015)Google Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  1. 1.School of Computer ScienceMcGill UniversityMontréalCanada

Personalised recommendations