Introduction
On this page we’ll see how to use Julia on the maya 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 0.4.6 installed on maya. Before launching Julia, one must load the following module:
[saiku1@maya-usr1 ~]$ module load julia/0.4.6
If everything goes well, you should not see any error upon loading the module. If you plan to use Julia frequently on maya, you might want to add the above command to your login profile bash script. Once the module julia/0.4.6 is loaded, Julia can be launched by typing julia
[saiku1@maya-usr1 ~]$ julia _ _ _ _(_)_ | A fresh approach to technical computing (_) | (_) (_) | Documentation: http://docs.julialang.org _ _ _| |_ __ _ | Type "?help" for help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 0.4.6 (2016-06-19 17:16 UTC) _/ |\__'_|_|_|\__'_| | Official http://julialang.org/ release |__/ | x86_64-unknown-linux-gnu
Exiting Julia is easy: type quit() at the command prompt
julia> quit() [saiku1@maya-usr1 ~]$
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> julia> pwd() "/home/saiku1" julia> cd("julia/") julia> pwd() "/home/saiku1/julia"
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.
[saiku1@maya-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.
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.
Download: run.slurm
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.
Download: hello_parallel.jl
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/0.4.6 is loaded before executing the program on the processes. This ensures that Julia executable is made available on all the allocated processes.
Download: hello_parallel.slurm
The above slurm script can be scheduled using the sbatch command as
[saiku1@maya-usr1 parallel]$ sbatch hello_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.