Julia was created as an open source alternative to MATLAB and Octave.
External Links:
Julia website
Learning Julia
module avail
.
To set the environment, load the module.
module load julia
Do not use Julia on a login node. Submit Julia scripts with a batch submission file, and use the HPC-VCL if doing interactive visualization with Julia.
Here is an example batch script. For more information on submitting batch scripts, see the documentation on running jobs.
For a sample Julia script called my_code.jl containing
# a simple Julia code using LinearAlgebra a = [1,2,4]; println("a",a) b = normalize(a) println("normalize(a)",b) println("norm(b)",norm(b))
and a sample submission script submit.sh
#!/bin/bash #BSUB -n 1 #BSUB -W 30 #BSUB -o out.%J #BSUB -e err.%J module load julia julia -p 1 my_code.jl
a batch job is submitted as
bsub < submit.sh
Script submit.sh requests the use of 1 core (-n 1) for up to 30 minutes (-W 30). The output in out.JOBID is
a[1, 2, 4] normalize(a)[0.2182178902359924, 0.4364357804719848, 0.8728715609439696] norm(b)1.0Check the documentation on running jobs to customize the batch script.
If your Julia script takes advantage of multithreading (i.e., using more than one core on just one node for parallelization), then you need to change your batch submission file accordingly.
Here is an example “Hello World” .jl script for multithreading called test_multithread.jl:
import Printf N=4 Threads.@threads for i in 1:N sleep(1) Printf.@printf "Hello from thread %d\n" i end
Here is a sample submission script submit.sh
#!/bin/bash #BSUB -n 4 #BSUB -W 30 #BSUB -R span[hosts=1] #BSUB -o out.%J #BSUB -e err.%J module load julia julia -t 4 test_multithread.jl
The batch job is submitted as
bsub < submit.sh
and the output in out.JOBID looks similar to (order of threads differs each time)
Hello from thread 1 Hello from thread 2 Hello from thread 4 Hello from thread 3
If your Julia script takes advantage of MPI (i.e., using multiple cores on multiple nodes for parallelization), then you need to change your batch submission file accordingly.
However, before designing and submitting a batch job, there are some package installation procedures and MPI configuration steps that must take place:
mkdir -p path/to/your/julia/packages
(fill in correct path)export JULIA_DEPOT_PATH=path/to/your/julia/packages
(note, must be in a location that compute nodes have write access to . /share is not a great choice, because files not accessed in 30 days are deleted. /usr/local/usrapps/ < your group name > will not work b/c it is not writeable from compute nodes. The PI’s Research Storage is a good option: OIT Research Storage module load julia
(or the specific version of julia you are using) module load openmpi-gcc
Julia
import Pkg
Pkg.add("MPI")
Pkg.add("MPIPreferences")
exit()
julia --project -e 'using MPIPreferences; MPIPreferences.use_system_binary()'
Here is an example “Hello World” .jl script for MPI: example
Here is a sample submission script submit.sh
#!/bin/bash #BSUB -n 4 #BSUB -W 30 #BSUB -R span[ptile=2] #BSUB -o out.%J #BSUB -e err.%J export JULIA_DEPOT_PATH=path/to/your/julia/packages # file in correct path, the path must be writeable by a compute node (i.e., not /usr/local/usrapps/$GROUP), and it shoud not be $HOME either because it does not have enough space to install the packages module load julia module load openmpi-gcc/ mpirun julia 04-sendrecv.jl
A batch job is submitted as
bsub < submit.sh
and the output in out.JOBID looks similar to (order may be different, in fact, it may be different every time you run it)
1: Sending 1 -> 2 = [1.0, 1.0, 1.0, 1.0] 3: Sending 3 -> 0 = [3.0, 3.0, 3.0, 3.0] 0: Sending 0 -> 1 = [0.0, 0.0, 0.0, 0.0] 0: Received 3 -> 0 = [3.0, 3.0, 3.0, 3.0] 2: Sending 2 -> 3 = [2.0, 2.0, 2.0, 2.0] 3: Received 2 -> 3 = [2.0, 2.0, 2.0, 2.0] 2: Received 1 -> 2 = [1.0, 1.0, 1.0, 1.0] 1: Received 0 -> 1 = [0.0, 0.0, 0.0, 0.0]Check the documentation on running jobs to customize the batch script.
Additional packages outside of the base Julia install must be installed by the user. See the instructions for request a space for user maintained software.
The basic process to install a new Julia package is to use Pkg.add from a login node. By default, Julia will install the packages in the home directory in ~/.julia. That will quickly fill the home directory. Before installing packages, set the location for the installs by setting JULIA_DEPOT_PATH to the user maintained software directory.
export JULIA_DEPOT_PATH = /usr/local/usrapps/[your space for user maintained software]/[whatever you want to call the julia apps directory]
module load julia julia import Pkg Pkg.add("whatever")Check the Julia documentation on setting environment variables.
Last modified: April 12 2025 13:38:20.