MATLAB: Do I receive error “Unable to load block diagram…” when simulating a model on a remote cluster

clustercomputingMATLAB Parallel Serverparallelpctsimulationtoolbox

I am simulating a model as part of a MATLAB script using the 'sim' function. When I run the script on my local parallel pool it runs correctly, when I run on a pool created on a remote cluster I receive the error:
Unable to load block diagram 'myDiagram'

Best Answer

The error message you are receiving is occurring because the workers on the MDCS cluster do not have access to the model file, so they are unable to load the model. The solution to this issue is to place the model in a location accessible by the MDCS workers. There are two alternatives to do this:
1) *Create a _job_ for your computation, and attach files to the job.* This option does not require infrastructure changes but will not scale well if you have many workers and/or large files. The following example creates a job with attached files, adds a task, and submits the job.
c = parcluster('myRemoteClusterProfile');
j = createJob(c,'AttachedFiles', {'myModel.slx'});
t = createTask(j, @myFunc, 1, {10,10}); % myFunc has 1 output argument and two inputs
submit(j); % Submit the job to the cluster so it can be run
2) *Place the model in a networked file share*. This option may require some infrastructure changes depending on your network, however this option scales better for large files and many workers. The only change required to your code would be to use the full path to the model and data file instead of just the name.
For example:
sim('myModel.slx');
would become:
sim('\\path\to\network\share\myModel.slx');