handleParallelRAVEN Called by RAVEN functions that support parallel processing, to confirm whether the MATLAB Parallel Computing Toolbox is installed. - The toolbox is installed, and runParallel == true, ==> a parallel pool is started. - The toolbox is installed, but runParallel == false, ==> the auto- creation of a parallel pool is disabled, to prevent "parfor" in the target function to start a pool anyway. - The toolbox is not installed, and runParallel == true, ==> a warning is displayed that parallel computer is not possible. - The toolbox is not installed, and runParallel == false, ==> the target runs as intended, as "parfor" will automatically run in serial mode instead. Input: runParallel logical, whether the target function (which calls parallelPoolRAVEN) should be run in parallel (optional, default true) Output: ps parallel settings structure that will be used by the target function oldPoolAutoCreate logical, to reset the original ps.Pool.AutoCreate setting once the target function has finished Use: [ps, oldPoolAutoCreate] = parallelPoolRAVEN(runParallel)
0001 function [ps, oldPoolAutoCreate] = parallelPoolRAVEN(runParallel) 0002 % handleParallelRAVEN 0003 % Called by RAVEN functions that support parallel processing, to confirm 0004 % whether the MATLAB Parallel Computing Toolbox is installed. 0005 % - The toolbox is installed, and runParallel == true, ==> a parallel 0006 % pool is started. 0007 % - The toolbox is installed, but runParallel == false, ==> the auto- 0008 % creation of a parallel pool is disabled, to prevent "parfor" in 0009 % the target function to start a pool anyway. 0010 % - The toolbox is not installed, and runParallel == true, ==> a warning 0011 % is displayed that parallel computer is not possible. 0012 % - The toolbox is not installed, and runParallel == false, ==> the 0013 % target runs as intended, as "parfor" will automatically run in serial 0014 % mode instead. 0015 % 0016 % Input: 0017 % runParallel logical, whether the target function (which calls 0018 % parallelPoolRAVEN) should be run in parallel (optional, 0019 % default true) 0020 % 0021 % Output: 0022 % ps parallel settings structure that will be used by 0023 % the target function 0024 % oldPoolAutoCreate logical, to reset the original ps.Pool.AutoCreate 0025 % setting once the target function has finished 0026 % 0027 % Use: [ps, oldPoolAutoCreate] = parallelPoolRAVEN(runParallel) 0028 0029 if nargin<1 || isempty(runParallel) 0030 runParallel = true; 0031 end 0032 0033 addonList = matlab.addons.installedAddons; 0034 ps = []; oldPoolAutoCreate = []; 0035 if ~any(strcmpi(addonList.Name,'Parallel Computing Toolbox')) 0036 if runParallel % User wants parallel, but will not be possible 0037 disp('Cannot find MATLAB Parallel Computing Toolbox, process is not parallelized.') 0038 end 0039 else 0040 pool = gcp('nocreate'); 0041 if ~runParallel % User has Parallel toolbox, but does not want pool to start. 0042 % If pool is already running, delete it 0043 ps = parallel.Settings; 0044 oldPoolAutoCreate = ps.Pool.AutoCreate; 0045 ps.Pool.AutoCreate = false; 0046 delete(pool); 0047 elseif isempty(pool) 0048 parpool('IdleTimeout',120); 0049 end 0050 end 0051 end