Preface
Course material for a ~4+4 hours introductory course to Julia. Topics: Parallel Programming and further topics on high performance computing
Citation
In case you want to refer to this lecture material, use the following BibTex snippet:
@misc{perftop2023,
doi = {10.5281/zenodo.10514499},
url = {https://kandolfp.github.io/ws23_ulg_vu_ama_performance/},
author = {Ehrensperger, Gregor and Kandolf, Peter},
keywords = {FOS: Mathematics},
language = {en},
title = {ULG Data Science - WS23 971007 VU Advanced Methods and its Applications - Performance topics},
year = {2024},
copyright = {Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International}
}
or use CITATION.cff.
Getting started with Julia
Julia is a free and open source scientific programming language with a vast ecosystem of libraries that aim towards scientific computing. Visit julialang.org for the download, documentation, learning materials and much more. Julia manages to allow the best of two worlds, high-level interpreter and low-level compiler language. It offers the high performance of compiled languages like C or Fortran by still bringing in the simplicity of dynamic languages like Python or R. Julia recently entered its teens and for this occasion a blog post was published with the title Why We Use Julia, 10 Years Later as a follow up to the Why We Created Julia. Both entries are a good read and give you an insight into the language and its creators.
In this workshop we are going to take a look at Julia for multi processor programming, if you are looking for a more basic start we recommend Scientific Coding with Julia.
Acknowledgment
The foundation of these notes is based on parts of our Julia Workshop which was given at the Doctoral College Computational Interdisciplinary Modelling (DK CIM). This lecture will dive a bit deeper than we did in the section Parallel Computing.
Some general words on the organization of this workshop
You will find code blocks that you can copy if necessary (top right corner copy
). Furthermore, if we think something is very important we will highlight it with a box:
We also have various environments with different color coding that usually are collapsed to not hinder the reading process:
Examples are green
Exercises are blue
<pre> </pre>
That is about all we wanted to let you know, so let us get into it.
Setup
Follow the setup in this section to install everything that is required to get started.
Julia
To install Julia on your system please download the latest stable binary from Setup Download and follow the instructions on Setup Julia for the installation.
Under the above link you will also find instructions on how to uninstall Julia, even though we are quite sure you will not want to do it ;).
Alternatively you can also use juliaup to install and use Julia. This handy little gadget allows for automatic updates as well as easy parallel installation of and switching between different Julia versions.
Additional information for Linux:
Some distributions allow for Julia to be installed via the package manager or software center. Note that very often this is an old version so this method is not recommended.
A very convenient way to manage your Julia installation is juliaup. To install this tool, simply call the following command from your terminal:
curl -fsSL https://install.julialang.org | sh
Once installed, simply reopen your terminal and call juliaup add 1.9.4
to add the very version used for this course. In case you installed Julia just for this course, you could then set
juliaup default 1.9.4
to pin your default version to 1.9.4
whenever you start julia
. Alternatively you can launch this specific version by calling julia +1.9.4
.
Visual Studio Code
Installing Visual Studio Code is optional since one can use any editor for programming in Julia but Visual Studio Code (+plugin) is the most common "Julia IDE". For example JuliaEditorSupport has plugins for some alternative editors.
Follow the instructions on https://code.visualstudio.com/ to install Visual Studio Code.
Visual Studio Code, also commonly referred to as VS Code, is a fully-fledged interactive development environment (IDE), complete with code highlighting, autocomplete, debugger, Git integration and much more. In order to make VS Code fully compatible with Julia we need to install the Julia extension.
Installing the Julia extension for VS Code
Follow the instructions on VS Code Julia extension to install and configure the extension. You can find the basic instructions from above here as well.
If you run into difficulties with VS Code in connection with Julia, the documentation of the Julia extension is an excellent source for help.
Julia and VS Code
There is no better resource than https://www.julia-vscode.org to explain how to program in Julia with VS Code. The website also provides an interactive view of some of the following concepts.
On the left you have the navigational panel where you can switch between context of the viewer.
Specifically you will need the Explorer and Julia.
Right next to it you get additional information with regards to the current context.
For example you will see files, when you are in Explorer or you see your Workspace, Documentation, and Plot Navigation in the Julia context.
When opening a Julia file (ending in
.jl
) (double click in the Explorer - single click only gives you a quick view and the file will not stay open if you click another file) you have syntax highlighting and autocomplete right away.To run a Julia program, click the small arrow on the top left or
Ctrl+F5
if you prefer keyboard shortcuts.Both will run the code in the Julia REPL.
You will see the output on the bottom.
With these short basics and https://www.julia-vscode.org you are good to go for the lecture. You can also find a list of keybindings once you are more familiar with the IDE and never want to get your hands off the keyboard.
In VS Code you can always type CTRL + SHIFT + P
to get access to the prompt and execute commands within VS Code.