Julia

Introduction

In this example, we will explore how to submit a Julia program to Multivac to compute an objective function.

Example Code

Suppose we want to minimize the following objective function:

\[f(x) = x^2 + 3x + 2\]

We will create a file named test_julia.jl to compute the objective function value for a specific value of x:

# Define the objective function
f(x) = x^2 + 3x + 2

# Define a specific value of x
x_val = 5

# Compute the objective function value for x_val
result = f(x_val)

# Print the result
println("The objective function value for x = $x_val is $result")

Execution

We will create a configuration file, for example test_julia.slurm, containing the execution settings for this Julia script.

VERSION=1.3
JOB_NAME=julia_example
NAME_OUTPUT=out
PARTITION=all
N_TASKS=1
CPUS_PER_TASK=1
MAIL_TYPE=END,FAIL
MAIL_USER=nom.usuari@upc.edu
MEMORY=1G
BEGIN=now
TIME_LIMIT=00:05:00
LOG_OUTPUT=log
FORCED_NODES=
EXCLUDED_NODES=
ROUTE=~/
COMMANDS=(
        "/usr/local/programari/julia-1.10.1/bin/julia --eval \"include(\\\"$ROUTE/test_julia.jl\\\")\""
)

We will submit this script from iocex using the following command:

multivac test_julia.slurm

Once execution is complete, the output of our program will be visible in the same directory where the job was launched.