Function File: res = run_parallel(options, func, varargin)

Distribute the execution of a function to multiple processes and return the results of each call as an cell array.

options.number_of_parameters … total number of calls to func to be executed

options.number_of_processors … maximum number of processes running at the same time

options.ignore_errors … continue if func throws an exception

options.octave_exec … Octave’s executable to start

func … user function to be called (e.g. res{idx} = feval(func, idx, varargin{:}))

varargin … additional arguments to be passed to func

See also: run_parallel_func, run_parallel_helper, doe_param_dim_to_res_dim, doe_res_idx_to_param_idx.

Demonstration 1

The following code

 Phi = linspace(-pi, pi, 1000);
 f = @(i, Phi) quadv(@(x) sin(x + Phi(i)).^2, 0, 2 * pi);
 opt.number_of_parameters = numel(Phi);
 opt.number_of_processors = 4;
 tic();
 y = run_parallel(opt, f, Phi);
 tpar = toc();
 tic();
 yser = zeros(1, numel(Phi));
 for i=1:numel(Phi)
   yser(i) = feval(f, i, Phi);
 endfor
 tser = toc();
 assert([y{:}], yser);
 fprintf(stderr, "serial time: %g\n", tser);
 fprintf(stderr, "parallel time: %g\n", tpar);
 fprintf(stderr, "speedup: %g\n", tser / tpar);

gives an example of how 'run_parallel' is used.

Package: mboct-octave-pkg