Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if MATLAB startup.m is running on a worker

A colleague has a MATLAB startup.m file that contains interactive code (it calls the command questdlg to ask him which project directory he wishes to work in).

This works fine for him when running MATLAB directly. However, he also needs to run MATLAB code in parallel, having started up a matlabpool.

When starting up, the workers in the matlabpool are running his startup.m file, getting to the questdlg and then hanging (infinitely, or until Ctrl C).

An easy solution is to just get rid of the interactive code from his startup.m, as it's not really essential.

But is there a way to detect whether this startup.m is being run by a worker starting up - something similar to isdeployed or ismcc? Then he could keep the interactive code that he finds useful, but only execute it when not starting up a worker.

The command getCurrentWorker seemed like it might be what was needed, but I believe that only works during the execution of a task, rather than at startup.

like image 559
Sam Roberts Avatar asked Nov 03 '22 21:11

Sam Roberts


1 Answers

You could use the usejava function to see if the interactive desktop is running, which is probably a good enough approximation unless you frequently use -nodesktop mode.

if usejava('desktop')
    questdlg(...);
end
like image 113
Edric Avatar answered Nov 15 '22 10:11

Edric