Blackjack simulation

Example files on ARC-TS clusters can be found in /sw/examples/matlab.

There are two pairs of files for each of the two parallel profiles: there is a .m file and a .sbat file for the local and current profiles.

The local profile can only run on one node, whereas the current profile can be used with multiple nodes. What you request in your job script differs depending on which profile you intend to use. Additionally, the variables that indicate the correct number of workers differs in each.

When using the local profile, your job script should request

####  Note that for MATLAB, local profile, use cpus-per-task to set
####  multiple processors, NOT --tasks-per-node

#SBATCH --nodes=1
#SBATCH --tasks-per-node=1
#SBATCH --cpus-per-task=4

Whereas for the current profile, your job script should request

####  Note that for MATLAB, current profile, use tasks-per-node to set
####  multiple processors, NOT --cpus-per-task

#SBATCH --nodes=2
#SBATCH --tasks-per-node=2
#SBATCH --cpus-per-task=1

For the local profile, the environment variable SLURM_NPROCS will contain the number of processors that the job has assigned, and you can use that in your MATLAB script. The following code will set N to 4 if the SLURM_NPROCS variable does not exist, so your `.m` script does not need to be changed to run outside of a job.

%%%% For use with the local profile
%%%% You should start one worker per task
if isempty(getenv('SLURM_NPROCS'))
    N = 4;
else
    N = str2num(getenv('SLURM_NPROCS'));
end

For the current profile, the environment variable SLURM_NTASKS will contain the number of processors that the job has assigned for each worker, and you can use that in your MATLAB script. The following code will set N to 4 if the SLURM_NTASKS variable does not exist, so your `.m` script does not need to be changed to run outside of a job.

%%%% For use with the current profile
%%%% You should start one worker per task
if isempty(getenv('SLURM_NTASKS'))
    N = 4;
else
    N = str2num(getenv('SLURM_NTASKS'));
end