Why is compiled parfor repeatedly trying to start a parallel pool?

10 views (last 30 days)
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)

OCDER
OCDER on 4 Oct 2017
Edited: OCDER on 4 Oct 2017
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
Mark Manzardo
Mark Manzardo on 6 Oct 2017
Edited: Mark Manzardo on 6 Oct 2017
I've validated a work around for my situation in part thanks to the fix Donald suggested (Thanks for pointing me in the right direction). The following was required to maintain functionality in uncompiled and compiled versions for both Windows and Linux environments given my situation:
if true
IsPar = true;
try
if isempty(gcp('create'))
ps = parallel.Settings;
if ps.Pool.AutoCreate
parpool(parcluster);
end
end
catch
IsPar = false;
try
ps.Pool.AutoCreate = false;
catch
end
end
end
The IsPar flag is used later throughout the code to prevent failure conditions when other PCT functions (i.e., other than parfor) are encountered in the code. NOTE: this was all necessary because license('test','Distrib_Computing_Toolbox') doesn't work like it should specifically for my situation on Linux when compiled.

Sign in to comment.

Categories

Find more on Licensing on Cloud Platforms 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!