Skip to Main Content Skip to Search
Product Documentation

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(poolsize)
matlabpool configname
matlabpool configname poolsize
matlabpool(schedobj)
matlabpool(schedobj, 'open')
matlabpool(schedobj, 'open', ...)
matlabpool(schedobj, 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 Parallel Configurations for Cluster Access.) You can also specify the pool size using matlabpool open poolsize, but most schedulers have a maximum number of processes that they can start (12 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(poolsize), matlabpool configname, and matlabpool configname poolsize operate as matlabpool open ..., and are provided for convenience.

matlabpool(schedobj) or matlabpool(schedobj, 'open') is the same as matlabpool open, except that the worker pool is started on the scheduler specified by the object schedobj.

matlabpool(schedobj, 'open', ...) is the same as matlabpool('open', ...) except that the worker pool is started on the scheduler specified by the object schedobj.

matlabpool(schedobj, poolsize) is the same as matlabpool poolsize except that the worker pool is started on the scheduler specified by the object schedobj.

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, such as configuration name and pool size. The default is 'open'. For example, the following are equivalent:

matlabpool open MyConfig 4
matlabpool('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. The 'FileDependencies' property name is case sensitive, and must appear as shown. (Note: This form of the command does not allow you to directly specify any other job property-value pairs when opening a pool.)

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).

Tips

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

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.

Another difference between client and workers is that any addpath arguments that are part of the matlabroot folder are not set on the workers. The assumption is that the MATLAB install base is already included in the workers' paths. The rules for addpath regarding workers in the pool are:

For example, suppose that matlabroot on the client is C:\Applications\matlab\. With an open MATLAB pool, execute the following to set the path on the client and all workers:

addpath('P1',
        'P2',
        'C:\Applications\matlab\T3',
        'C:\Applications\matlab\T4',
        'P5',
        'C:\Applications\matlab\T6',
        'P7',
        'P8');

Because T3, T4, and T6 are subfolders of matlabroot, they are not set on the workers' paths. So on the workers, the pertinent part of the path resulting from this command is:

P1
P2
<worker original matlabroot folders...>
P5
P7
P8

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 code files to the workers:

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

Start a MATLAB pool with the scheduler and pool size determined by the default configuration:

schd = findResource('scheduler', ...
                    'configuration', defaultParallelConfig);
matlabpool(schd)

See Also

defaultParallelConfig | parfor | pctRunOnAll

  


Free Parallel Computing Interactive Kit

See how to solve large problems with minimal effort and reduce simulation time.

Get free kit

Trials Available

Try the latest versions of parallel computing products.

Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS