MATLAB Job Submission on MatriCS

This example shows how to submit a MATLAB job on MatriCS.
To execute each section in this script you can either click on , or click on the blue bar on the left of the section
Table of Contents

Documentation and Examples

Cluster Configuration

Job Submission

In this example, the code being executed approximates the value of Pi using a Monte Carlo method. See the Job Submission section and the call to the @computePi function. The code that approximates pi is written in the Write Your Own Function section. You can write your own MATLAB function here and then test it. If you change the function name, remember to change it in the batch function as well.
c = parcluster('MatriCS');
job = batch(c,@computePI,1,{10e3,10e3},Pool=c.PreferredPoolNumWorkers,CurrentFolder='.');
Monitor your job
To monitor your job you can click on Home and then on Parallel (Icon with 4 blue bars) then choose Monitor Jobs.
You can also just display the variable job
job
Otherwise in a terminal, you can view your job with the command:
squeue -u $(whoami)

Get the result

If the job has completed successfully, you should see the estimated value of pi displayed, approximately 3.14.
if job.State == "finished"
results = job.fetchOutputs
elseif job.State == "running"
disp(['Job state: ', job.State]);
end

Compute PI with Monte Carlo Method

function PI = computePI(m,n)
if canUseGPU
c = gpuArray.zeros(1);
for i = 1:n
x = gpuArray.rand(m,1);
y = gpuArray.rand(m,1);
r = x.^2 + y.^2;
c = c + sum(r<=1);
end
PI = 4/(m*n) * gather(c);
else
c = 0;
parfor i = 1:n
x = rand(m,1);
y = rand(m,1);
r = x.^2 + y.^2;
c = c + sum(r<=1);
end
PI = 4/(m*n) * c;
end
end

Write Your Own Function

Now to you: write your function and modify the batch command to call your function.
function out = myFunction(in)
out = in;
end