Products & Services Solutions Academia Support User Community Company

Learn more about Parallel Computing Toolbox   

matlabpool - Open or close pool of MATLAB sessions for parallel computation

Syntax

matlabpool
matlabpool open
matlabpool open poolsize
matlabpool open configname
matlabpool open configname poolsize
matlabpool poolsize
matlabpool configname
matlabpool configname poolsize
matlabpool close
matlabpool close force
matlabpool close force configname
matlabpool size
matlabpool('open', ...)
matlabpool('close', ...)
matlabpool('open',..., 'FileDependencies', filecell)
matlabpool('addfiledependencies', filecell)
matlabpool updatefiledependencies

Description

matlabpool enables the parallel language features in the MATLAB language (e.g., parfor) by starting a parallel job that connects this MATLAB client with a number of labs.

matlabpool or matlabpool open starts a worker pool using the default parallel configuration, with the pool size specified by that configuration. (For information about setting up and selecting parallel configurations, see Programming with User Configurations.) You can also specify the pool size using matlabpool open poolsize, but most schedulers have a maximum number of processes that they can start (8 for a local scheduler). If the configuration specifies a job manager as the scheduler, matlabpool reserves its workers from among those already running and available under that job manager. If the configuration specifies a third-party scheduler, matlabpool instructs the scheduler to start the workers.

matlabpool open configname or matlabpool open configname poolsize starts a worker pool using the Parallel Computing Toolbox user configuration identified by configname rather than the default configuration to locate a scheduler. If the pool size is specified, it overrides the maximum and minimum number of workers specified in the configuration, and starts a pool of exactly that number of workers, even if it has to wait for them to be available.

Without specifying open or close, the command default is open. So, matlabpool poolsize, matlabpool configname, and matlabpool configname poolsize operate as matlabpool open ..., and are provided for convenience.

matlabpool close stops the worker pool, destroys the parallel job, and makes all parallel language features revert to using the MATLAB client for computing their results.

matlabpool close force destroys all parallel jobs created by matlabpool for the current user under the scheduler specified by the default configuration, including any jobs currently running.

matlabpool close force configname destroys all parallel jobs being run under the scheduler specified in the configuration configname.

matlabpool size returns the size of the worker pool if it is open, or 0 if the pool is closed.

matlabpool('open', ...) and matlabpool('close', ...) can be invoked as functions with optional arguments. The default is 'open'. For example, the following are equivalent:

matlabpool open MyConfig 4
matlabpool('open', 'MyConfig', 4)

matlabpool('open',..., 'FileDependencies', filecell) starts a worker pool and allows you to specify file dependencies so that you can pass necessary files to the workers in the pool. The cell array filecell is appended to the FileDependencies specified in the configuration used for startup.

matlabpool('addfiledependencies', filecell) allows you to add extra file dependencies to an already running pool. filecell is a cell array of strings, identical in form to those you use when adding file dependencies to a job or when you open a MATLAB pool. Each string can specify either absolute or relative files, directories, or a file on the MATLAB path. The command transfers the files to each worker, placing the files in the file dependencies directory, exactly the same as if you set them at the time the pool was opened.

matlabpool updatefiledependencies checks all the file dependencies of the current pool to see if they have changed, and replicates any changes to each of the labs in the pool. In this way, you can send code changes out to remote labs. This checks dependencies that you added with the matlabpool addfiledependencies command as well as those you specified when the pool was started (by a configuration or command-line argument).

Remarks

When a pool of workers is open, the following commands entered in the client's Command Window also execute on all the workers:

cd
addpath
rmpath

This enables you to set the working directory and the path on all the workers, so that a subsequent parfor-loop executes in the proper context.

If any of these commands does not work on the client, it is not executed on the workers either. For example, if addpath specifies a directory that the client cannot see or access, the addpath command is not executed on the workers. However, if the working directory or path can be set on the client, but cannot be set as specified on any of the workers, you do not get an error message returned to the client Command Window.

This slight difference in behavior is an issue especially in a mixed-platform environment where the client is not the same platform as the workers, where directories local to or mapped from the client are not available in the same way to the workers, or where directories are in a nonshared file system. For example, if you have a MATLAB client running on a Microsoft Windows operating system while the MATLAB workers are all running on Linux® operating systems, the same argument to addpath cannot work on both. In this situation, you can use the function pctRunOnAll to assure that a command runs on all the workers.

Examples

Start a pool using the default configuration to define the number of labs:

matlabpool

Start a pool of 16 labs using a configuration called myConf:

matlabpool open myConf 16

Start a pool of 2 labs using the local configuration:

matlabpool local 2

Run matlabpool as a function to check whether the worker pool is currently open:

isOpen = matlabpool('size') > 0

Start a pool with the default configuration, and pass two M-files to the workers:

matlabpool('open', 'FileDependencies', {'mod1.m', 'mod2.m'})

See Also

defaultParallelConfig, pctRunOnAll, parfor

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS