PoolPrepare

PoolPrepare prepares a pool of MATLAB instances for executing code in parallel

Syntax

  • numpool=PoolPrepare(numpool,pariter,UserOptions)example
  • [numpool, tstart]=PoolPrepare(___)example
  • [numpool, tstart, progbar]=PoolPrepare(___)example
  • [numpool, tstart, progbar, usePCT]=PoolPrepare(___)example
  • [numpool, tstart, progbar, usePCT, usematlabpool]=PoolPrepare(___)example

Description

PoolPrepare and PoolClose are used respectively to open and close a prespecified number of parallel MATLAB sessions, which need to be distributed over the physical cores where MATLAB is running.

example

numpool =PoolPrepare(numpool, pariter, UserOptions) Sequential vs parallel run.

example

[numpool, tstart] =PoolPrepare(___) Sequential vs parallel run (show tstart).

example

[numpool, tstart, progbar] =PoolPrepare(___) Sequential vs parallel run (show progbar).

example

[numpool, tstart, progbar, usePCT] =PoolPrepare(___) Sequential vs parallel run (show usePCT).

example

[numpool, tstart, progbar, usePCT, usematlabpool] =PoolPrepare(___) Sequential vs parallel run (show usematlabpool).

Examples

expand all

  • Sequential vs parallel run.
  • n = 50000;
    x = randn(1,n) ;
    y = zeros(1,n);
    % sequential run
    tic
    for i = 1 : n
    y(i) = std(x(1:i));
    end
    fprintf('\n\n\n  Normal for: %f secs \n \n ',toc);
    % parallel run
    numpool = 4;
    pariter = n;
    UserOptions = {};
    [numpool, tstart, progbar, usePCT, usematlabpool] = ...
    PoolPrepare(numpool,pariter,UserOptions);
    parfor i = 1 : n
    y(i) = std(x(1:i));
    end
    cleanpool = 1; % this closes the pool of MATLAB sessions
    tend = PoolClose(cleanpool, tstart, progbar, usePCT,  usematlabpool);
    fprintf('\n\n\n      parFor: %f secs\n\n',tend);

  • Sequential vs parallel run (show tstart).
  • n = 50000;
    x = randn(1,n) ;
    y = zeros(1,n);
    % sequential run
    tic
    for i = 1 : n
    y(i) = std(x(1:i));
    end
    fprintf('\n\n\n  Normal for: %f secs \n \n ',toc);
    % parallel run
    numpool = 4;
    pariter = n;
    UserOptions = {};
    [numpool, tstart, progbar, usePCT, usematlabpool] = ...
    PoolPrepare(numpool,pariter,UserOptions);
    disp(tstart)
    parfor i = 1 : n
    y(i) = std(x(1:i));
    end
    cleanpool = 1; % this closes the pool of MATLAB sessions
    tend = PoolClose(cleanpool, tstart, progbar, usePCT,  usematlabpool);
    fprintf('\n\n\n      parFor: %f secs\n\n',tend);

  • Sequential vs parallel run (show progbar).
  • n = 50000;
    x = randn(1,n) ;
    y = zeros(1,n);
    % sequential run
    tic
    for i = 1 : n
    y(i) = std(x(1:i));
    end
    fprintf('\n\n\n  Normal for: %f secs \n \n ',toc);
    % parallel run
    numpool = 4;
    pariter = n;
    UserOptions = {};
    [numpool, tstart, progbar, usePCT, usematlabpool] = ...
    PoolPrepare(numpool,pariter,UserOptions);
    % show progrbar
    disp(progbar)
    parfor i = 1 : n
    y(i) = std(x(1:i));
    end
    cleanpool = 1; % this closes the pool of MATLAB sessions
    tend = PoolClose(cleanpool, tstart, progbar, usePCT,  usematlabpool);
    fprintf('\n\n\n      parFor: %f secs\n\n',tend);

  • Sequential vs parallel run (show usePCT).
  • n = 50000;
    x = randn(1,n) ;
    y = zeros(1,n);
    % sequential run
    tic
    for i = 1 : n
    y(i) = std(x(1:i));
    end
    fprintf('\n\n\n  Normal for: %f secs \n \n ',toc);
    % parallel run
    numpool = 4;
    pariter = n;
    UserOptions = {};
    [numpool, tstart, progbar, usePCT, usematlabpool] = ...
    PoolPrepare(numpool,pariter,UserOptions);
    disp(usePCT)
    parfor i = 1 : n
    y(i) = std(x(1:i));
    end
    cleanpool = 1; % this closes the pool of MATLAB sessions
    tend = PoolClose(cleanpool, tstart, progbar, usePCT,  usematlabpool);
    fprintf('\n\n\n      parFor: %f secs\n\n',tend);

  • Sequential vs parallel run (show usematlabpool).
  • n = 50000;
    x = randn(1,n) ;
    y = zeros(1,n);
    % sequential run
    tic
    for i = 1 : n
    y(i) = std(x(1:i));
    end
    fprintf('\n\n\n  Normal for: %f secs \n \n ',toc);
    % parallel run
    numpool = 4;
    pariter = n;
    UserOptions = {};
    [numpool, tstart, progbar, usePCT, usematlabpool] = ...
    PoolPrepare(numpool,pariter,UserOptions);
    disp(usematlabpool)
    parfor i = 1 : n
    y(i) = std(x(1:i));
    end
    cleanpool = 1; % this closes the pool of MATLAB sessions
    tend = PoolClose(cleanpool, tstart, progbar, usePCT,  usematlabpool);
    fprintf('\n\n\n      parFor: %f secs\n\n',tend);

    Input Arguments

    expand all

    numpool — The number of parallel sessions to open. Integer.

    If numpool is not defined, then it is set equal to the number of physical cores in the computer.

    Data Types: scalar

    pariter — Number of parfor loops that need to be monitored. Integer.

    If pariter > 0, then the 'pariter' parallel instancies executed in a parfor statement will be monitored with a progress bar. If pariter is 0 or is not defined, then the progression of the parallel execution is not monitored.

    Data Types: scalar

    UserOptions — Structure containing the user options of the calling function. Cell array of strings.

    It is used, for example, to check if the user has specified numpool or not, and proceed accordingly (i.e. use the number of workers set in the current MATLAB profile, rather then allocate the numpool MATLAB instances requested by the user).

    Data Types: cell array of strings

    Output Arguments

    expand all

    numpool —The number of parallel sessions actually opened. Integer

    They may differ from the request of the user, depending on the computer configuration.

    Data Types - double

    tstart —Time stamp to be given as input to PoolClose. Double

    Records the internal computer time at the end of the execution of the PoolPrepare function, so that to monitor the overall execution time of the statements embedded between PoolPrepare and PoolClose.

    Data Types - double

    progbar —To be given as input to PoolClose. Structure or integer

    Contains the status of the progress bar used to monitor the progression of the parallel execution.

    Data Types - struct | double Optional Output:

    usePCT —Boolean indicating if the parallel computing toolbox is installed. Scalar {0,1}

    Parpool checks for the existence of the parallel computing toolbox. 'usePCT' returns the result of the check to PoolClose, to avoid additional unnecessary checks.

    Data Types - integer | logical

    usematlabpool —Boolean indicating the use of 'usematlabpool' or 'parpool'. Scalar {0,1}

    Boolean indicating if the pool of MATLAB instances is created using 'matlabpool' or 'parpool', depending on the MATLAB version installed. From R2013b 'parpool' is used. Earlier releases use 'usematlabpool'.

    Data Types - integer | logical

    References

    See Also

    |

    This page has been automatically generated by our routine publishFS