A parallel pool is a set of MATLAB® workers on a compute cluster or desktop. By default, a parallel pool
starts automatically when needed by parallel language features such as
parfor
. You can specify the default pool size and cluster
in your parallel preferences. The preferences panel displays your pool size and
cluster when you select Parallel Preferences in the
Parallel menu. You can change pool size and cluster
in the Parallel menu. Alternatively, you can choose
cluster and pool size using parcluster
and
parpool
respectively, on the MATLAB command line. See the image for more detail.
The workers in a parallel pool can be used interactively and communicate with
each other during the lifetime of the job. You can view your
parpool
jobs in the Job Monitor. While these pool
workers are reserved for your interactive use, they are not available to other
users. You can have only one parallel pool at a time from a MATLAB client session. In MATLAB, the current parallel pool is represented by a parallel.Pool object.
By default, a parallel pool starts automatically when needed by certain parallel language features. Many functions can automatically start a parallel pool, including:
Your parallel preferences specify which cluster the pool runs on, and the preferred number of workers in the pool. To access your preferences, on the Home tab, in the Environment section, click Parallel > Parallel Preferences.
In your parallel preferences, you can turn off the option for the pool to open or close automatically. If you choose not to have the pool open automatically, you can control the pool with the following techniques.
You can use the parallel status indicator in the lower left corner of the MATLAB desktop to start a parallel pool manually.
In MATLAB Online, the parallel status indicator is not visible by
default. You must start a parallel pool first by using parpool
or any of the functions
that automatically start a parallel pool.
Click the indicator icon, and select Start Parallel Pool. The pool size and cluster are specified by your parallel preferences and default cluster. Your default cluster is indicated by a check mark on the Parallel > Default Cluster menu.
The menu options are different when a pool is running. You can:
View the number of workers and cluster name
Change the time until automatic shut-down
Shut down the parallel pool
To stop a pool, you can also select Shut Down Parallel Pool.
Start a Parallel Pool. You can start and stop a parallel pool programmatically by using default settings or specifying alternatives.
To open a parallel pool based on your preference settings:
parpool
To open a pool of a specific size:
parpool(4)
To use a cluster other than your default and specify where the pool runs:
parpool('MyCluster',4)
You can run a parallel pool on different parallel environments. For more information, see Choose Between Thread-Based and Process-Based Environments.
Shut Down a Parallel Pool. To get the current parallel pool and use that object when you want to shut down the pool:
p = gcp; delete(p)
Ensure That No Parallel Pool Is Running. When you issue the command gcp
without arguments, you
might inadvertently open a pool. To avoid this problem:
delete(gcp('nocreate'))
There are several places to specify pool size. Several factors might limit the size of a pool. The actual size of your parallel pool is determined by the combination of the following:
Licensing or cluster size
The maximum limit on the number of workers in a pool is restricted by the number of workers in your cluster. This limit might be determined by the number of MATLAB Parallel Server™ licenses available. In the case of MATLAB Job Scheduler, the limit might be determined by the number of workers running in the cluster. A local cluster running on the client machine requires no licensing beyond the one for Parallel Computing Toolbox™. The limit on the number of workers is high enough to support the range of known desktop hardware.
Cluster profile number of workers (NumWorkers
)
A cluster object can set a hard limit on the number of workers, which you specify in the cluster profile. Even if you request more workers at the command line or in your preferences, you cannot exceed the limit set in the applicable profile. Attempting to exceed this number generates an error.
Command-line argument
If you specify a pool size at the command line, you override the setting of your preferences. This value must fall within the limits of the applicable cluster profile.
Parallel preferences
If you do not specify a pool size at the command line, MATLAB attempts to start a pool with size determined by your parallel preferences. This value is a preference, not a requirement or a request for a specific number of workers. So if a pool cannot start with as many workers as called for in your preferences, you get a smaller pool without any errors. You can set the value of the Preferred number of workers to a large number, so that it never limits the size of the pool that is created. If you need an exact number of workers, specify the number at the command line.
For selection of the cluster on which the pool runs, precedence is determined by the following.
The command-line cluster object argument overrides the default profile
setting and uses the cluster identified by the profile
'MyProfile'
.
c = parcluster('MyProfile');
p = parpool(c);
The cluster is specified in the default profile.
p = parpool;
delete
| distributed
| gcp
| parcluster
| parfeval
| parfor
| parpool
| spmd