How to I pass off a Simulink application command syntax to MATLAB Job Scheduler on a local cluster?
Show older comments
I have a MATLAB/Simulink application that I normally would call from the MATLAB command window with:
app inputfile.m
And then it would run.
If I want to pass that off to the MATLAB Job Scheduler, how would I go about doing that?
I tried following the help documentation about using the cluster profile, creating the parallel job, and then creating the task, except that in the syntax for createTask(j, F, N...)
I tried to put in the "app inputfile.m" as the function into the createTask function and that didn't work.
What would be the better way for me to pass off "app inputfile.m" to MJS?
Your help is greatly appreciated.
Thank you.
Answers (4)
Edric Ellis
on 6 Sep 2019
Where do the results from running app inputfile.m go? Does this create variables directly in the base workspace?
To use app together with createTask, you'd probably need to call it like this:
createTask(job, @app, 0, {'inputfile.m'})
job = batch('app inputfile.m');
wait(job), load(job)
If that does work, then you can simply call batch multiple times.
An alternative might be to use parfor to run app in a parallel loop. But that depends a bit on how the outputs of app are produced...
10 Comments
Ewen Chan
on 6 Sep 2019
Edric Ellis
on 6 Sep 2019
The batch command runs whatever you specify on the cluster. If you don't specify a cluster object, it uses the result of calling parcluster() to use your default cluster. The command runs in the background on the cluster, and job gives you a way to get the results back. You might find it useful to read through some of this documentation: https://uk.mathworks.com/help/parallel-computing/simple-batch-processing.html
If app produces results by writing them to disk... then that does complicate matters a little. You'll need to carefully specify things for app so that it doesn't try to write to the same location multiple times simultaneously. You'll also need to ensure that it writes the files somewhere you can pick them up later (if you start off using the 'local' cluster, then things are simpler since everything is happening on your computer).
Ewen Chan
on 6 Sep 2019
Edric Ellis
on 6 Sep 2019
When you use batch, it (generally speaking) automates the process of getting your MATLAB code to the cluster, running your script, and getting the results back to you. In your case, some minor additional work might be needed to ensure your "inputfile" is definitely sent to the cluster. That's because you're specifying the name of a script that you want app to run. (In the normal course of events, batch performs a MATLAB dependency analysis on the script/function that you specify - but it can't see inside eval commands - and I presume that is essentially how app is running "inputfile").
If you can tell app explicitly where to put the output file, that might be useful.
Yes, jobs created by batch show up in the Job Monitor. I don't think there's necessarily anything specific about your use of Simulink in the batch job - but it might be necessary to attach additional files to the job so that the cluster workers can load all related models.
Ewen Chan
on 6 Sep 2019
Edric Ellis
on 6 Sep 2019
batch does automatically set up the MATLAB path for the workers. The reference page that I linked to earlier has the full details, see specifically the 'AutoAddClientPath' property - defaults to true.
You can submit as many batch jobs as you wish, and you can submit them all from a single MATLAB desktop session. The cluster will run as many as it can simultaneously, the others will remain queued until they can run.
It's not clear to me whether you are going to use MATLAB Job Scheduler (MJS) - which is part of the MATLAB Parallel Server product, or the "local" cluster, which is part of Parallel Computing Toolbox. By default, the "local" cluster runs as many jobs concurrently as you have cores on your machine. More details on the "local" cluster here https://uk.mathworks.com/help/parallel-computing/program-independent-jobs-on-a-local-cluster.html#bq5skz7-1 .
What happened when you tried to run
batch('app inputfile.m')
?
Ewen Chan
on 6 Sep 2019
Ewen Chan
on 9 Sep 2019
Edric Ellis
on 10 Sep 2019
If you're interactively waiting for things to complete, then perhaps the Job Monitor might be the way forward - there you'll be able to see when things are complete.
Programattically - you can either call wait with a timeout, or check job.State to see if it is 'finished'.
Ewen Chan
on 10 Sep 2019
Jason Ross
on 5 Sep 2019
0 votes
12 Comments
Ewen Chan
on 5 Sep 2019
Ewen Chan
on 9 Sep 2019
Jason Ross
on 9 Sep 2019
There is some automated dependency analysis that happens, but it may not detect everything. But you can probably get the rest of the way there with another couple steps. There is a specific entry here about how to find model dependencies and set them up for parallel processing.
I suspect using the above two approaches you can cover more ground than submitting and finding the next missing dependency.
Ewen Chan
on 9 Sep 2019
Jason Ross
on 9 Sep 2019
batch has the ability to add paths via the 'AdditionalPaths' PV pair, so you could add them that way.
Ewen Chan
on 9 Sep 2019
Jason Ross
on 9 Sep 2019
A cell array is a fine way to pass it in:
'AdditionalPaths' — A character vector or cell array of character vectors that defines paths to be added to the MATLAB® search path of the workers before the script or function executes. The default search path might not be the same on the workers as it is on the client; the path difference could be the result of different current working folders (pwd), platforms, or network file system access. The 'AdditionalPaths' property can assure that workers are looking in the correct locations for necessary code files, data files, model files, etc.
Ewen Chan
on 9 Sep 2019
Ewen Chan
on 9 Sep 2019
Jason Ross
on 9 Sep 2019
It may be complaining because of duplicate paths or paths that don't exist? You don't mention your platform, but on Windows dealing with drive letters can be finicky, for example.
Also, is is issuing a warning or an error? In the case of a warning you might just want to ignore it for proof of concept type work, and return to it when you have things generally working.
Ewen Chan
on 9 Sep 2019
Ewen Chan
on 9 Sep 2019
Ewen Chan
on 9 Sep 2019
0 votes
2 Comments
Jason Ross
on 9 Sep 2019
When you run the installer, make sure that MDCE is selected and it should be there. When you set up the MDCE installation it's a best practice to do an all products install so you can service any inbound request from any arbitrary user.
If you try and backfill files manually it can become a tedious nightmare very quickly -- the installer knows how to do "the right thing".
Ewen Chan
on 9 Sep 2019
Ewen Chan
on 10 Sep 2019
4 Comments
Edric Ellis
on 10 Sep 2019
If you're using the 'local' cluster type, this can occur if your output data is too large to save in a MAT file using your default MAT file format. You can change your default version to 7.3 by following the instructions here https://uk.mathworks.com/help/matlab/import_export/mat-file-versions.html - that should fix things. (You'll need to change the preference before submitting the job).
This problem should not occur when using an MJS cluster - that automatically knows how to store outputs that are >=2Gb.
Ewen Chan
on 10 Sep 2019
Edric Ellis
on 10 Sep 2019
It is indeed to do with how the 'local' cluster is saving data. But that is derived from your user-level MAT file preferences. If you change your default MAT file version to v7.3, then (unless you specify otherwise), all MAT files created by MATLAB - including those used by the 'local' cluster - will be able to store >= 2Gb. The link I provided should give you instructions as to how to do that.
The reason you don't see this when running your application locally is that the results are returned to you in RAM. Any cluster type has to store the results of a job in some persistent storage somewhere so that you can pick them up later. 'local' uses MAT files on disk for this.
Ewen Chan
on 10 Sep 2019
Categories
Find more on MATLAB Parallel Server in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!