R
Introduction
In this example, we will explore how to submit an R 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_R.R to compute the objective function value for a specific value of x:
# Define the objective function
f <- function(x) {
return(x^2 + 3*x + 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
cat("The objective function value for x =", x_val, "is", result, "\n")
Execution
We will create a configuration file, for example test_R.slurm, containing the execution settings for this R script.
VERSION=1.3
JOB_NAME=R_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=(
"Rscript $ROUTE/test_R.R"
)
We will submit this script from iocex using the following command:
multivac test_R.slurm
Once execution is complete, the output of the program will be visible in the same directory where it was launched.