Why is compiled parfor repeatedly trying to start a parallel pool?
Show older comments
Situation: MATLAB 2015b, CentOS Linux 7, Compiler & Parallel toolboxes installed on machine, Parallel not licensed. Uncompiled: code works fine (parfor loops work like for loops in reverse since the Parallel Toolbox is not licensed). Compiled: at each parfor loop, code tries to start parallel pool (wasting >10 sec).
Example code:
function out = TestPar(s1,s2)
s1=str2num(s1);s2=str2num(s2);
out=zeros(1,s1);
for k = 1:3,
parfor p=1:numel(out),
out(p) = mean(mean(rand(s2,s2)));
end
end
Code Execution uncompiled: TestPar('10000','155') Code Execution compiled: system('TestPar 10000 155')
Answers (1)
Your compiled application (which is pre 2016a) has access to parallel processing and will use the default parallel setting, which is to autocreate a parpool when a parfor is encountered. Change the default setting for this autocreate feature before compiling, since the compiled application will use the default setting of your machine.
To fix:
ps = parallel.Settings;
ps.Pool.AutoCreate = false; %will prevent parpool from activating when encountering parfor
3 Comments
Walter Roberson
on 4 Oct 2017
The behaviour changed as of R2016a; see https://www.mathworks.com/matlabcentral/answers/270249-does-matlab-compiler-checkout-toolbox-licenses-at-compile-time
OCDER
on 4 Oct 2017
Thanks Walter for this info!
Mark Manzardo
on 6 Oct 2017
Edited: Mark Manzardo
on 6 Oct 2017
Categories
Find more on Parallel for-Loops (parfor) 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!