MATLAB: Is “startup.m” file affecting the execution of “parpool” command

hangingMATLABparallelParallel Computing Toolboxparpoolslowstartupstartup.m

I have a "startup.m" file in which a pop-up window is displayed to the user in order to change the working directory at MATLAB startup.
However, it seems like it is affecting the execution of "parpool" command: such command is hanging forever when I use this "startup.m" file. Why?

Best Answer

The "startup.m" is opening a dialogue window on all of the workers and requesting a response from the user. The workers then wait on that dialogue window forever. This is the reason why "parpool" command is hanging forever.
This is happening because the "startup.m" file is on the path of the MATLAB workers on the same machine. MATLAB workers share the same path as the MATLAB client and execute the "startup.m" on initialization.
Workaround:
The "startup.m" file should be modified such that the interactive/problematic sections are executed only by the MATLAB client and not by MATLAB workers.
if (~java.awt.GraphicsEnvironment.isHeadless())
<code that we only want to happen on client>
end
Or:
if (usejava('desktop'))
<code that we only want to happen on client>
end