Running Julia on Elzar (CSHL HPC)

Creation date: 5/26/2023 3:14 PM    Updated: 6/2/2023 1:56 PM   cluster elzar hpc julia software
v.1.0, Robert Petkus, 5/26/23

Julia is a high-level, general-purpose dynamic programming language that is well suited for numerical analysis and computational science.  It has features such as multiple dispatch, parametric polymorphism; concurrent, parallel and distributed computing, and direct calling of C and Fortran libraries.  It also has a just-in-time (JIT) compiler.

→→ To use Julia in our HPC environment, simply use Easybuild modules.

Example as your user on bamdev1/bamdev2:


> module load EBModules
> module load Julia/1.8.2-linux-x86_64

> julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.2 (2022-09-29)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> sqrt(16)
4.0

julia> using LinearAlgebra

julia> A = rand(3, 3)
3×3 Matrix{Float64}:
 0.505015  0.0199518  0.963248
 0.768551  0.799936   0.282653
 0.177866  0.333901   0.982073

julia> det(A)
0.4451556460260788


Example running as a job:

Create a shell script for job submission (e.g., julia_test.sh):

#!/bin/bash
#$ -cwd
#$ -l m_mem_free=2G
#$ -pe threads 8
module load EBModules
module load Julia/1.8.2-linux-x86_64
julia julia_test.jl


Create a test Julia script (julia_test.jl):

# Robert Petkus - test some of the features of Julia
# Found these links helpful:

# Multiple dispatch: a function can have different behaviors depending on the types of its arguments
function f(x::Int, y::Int) # f for two integers
    return x + y
end

function f(x::String, y::String) # f for two strings
    return x * y # string concatenation
end

function f(x::Float64, y::Float64) # f for two floats
    return x / y # floating-point division
end

# Parametric polymorphism: a function can be defined for a range of types using type parameters
function g(x::T, y::T) where {T<:Number} # g for any subtype of Number
    return x - y
end

# Direct calling of Fortran libraries: a function can call an external Fortran subroutine using ccall
function h(n::Int) # h for an integer
    # call the dgesv subroutine from LAPACK to solve a linear system Ax = b
    A = rand(n, n) # create a random n x n matrix A
    b = rand(n) # create a random n-vector b
    ipiv = zeros(Int32, n) # create an array of pivot indices
    info = Ref{Int32}() # create a reference to store the return code
    ccall( (:dgesv_, "liblapack"), Cvoid,
        (Ref{Int32}, Ref{Int32}, Ptr{Float64}, Ref{Int32}, Ptr{Int32}, Ptr{Float64}, Ref{Int32}, Ref{Int32}),
        n, 1, A, n, ipiv, b, n, info ) # call the subroutine with appropriate arguments and types
    return (info[], b) # return the return code and the solution vector b (overwritten by dgesv)
end

# Random stuff - test functions with some examples
println(f(2, 3)) # 5
println(f("Hello", "World")) # HelloWorld
println(f(4.0, 2.0)) # 2.0
println(g(10, 3)) # 7
println(g(3.14, 2.71)) # 0.42999999999999994
info, x = h(5) # solve a 5 x 5 linear system
println(info) # 0 (success)
println(x) # the solution vector


Submit job:

> qsub julia-test.sh