Tips for Developing Parallel MATLAB Applications

Getting the Output

An interactive MATLAB Pool session doesn’t have output parse, since the session is always running.  To get the output of a batch job, query for it

>> o = job.getAllOutputArguments;

Getting the Error Messages

If you’re expecting output and the result is empty, check the error property for each task.  

>> job.Tasks(1).Error.message

>> job.Tasks(2).Error.message

>> …

Getting the Diary

An interactive MATLAB Pool session doesn’t have a diary, since the session is always running.  To capture the diary of a batch job, first specify to capture it

>> job = batch(…,’CaptureDiary’,true);


Once the job is finished, query for it

>> job.diary

Getting Log Files

If the output, error, and diary don’t provide enough information, check the MATLAB log file.  The log file(s) is placed in the scheduler‘s data location directory, in the respective job directory.  To get the job data location:

>> folder = fullfile(job.Parent.DataLocation, [’Job’ num2str(job.ID)]);


The folder is located on the head node.  Search for either Task#.log files or Job#.mpiexec.log, where # is the Job ID.

Getting Previous Job Objects

If the handle to the job object has been cleared or the MATLAB client has been exited, the handle to the job can be retrieved by using the Job Monitor.  Select Parallel > Job Monitor.  Search for the job to retrieve.  Right click on the job and select Assign Job to Workspace.

If the Job Monitor is not available (added for R2011b), run the following:

sched = findResource();

>> job = sched.findJob('ID',JOB-ID);


Where JOB-ID is the job ID when creating the job.  To get the job ID, run

>> job.ID


This will be needed before quitting MATLAB or clearing the job object in order to find it again.

What's the State of My MATLAB Job?

An interactive MATLAB Pool session doesn’t have a state parse.  To get the state of a batch job, query the state property

>> job.State

What’s the State of My TORQUE Job?

The state of the TORQUE job can be retrieved via the following call, run on the head node

% qstat –u `whoami`


Check the man page for qstat for the definition of the states values.

Where Does the MATLAB Worker Run on the Cluster?

By default, a Worker will run in the same directory name as the one the MATLAB client is running  in.  There are two ways to check.


Open a MATLAB Pool and run

>> spmd, pwd, end



Submit a batch job that queries the current directory

>> j = batch(@pwd, 1, {});

>> j.wait, j.getAllOutputArguments{:}


If it can’t run in the same folder name, then it will default to the user’s home directory.

How Much Longer Will it Take for My Job to Finish?

When running an interactive MATLAB Pool session, parfor will display intermediate disp statements.  This can be used to give some indication of the completion rate.  There’s no property for batch jobs to determine the completion rate and batch will not display its diary until the job has finished.  Writing a unique temporary file to disk may be one way to determine the completion rate.

Where Are My Attached Files on the Cluster?

When files are attached to a MATLAB Pool or batch job, the files are zipped up, copied over to the compute nodes, and then unzipped.  Files are placed in tempname , unique for each MATLAB Pool session or batch job.  The folder tempname is automatically added to the Worker’s MATLAB path.