The following will run the multithread_example.m script in the current
directory, using at most 4 threads (4 CPU cores). In general most MATLAB
code does not scale well beyond 8 cores and hence please do not set
cpus-per-task to more than 8.

The following, based on the previous example, how to pass parameters to
the MATLAB script. This assumes that the script contains a function
of the same name as the script. Two simulations are run sequentially.

#!/bin/bash#SBATCH --output=<CHANGETHIS>.log#SBATCH --job-name=<CHANGETHIS>#SBATCH --cpus-per-task=4#SBATCH --mem-per-cpu=1000#SBATCH --licenses=matlab:1#SBATCH --mail-type=END#SBATCH --mail-user=<CHANGETHIS># Run simulations with different parameters, the integers 1 and 2 in this case.
srun matlab -nodisplay-nosplash-nojvm-r"multithread_example(1);, exit"
srun matlab -nodisplay-nosplash-nojvm-r"multithread_example(2);, exit"

Interactive MATLAB: 1 license

To assist the debugging of scripts using the cluster licensed toolboxes, it is
sometime necessary to run MATLAB in interactive mode on the cluster. To do so,
simply run matlab after logging in on the head node. This will start a
single CPU session with 4GB of memory. Note that it will take about 30 to 50
seconds for the session to be allocated on the cluster and for MATLAB to start.
Note furthermore that the session has a hard time limit of 1 hour and will also
terminate after 20 minutes of inactivity.

Do not use the interactive session for simulations.

For the X11 graphics to be handled correctly, this assumes you have a X11
server installed on your computer and that you logged in with X11 forwarding
enabled.

Random Number Generator Initialisation

There are two random number generators (RNGs) built into MATLAB and that are used by various functions such as RAND and the functions sampling from the various distributions. The sequence of numbers produced by RNGs in MATLAB are determined by the internal state of the generators. Setting the generator to the same fixed state allows computations to be repeated. Setting the generator to different states leads to unique computations. Since MATLAB resets the state at start-up, the various functions using the generators will generate the same sequence of numbers in each session unless the
initial state is changed. The initial state is in turn determined by the seed of the RNG.

For simulations running on the clusters, the following code should be executed once for every simulation run in order to ensure randomised sequences across the runs: