Local parpool cannot initiate following specific command in startup.m

5 views (last 30 days)
I'm running MATLAB R2018b on windows 10. I use the typical startup.m file to set some fairly innocuous groot properties and add some folders containing general tools to the MATLAB path.
Recently, I've included a small script that allows me to add additional folders to the path, depending on which project I am working on. It looks something like this:
% Add other folders to path, depending on project
fprintf('What are you working on?\n')
fprintf('\t1: Project 1.\n')
fprintf('\t2: Project 2.\n')
switch input('')
case 1
addpath(genpath('***Path1***'))
case 2
addpath(genpath('***Path2***'))
otherwise % do nothing
end
The issue is, when I include this script in the startup.m file, I am unable to start a parpool using the 'local' profile - the cluster validation tool gets hung up on the "Job Test (createJob)" step. But, I have no issues if I run this script outside of the startup.m file (i.e., after initialization of the MATLAB instance). I realize that this solves the problem, but I'm curious as to why I can't run the script from within the startup.m file. Does anybody have any comments?
For what it's worth, when I halt the call to parpool that gets hung, I get:
Operation terminated by user during
parallel.internal.getJavaFutureResult (line 15)
In parallel.internal.pool.InteractiveClient/waitForSessionCreation (line
647)
sessionFuture, 1,
java.util.concurrent.TimeUnit.SECONDS);
In parallel.internal.pool.InteractiveClient/start (line 354)
obj.Session =
obj.waitForSessionCreation(sessionFuture,
connectionCounter, ...
In parallel.Pool>iStartClient (line 796)
spmdInitialized = client.start(poolType , numWorkers, cluster, ...
In parallel.Pool.hBuildPool (line 585)
iStartClient(client, 'pool', cluster, guiMode,
supportRestart, argsList);
In parallel.internal.pool.doParpool (line 18)
pool = parallel.Pool.hBuildPool(constructorArgs{:});
In parpool (line 98)
pool = parallel.internal.pool.doParpool(varargin{:});

Accepted Answer

Thomas Falch
Thomas Falch on 12 Sep 2019
The MATLAB workers of the parallel pool will also execute the startup.m script. Since this script contains input(), all the workers will block forever, waiting for input. However, since these workers run in the background, without a GUI, it is not possible to give them any input, and the parpool will simply fail to start.
To avoid this problem make sure your startup.m does not contain any commands like input() which will block, waiting for the user.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!