Controlling new parallel feature "Automatically create a parallel pool when parallel keywords are executed"

18 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Edric Ellis
Edric Ellis il 15 Gen 2014
Unfortunately, there's no API to modify the parallel preferences. I think you have essentially two options here, and these are:
  1. Turn off auto-opening pools in the parallel preferences UI. Then you have essentially the same situation as existed in R2013a.
  2. Use the optional "number of workers" argument in your PARFOR loop - see the documentation for more.
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 Commenti
Friedrich
Friedrich il 15 Gen 2014
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.
Eduard
Eduard il 15 Gen 2014
Thanks Edric, option two sounds like a reasonable solution. I'll consider this.
Option one is not possible since the script should run out of the box and I can't make sure everyone who uses it always remembers to turn of that option.
@Friedrich: Even if that would work, it sounds very hacky to me. Actually I doubt this file is read interactively when starting the parallel pool; probably only at MATLAB startup? Anyway I'll definitely not start messing around with settings files inside scripts.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by