On this page we’ll see how to use Julia on the taki cluster. Before proceeding, make sure you’ve read the How To Run tutorial first. Julia is a recent full-featured compiled language. It can be used interactively or through scripting. We have version 1.6.2 installed on taki. Before launching Julia, one must load the following module:
[dkelly7@taki-usr1 ~]$ module load Julia/1.6.2-linux-x86_64
If everything goes well, you should not see any error upon loading the module. If you plan to use Julia frequently on taki, you might want to add the above command to your login profile bash script. Once the module julia/1.6.2 is loaded, Julia can be launched by typing julia
[dkelly7@taki-usr1 ~]$ julia _ _ _ _(_)_ | Documentation: http://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.6.2 (2021-07-14) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ |
Exiting Julia is easy: type exit() at the command prompt
julia> exit() [dkelly7@taki ~]$
The directory from which Julia is launched becomes the current working directory, which can retrieved by the command pwd(). To change the current working directory use the cd() command.
julia> pwd() "/home/dkelly7" julia> cd("plot/") julia> pwd() "/home/dkelly7/plot"
Functions in Julia can be executed in two ways: a. by typing at the command prompt, for example, as shown above, and b. by calling the functions, possibly along with other programming language constructs like an if conditional, for loops etc., in a file (with any extension), which can be run using the include() command. For example, below we call the println function to print “hello world” on the screen. We also show how to run a file with a set of commands, and instructions – in this case a hello_world.jl file containing the command “println(“hello world”)”. Note that since Julia is a compiled language, when we execute the file with the include() command, the two steps of compilation, and execution happen behind the scene. In other words, unlike C, we do not have to compile Julia code first, and then run an executable.
julia> println("hello world") hello world julia> include("hello_world.jl") hello world
Julia code can be run in a non-interactive fashion by calling the command “julia” with the name of a file with Julia code as the argument.
[dkelly7@taki-usr1 ~]$ julia hello_world.jl Hello world!
Example batch script
We’ll write a simple Julia program that says “Hello world!”, and prints the factorial of 10.
x = factorial(10) println("Hello world! 10! = ", x)
Julia code can be run using a slurm batch script by including the “julia” command with the file name of the code as the argument as shown below.
Parallel programming using MPI
Julia has an interface package called MPI that implements the Message Passing Interface (MPI) protocol.
In this section we will look at a few examples to illustrate a few features of the package. Let us begin with a Greetings example where a single program is executed on multiple processes, and each process returns a hello message.
The number of processes on which the program is run is specified in as slurm file as shown below. Notice two things in the slurm file. We use the –mem option and set it to MaxMemPerNode. Since Julia is a compiled language, we need to provide enough memory for the runtime to load on each process. Setting the memory per node to the maximum allowed will ensure that enough memory is made available. Also, notice that the module julia/1.6.2 is loaded before executing the program on the processes. This ensures that Julia executable is made available on all the allocated processes.
The above slurm script can be scheduled using the sbatch command as
[dkelly7@taki-usr1 plot]$ sbatch helloworld_parallel.slurm Submitted batch job 4124623
If the program runs successfully, slurm.err file should be empty, and slurm.out should have contents similar to:
Hello! I am Hello! I am Hello! I am Hello! I am Hello! I am Hello! I am 6 of 8 Hello! I am 0 of 8 5 of 8 4 of 8 3 of 8 1 of 8 Hello! I am 2 of 8 7 of 8
The garbled output above is the result of the racing of each process to output their messages to slurm.out.