News and Blog

EPSRC CDT in Next Generation Computational Modelling

Why Julia?

Jonathon introducing the topic of the day

At the end of November, Jonathon Waters delivered a seminar on the relatively new programming language Julia. Jonathon is an NGCM iPhD student at University of Southampton, being in his second year of PhD and part of Cohort 2. Julia is a new programming language, still in beta, which uses concepts from several well established programming languages in order to create an easy-to-use high performance software.

The official website describes Julia as

"a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical computing environments. It provides a sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive mathematical function library.”

As such, Julia has several key aims to achieve. Firstly, the speed of compiled languages (C/C++, Fortran) is desired. Furthermore, Julia aims at the dynamism of high-level languages, such as Ruby or Python, and the mathematical notations of MatLAB. Lastly, the general usage of Python, and the statistical ease of R are wanted.

During the seminar, Jonathon outlined the key features of Julia. Firstly, Julia is a multiple dispatch language. Compared to a single dispatch language, in which a function call always dispatches to the same function, in a multiple dispatch language, a function call may dispatch to different functions depending on the type called at run-time. This ensures that, depending on different variables gave to the function, different results will be produced.

Live demonstration of multiple dispatch

A second feature of Julia is its performance. It combines the approaches of interpreting languages (Python), transforming the instructions into bytecode on the fly, with compiled languages (C/Fortran), compiling the code into machine code and then running the resulted executable. This way, it allows Julia to produce similar speeds to C, while having a code similar to Python or Matlab. A live demo presented by Jonathon showed that Julia can solve a fractal problem approximately 100 faster than Python.

Julia performance against other languages. Credit:

Packages are another important feature of Julia. Due to its built-in package manager, it already has over 1100 registered packages. Moreover, it has the ability to interface with C, Fortran and Python packages, enabling easy reuse of existing code. Lastly, high number of packages in pure Julia are developed rapidly due to its compiler ability.

The last feature of Julia presented by Jonathon was the parallelism. In Julia, parallelisation can be implemented directly from command line by calling the desired script with a given number of cores. Another method is by sending tasks to different threads directly from code. Lastly, Julia can run loops in parallel directly, without the need for expressly designating different threads for each loop. These features were also presented by another live coding demonstration by Jonathon.

Example of loop mapping code provided by Jonathon.

While Julia presents some awesome features, it also presents several pitfalls. While not necessary a con, Julia's arrays are 1-indexed, along with Fortran array ordering. As such, depending on the code used, it might not be compatible with Python or C. Moreover, the dictionaries are hashed differently to Python dictionaries, which currently might prove slower. Thirdly, although it has quite a impressive parallelisation, and the parallel performance of Julia is ever improving, it is still often not fast enough, and might even slow down execution. Lastly, as mentioned earlier, Julia is still in beta (v0.5). Thus, future versions might not be backwards compatible, rendering present code unusable.

Several competitors to Julia already exist. Numba is a library in Python which provides a compiler for it. Also, Cython is a hybrid language, which translates Python code into C code, greatly improving the execution speed.

Overall, the attendees were presented a new language, Julia, created to overcome the programming time vs runtime problem. It has several pros, such as speed, familiarity to Python and C, multiple dispatch, parallelism, packages, and calls to other languages. Also, it has some drawbacks, such as still being in beta, poor parallelism, indexing and hashing. The seminar was a success, as Jonathon did a fantastic job introducing all the key concepts to the audience, sparking questions and discussions on performance.