- Turn off auto-opening pools in the parallel preferences UI. Then you have essentially the same situation as existed in R2013a.
- Use the optional "number of workers" argument in your PARFOR loop - see the documentation for more.
Controlling new parallel feature "Automatically create a parallel pool when parallel keywords are executed"
19 次查看(过去 30 天)
显示 更早的评论
Hi all,
is there a possibility to control this feature (e.g. temporarily deactivate or read the settings value) from within a script?
Background is that I have a script that contains a parfor loop. For this parfor loop to work on workers there needs to be done some initializing though before entering the loop. This initialization is omitted when the matlabpool is automatically created when reaching the parfor loop.
This means I either need to start the matlabpool before reaching the loop so I can do the initialization (which I don't want to do by default) or (as an ugly workaround) I could add a dummy parfor loop to trigger the automatic startup of the matlabpool due to the new setting early.
Is there a proper way to control the preference (without user interaction)?
Regards Eduard
0 个评论
采纳的回答
Edric Ellis
2014-1-15
Unfortunately, there's no API to modify the parallel preferences. I think you have essentially two options here, and these are:
As an example of the second approach, you could do something like this
if wantToGoParallel
M = Inf;
else
M = 0;
end
parfor (idx = 1:N, M)
doStuff(...);
end
2 个评论
Friedrich
2014-1-15
Actually one could change one entry in the parallel.settings file in the prefdir. There is one sections in that file which reads:
<settings name="pool">
<key name="AutoCreate">
<bool>
<value>1</value>
</bool>
</key>
Change the value 1 to 0 to disable it. So a bit fopen, fseek, fwrite does the job.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!