Initial Setup
1. Load and Open the MATLAB Module
Note: Normal text denotes user input, code blocks denote response from software.
[johnchris@a002 ~]$ interactive
Executing: srun --pty -N1 -n1 -c4 --mem=8g -pinteractive -t0-04:00:00 /bin/bash
Press any key to continue or ctrl+c to abort.
cpu-bind=MASK - c003, task 0 0 [610031]: mask 0x888800000000 set
[johnchris@c003 ~]$ rm -rf .matlab # First-time user ONLY
[johnchris@c003 ~]$ module load matlab
[johnchris@c003 ~]$ matlab
Note: You get assigned to a node on the cluster (c003 in this example). Then, you get the following message, and the MATLAB window opens interactively on the terminal.
< M A T L A B (R) >
Copyright 1984-2026 The MathWorks, Inc.
R2026a Update 2 (26.1.0.3251617) 64-bit (glnxa64)
May 5, 2026
To get started, type doc.
For product information, visit www.mathworks.com.
Note: There is a space between rm and -rf, as well as another one between -rf and .matlab
2. Now we are in a MATLAB session. Run the MATLAB command:
Note: Type each individual line, do not copy-paste these commands as a block of code or you may see errors. ConfigCluster should only be called once per cluster. No need to do it for the second time.
>> configCluster
Complete. Default cluster profile set to "Andromeda".
>> c = parcluster;
Must set WallTime before submitting jobs to Andromeda2. E.g.
>> c = parcluster;
>> % 5 hour, 30 minute walltime
>> c.AdditionalProperties.WallTime = '05:30:00';
>> c.saveProfile
>> c.saveProfile;
3. Exit the MATLAB Session
>> exit
[johnchris@c003 ~]$
Configuring Jobs
1. Create a Slurm File (parallel_matlab.sl) that calls your MATLAB code file which you will construct next.
#!/bin/bash
#SBATCH --job-name=sample # Job name
#SBATCH --time=12:00:00 # Time limit hrs:min:sec (max: 120 hours)
#SBATCH --ntasks=1 # Number of tasks
#SBATCH --nodes=1 # Number of nodes requested
#SBATCH --partition=short # Choice of partition
#SBATCH --cpus-per-task=1 # Number of CPU processors per task
#SBATCH --mem-per-cpu=4G # RAM per node (Max: 180GB/44 cores, 250GB/60 cores)
#SBATCH --mail-type=ALL # Mail notifications (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=username@bc.edu # BC email address
module load matlab
cd /projects/<proj_name>/parallel_matlab # Directory of MATLAB code file
matlab -batch parallel_matlab >¶llel_matlab.out
Note: Bold denotes input individual users MUST change. Ensure the time limit is sufficient for MATLAB execution.The cluster currently provides time-based partitions for CPU & GPU nodes. They are: long (up to 120 hours), medium (up to 48 hours), and short (up to 12 hours). Submitting a job this way requires you to edit c.AdditionalProperties to specify computational resources.
2. Add the Parallel Computing Command to MATLAB Code File (parallel_matlab.m)
c = parcluster;
%Corresponding to the time limit in the Slurm file
c.AdditionalProperties.WallTime = ’12:00:00′;
%Corresponding to CPU memory, per core
c.AdditionalProperties.MemPerCPU = ‘6G’;
%Number of processors requested per node, same as the number in parpool()
c.AdditionalProperties.ProcsPerNode = 10;
%If you wish to work across nodes, divide the number above by the number of nodes
%E.g. “c.AdditionalProperties.ProcsPerNode = 5;” will work on 2 nodes in this example
%Can be different from the node choice
c.AdditionalProperties.Partition= ‘short’;
saveProfile(c)
%Total CPU cores requested for the program, cannot exceed 512 cores
parpool(10)
%End of the parallel computing command, program codes start here
tic
n = 20000;
A = 500;
a = zeros(1,n);
parfor i=1:n
if mod(i, 100) == 1
i
end
a(i) = max(abs(eig(rand(A))));
end
toc
delete(gcp(‘nocreate’));
Note: If you use the ‘touch’ command to generate the MATLAB code file, the .m file might not be executable when being directly copied from the sample script shown above, which contains non-ASCII whitespace characters. Removing the whitespace characters will solve this issue.
Submitting Jobs
- Upload the Slurm file (parallel_matlab.sl) and the MATLAB code file (parallel_matlab.m) to the directory specified in your Slurm file (/projects/<proj_name>/parallel_matlab is given in the example, but you must change it to reflect your own file path) on the Andromeda cluster:
Note: It is advised to upload the Slurm file and the MATLAB code file in the same directory.
[johnchris@a002 ~/parallel_matlab]$ ls
parallel_matlab.m parallel_matlab.sl
- Once logged in to the Andromeda cluster, open the directory you created on the terminal:
[johnchris@a002 ~]$ cd parallel_matlab
[johnchris@a002 ~/parallel_matlab]$
- Submit your job (the Slurm .sl file) onto Andromeda:
[johnchris@a002 ~/parallel_matlab]$ sbatch parallel_matlab.sl
Submitted batch job 2652880
- You can check on the status of your jobs using the following code. “R” indicates that the job is running.
[johnchris@a002 ~/parallel_matlab]$ squeue -u username
2652884 short MATLAB_R johnchris R 0:03 1 c018
2652880 short sample johnchris R 0:21 1 c002
Note: Job 2652880 (sample) is what the Slurm file calls directly. Job 2652884 (MATLAB_R) is the parallel pool that the code in parallel_matlab.m calls within MATLAB.
- Once your job is done, a file will appear (parallel_matlab.out), as named in the Slurm file, with the output of your MATLAB session.
[johnchris@andromeda ~/parallel_matlab]$ ls
parallel_matlab.m parallel_matlab.sl parallel_matlab.out
Running Interactively
If you do not wish to use a Slurm file, you may instead write code directly in the terminal after entering an interactive session. This will take you to an available compute node on Andromeda.
[johnchris@andromeda ~]$ interactive
[johnchris@c003 ~]$ module load matlab
[johnchris@c003 ~]$ matlab
Note: You get assigned to a node on the cluster (eg. c003 in this case). Then, you get the following message and the MATLAB window opens interactively on the terminal.
< M A T L A B (R) >
Copyright 1984-2026 The MathWorks, Inc.
R2026a Update 2 (26.1.0.3251617) 64-bit (glnxa64)
May 5, 2026
To get started, type doc.
For product information, visit www.mathworks.com.
You can now enter the code in MATLAB interactively as below:
Note: Type each individual line, do not not copy paste these commands as a block of code or you may see errors.
>> c = parcluster;
>> c.AdditionalProperties.MemPerCPU=’6G’;
>>c.AdditionalProperties.WallTime = ‘8:00:00’;
>>saveProfile(c)
>>parpool(10)
Note: This is not always a quick process, it can take time for resources to be allocated due to normal cluster queues.
Starting parallel pool (parpool) using the 'Andromeda' profile ...
Submit arguments: --ntasks=10 --cpus-per-task=1 --ntasks-per-core=1 --mem-per-cpu=6G -t 8:00:00
Connected to parallel pool with 10 workers.
ans =
ClusterPool with properties:
Connected: true
NumWorkers: 10
Busy: false
Cluster: Andromeda (Generic Cluster)
AttachedFiles: {}
AutoAddClientPath: true
FileStore: [1x1 parallel.FileStore]
ValueStore: [1x1 parallel.ValueStore]
IdleTimeout: 30 minutes (30 minutes remaining)
SpmdEnabled: true
EnvironmentVariables: {}
You can now insert your desired MATLAB code:
>> tic
>> n = 20000;
>> A = 500;
>> a = zeros(1,n);
>> parfor i=1:n
if mod(i,100) == 1
i
end
a(i) = max(abs(eig(rand(A))));
end
ans =
701
ans =
301
ans =
801
...
ans =
19701
ans =
19801
ans =
19901
>>toc
Elapsed time is 399.318174 seconds.
>>delete(gcp(‘nocreate’));
Parallel pool using the 'Andromeda' profile is shutting down
>>exit
[johnchris@c003 ~]$
Batch Job
You can also use the ‘batch’ command to submit asynchronous jobs to the cluster. The batch command will return a job object which is used to access the output of the submitted job.
- Configure the MATLAB code (parabatch_matlab.m) with desired parallel computing process as a function:
function t = parabatch_matlab()
t0 = tic;
n = 20000;
A = 500;
a = zeros(1,n);
parfor i = 1:n
if mod(i, 100) == 1
i
end
a(i) = max(abs(eig(rand(A))));
end
t = toc(t0);
end
2. Open the specified directory on Andromeda:
[johnchris@a002 ~]$ cd parallel_matlab
[johnchris@a002 ~/parallel_matlab]$
- Use ‘srun’ to go to a Compute node in Andromeda. Then start a MATLAB session, and
open a parcluster:
[johnchris@a002 ~/parallel_matlab]$ srun –job-name=sample –nodes=1 –ntasks=1 –time=1:00:00 –mem=20G –pty bash -i
cpu-bind=MASK - c002, task 0 0 [4081418]: mask 0x800000000000 set
[johnchris@c002 parallel_matlab]$ module load matlab
[johnchris@c002 parallel_matlab]$ matlab
Note: You get assigned to a node on the cluster (eg. c002 in this case). Then, you get the following message and the MATLAB window opens interactively on the terminal.
< M A T L A B (R) >
Copyright 1984-2026 The MathWorks, Inc.
R2026a Update 2 (26.1.0.3251617) 64-bit (glnxa64)
May 5, 2026
To get started, type doc.
For product information, visit www.mathworks.com.
Note: Type each individual line, do not copy paste these commands as a block of code or you may see errors.
>>c = parcluster;
>>c.AdditionalProperties.MemPerCPU=’6G’;
>>c.AdditionalProperties.WallTime = ‘1:00:00’;
>>saveProfile(c)
>>parpool(10)
Starting parallel pool (parpool) using the 'Andromeda' profile ...
Submit arguments: --ntasks=10 --cpus-per-task=1 --ntasks-per-core=1 --mem-per-cpu=6G -t 1:00:00
Connected to parallel pool with 10 workers.
ans =
ClusterPool with properties:
Connected: true
NumWorkers: 10
Busy: false
Cluster: Andromeda (Generic Cluster)
AttachedFiles: {}
AutoAddClientPath: true
FileStore: [1x1 parallel.FileStore]
ValueStore: [1x1 parallel.ValueStore]
IdleTimeout: 30 minutes (30 minutes remaining)
SpmdEnabled: true
EnvironmentVariables: {}
Note: Please ensure to specify an appropriate wall time for your job as the MATLAB parallel process may encounter errors if wall time is not specified in the above code.
- Now call your function file using the batch command. The number after ‘Pool’ specifies
the number of workers to be used (change this according to your needs). The batch
command returns a job object, j.
>>j = c.batch(@parabatch_matlab,1,{},’Pool’,10,’Currentfolder’,’.’,’AutoAddClientPath’,false)
Submit arguments: --ntasks=11 --cpus-per-task=1 --ntasks-per-core=1 --mem-per-cpu=6G -t 1:00:00
j =
Job
Properties:
ID: 4
Type: pool
Username: johnchris
State: running
StorageBytes: 16493 (17 KB)
SubmitDateTime: 02-Jul-2026 16:22:23
StartDateTime:
RunningDuration: 0 days 0h 0m 0s
NumWorkersRange: [11 11]
NumThreads: 1
SpmdEnabled: true
AutoAttachFiles: true
Auto Attached Files: /home/johnchris/parallel_matlab/parabatch_matlab.m
AttachedFiles: {}
AutoAddClientPath: false
AdditionalPaths: {}
FileStore: [1x1 parallel.FileStore]
ValueStore: [1x1 parallel.ValueStore]
EnvironmentVariables: {}
Associated Tasks:
Number Pending: 11
Number Running: 0
Number Finished: 0
Task ID of Errors: []
Task ID of Warnings: []
Task Scheduler IDs: 2653886
Note: Be aware that in addition to the number of workers that you ask for in your ‘Pool’ argument, you will also receive an additional “Orchestrator” worker that is required for job execution. Therefore, a request of 10 pool workers will result in 11 total tasks from the scheduler.
5. ‘j.State’ tells you whether the job is queued (waiting to start), running, or finished.
>>j.State
ans =
‘running’
- Use ‘j.fetchOutputs’ to retrieve function output arguments. Use ‘j.fetchOutputs{:}’ to display all contents in it. In this case, and = 286.8998 indicates that the program took 286.8998 seconds to run. If calling a batch with a script, use load instead. Data that has been written to files on the cluster needs to be retrieved directly from the file system, such as via FTP.
>> j.fetchOutputs
ans =
1x1 cell array
{[286.8998]}
Note: outputs can only be fetched if the job is in state ‘finished’.
- You can view a list of your past and current jobs, as well as their IDs, using the ‘c.Jobs’ Command.
>> c.Jobs
ans =
3x1 Job array:
ID Type State FinishDateTime StorageBytes Username Tasks
-----------------------------------------------------------------------------
1 2 pool finished 02-Jul-2026 16:15:15 35 KB johnchris 11
2 3 pool running 27 KB johnchris 10
3 4 pool finished 02-Jul-2026 16:27:28 35 KB johnchris 11
- If a serial job produces an error, call the ‘getDebugLog’ method to view the error log file. When submitting independent jobs, with multiple tasks, specify the task number. You can also analyze the job’s log file output when debugging.
>> c.getDebugLog(j.Tasks(3))
Error using parallel.cluster.CJSCluster/getDebugLog (line 793)
Tasks from a communicating job not supported. Task must be from an independent job.
>> c.getDebugLog(j)
LOG FILE OUTPUT:
cpu-bind=MASK - c028, task 0 0 [3117304]: mask 0x800000000010 set
The scheduler has allocated the following nodes to this job:
c[028-031]
"/m31/modules/matlab/2026a/bin/mw_mpiexec" -genvlist PARALLEL_SERVER_DECODE_FUNCTION,PARALLEL_SERVER_STORAGE_CONSTRUCTOR,PARALLEL_SERVER_JOB_LOCATION,PARALLEL_SERVER_MATLAB_EXE,PARALLEL_SERVER_MATLAB_ARGS,PARALLEL_SERVER_DEBUG,MLM_WEB_LICENSE,PARALLEL_SERVER_STORAGE_LOCATION,PARALLEL_SERVER_CMR,PARALLEL_SERVER_TOTAL_TASKS,PARALLEL_SERVER_NUM_THREADS,PARALLEL_SERVER_BIND_TO_CORE,MW_FEATURE_MathworksServiceHostIsOnByDefault,HOME,USER,TZ -bind-to core:1 -l -n 11 "/m31/modules/matlab/2026a/bin/worker" -parallel
START: Thu Jul 2 04:22:25 PM EDT 2026
[0] Parallel pool is shutting down.
real 5m5.205s
user 0m0.012s
sys 0m0.011s
END: Thu Jul 2 04:27:30 PM EDT 2026
Exiting with code: 0
>>j.getTaskSchedulerIDs{:}
ans =
'2653886'
SPMD Example
Single Program Multiple Data (SPMD) is an advanced construct that enables communication
amongst different workers (processors) throughout the computation, and customization of tasks
across workers. Under SMPD, each worker has a unique index, spmdIndex. In the example
below, workers 1-10 are assigned to only take the loops with the same digit as their spmdIndex
- Create a Slurm file (spmd_test.sl) that calls your MATLAB code file (spmd_matlab.m).
#!/bin/bash
#SBATCH --job-name=spmd
#SBATCH --time=12:00:00
#SBATCH --ntasks=1
#SBATCH --nodes=1
#SBATCH --partition=shared
#SBATCH --mem-per-cpu=4G
#SBATCH --cpus-per-task=1
#SBATCH --mail-type=ALL
#SBATCH --mail-user=username@bc.edu
module load matlab
cd /home/johnchris/parallel_matlab
matlab -batch spmd_matlab >&spmd_matlab.out
Note: Bold denotes input individual users MUST change.
- Configure the MATLAB code (spmd_matlab.m) with desired parallel computing process:
c = parcluster;
c.AdditionalProperties.WallTime=’6:00:00′;
c.AdditionalProperties.MemPerCPU=’6G’;
c.AdditionalProperties.ProcsPerNode=10;
c.AdditionalProperties.Partition=’shared’;
saveProfile(c)
parpool(10)
tic
spmd(10)
n = 20000;
A = 500;
a = zeros(1,n);
for i = 1:n
if mod(i, 10) == mod(labindex,10)
a(i) = max(abs(eig(rand(A))));
end
end
end
toc
delete(gcp(‘nocreate’));
3. The rest are the same as Step 1 to Step 5 in the “Submitting Jobs” section above.
Running Locally
MATLAB supports parallel processing through two key products: Parallel Computing Toolbox (PCT) and MATLAB Parallel Server. For workloads requiring 92 or fewer workers, utilizing PCT with a local cluster profile might be a more efficient choice. This approach eliminates the need for complex Parallel Server setup and avoids the overhead associated with remote cluster configuration. PCT enhances MATLAB with faster local execution, shorter development time, interactive debugging, and built-in parfor loop support.
1. Create a Slurm file (parallel_matlab_local.sl) that calls your MATLAB code file which you will construct next.
#!/bin/bash
#SBATCH --job-name=sample #Job name
#SBATCH --time=12:00:00 #Time limit hrs:min:sec
#SBATCH --ntasks=24 #Number of tasks (Max 92)
#SBATCH --nodes=1 #Number of nodes requested (must = 1 for local jobs)
#SBATCH --partition=short #Node choice
#SBATCH --mem-per-cpu=4G #RAM/node, Max (180GB/44 cores, 250GB/60 cores,1932GB/92)
#SBATCH --mail-type=ALL #Mail events (NONE, BEGIN, END, FAIL, ALL)
#SBATCH --mail-user=username@bc.edu #BC email address
module load matlab
cd /projects/<proj_name>/parallel_matlab #Directory of your MATLAB code file
matlab -nojvm -r parallel_matlab_local >¶llel_matlab_local.out
Note: Underline denotes input individual users MUST change. Make sure that the time limit is sufficient for the MATLAB job to start and complete. The cluster currently provides time-based partitions for CPU & GPU nodes. For Andromeda: long (up to 120 hours), medium (up to 48 hours), and short (up to 12 hours). Submitting a job this way requires you to edit c.AdditionalProperties in order to specify computational resources wanted.
2. Add the parallel computing command in your MATLAB code file (parallel_matlab_local.m).
% Note that this code first checks to see if a pool is already open, and if not, uses the local “Processes” profile. It then opens a local, single-node pool based on the number of workers specified in your parallel_matlab_local.sl file.
if isempty(gcp(“nocreate”))
parpool(“Processes”, maxNumCompThreads);
end
%End of the parallel computing command, program codes start here
tic
n = 20000;
A = 500;
a = zeros(1,n);
parfor i=1:n
if mod(i, 100) == 1
i
end
a(i) = max(abs(eig(rand(A))));
end
toc
delete(gcp(‘nocreate’));
3. The rest are the same as Step 1 to Step 5 in the “Submitting Jobs” section above.