Julia and Packages
By default, Julia Programming Language is available via module.
Load & list available modules
module use /applis/PSMN/debian11/E5/modules/all
module avail
Load the version of Julia you want to work with
module load Julia/1.9.4-linux-x86_64
If you want to work with another particular version of Julia (See below section JILL), you will have to install it in your $HOME
or team storage (see Where to store files?).
For the rest of this documentation, replace mylogin
by your login as provided by PSMN.
Project Management with Julia
You can manage packages within a project environment (similar to a python venv)
Create a directory where you want to store your project
mylogin@c8220node1:~/$ mkdir -p ~/julia/julia194 && cd ~/julia/julia194
Enter Project Manager
Type ]
key:
mylogin@c8220node1:~/julia/julia194$ julia
mylogin@c8220node1:~/julia/julia194$ ]
Activate a new project
(@v1.9) pkg> activate tutorial
Activating new project at `~/julia/julia194/tutorial`
(tutorial) pkg> status
Status `~/julia/julia194/tutorial/Project.toml` (empty project)
Install a package inside Julia project environment
For example, Roots
:
(tutorial) pkg> add Roots
You can now use Roots
in your project environment
(tutorial) pkg> status
Status `~/julia/julia194/tutorial/Project.toml`
[f2b01f46] Roots v2.1.5
Verify the dependencies of your project
mylogin@x5570comp1:~/julia/julia194/tutorial$ ls
Manifest.toml Project.toml
mylogin@x5570comp1:~/julia/julia194/tutorial$ less Project.toml
Exit (deactivate) a project environment
(tutorial) pkg> activate
Activating project at `~/.julia/environments/v1.9`
(@v1.9) pkg>
Exit package manager
Type backspace
key.
Exit Julia
julia> exit()
Alternative Project Management with Julia
This method will create a project folder and source folder.
Enter Project Manager
Type ]
key:
mylogin@c8220node1:~/julia/julia194$ julia
mylogin@c8220node1:~/julia/julia194$ ]
Generate new project
(@v1.9) pkg> generate tutorial2
Generating project tutorial2:
tutorial2/Project.toml
tutorial2/src/tutorial2.jl
mylogin@c8220node1: ls ~/julia/julia194/tutorial2
Project.toml src
Exit package manager
Type backspace
key.
Exit Julia
julia> exit()
Two files were created:
~/julia/julia194/tutorial2/Project.toml
specifies the dependencies.
~/julia/julia194/tutorial2/src/tutorial2.jl
is a placeholder for your code.
Activate Existing Project
mylogin@c8220node1:~$ cd ~/julia/julia194/tutorial2
mylogin@c8220node1:~/julia/julia194/tutorial2$ julia --project=.
Add Packages to project
julia> ]
(tutorial2) pkg> add Roots
(tutorial2) pkg> status
Project tutorial2 v0.1.0
Status `~/julia/julia194/tutorial2/Project.toml`
[f2b01f46] Roots v2.1.5
You can now use the package Roots
in your project environment.
Multiple Versions of Julia with JILL
The most simple way to manage and work with multiple versions of Julia
in your $HOME
is to install the python package, JILL.
Install JILL
mylogin@c8220node1:~$ python3.9 -m pip install jill
mylogin@c8220node1:~$ export PATH="/home/mylogin/.local/bin:$PATH"
If you wish to make JILL permanently available in your environment, add the export line (export PATH="/home/mylogin/.local/bin:$PATH"
) to the end of your ~/.bashrc
file.
Install latest version of Julia with Jill
mylogin@c8220node1:~$ jill list
mylogin@c8220node1:~$ jill install
Launch Julia
mylogin@c8220node1:~$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.4 (2024-06-04)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia>
Install specific Julia version with JILL
mylogin@c8220node1:~$ jill install 1.6.2
mylogin@c8220node1:~$ jill list
Found 4 julia(s) in /home/mylogin/.local/bin:
julia --> 1.10.4
julia-1 --> 1.10.4
julia-1.6 --> 1.6.2
julia-1.10 --> 1.10.4
Launch specific Julia version with JILL
mylogin@c8220node1:~$ julia-1.6
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.6.2 (2021-07-14)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia>
Julia on GPU
To run a Julia program on GPU, you must launch your job on a GPU machine (See Partition E5-GPU). As an example, we will run a test on r730gpu01
(which is a login node). However, this is only a test.. Once you are prepared to launch your job, you should write a script and submit it through the queuing system (See Submitting a job).
Load Julia and CUDA modules
PSMN has NVidia GPUs therefore you must load the CUDA API. (NOTE: CUDA version may vary for your software!)
mylogin@r730gpu01: module use /applis/PSMN/debian11/E5/modules/all
module load Julia/1.9.4-linux-x86_64
module load CUDA/11.4.1
Call Julia and run command
This is an example using the package Oceananigans
.
mylogin@r730gpu01:~$ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.4 (2024-06-04)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> using Oceananigans
grid = RectilinearGrid(GPU(), size=(128, 128), x=(0, 2π), y=(0, 2π), topology=(Periodic, Periodic, Flat))
model = NonhydrostaticModel(; grid, advection=WENO())
ϵ (x, y) = 2rand() - 1
set!(model, u=ϵ, v=ϵ)
simulation = Simulation(model; Δt=0.01, stop_time=4)
run!(simulation)