Main Content

parpool

Create parallel pool on cluster

Syntax

Description

parpool starts a parallel pool of workers using the default profile. With default settings, MATLAB® starts a pool on the local machine with one worker per physical CPU core up to the limit set in the default profile. For more information on parallel settings, see Specify Your Parallel Settings.

In general, the pool size is specified by the PreferredPoolNumWorkers property of the default profile. For all factors that can affect your pool size, see Factors That Affect Pool Size.

parpool enables the full functionality of the parallel language features in MATLAB by creating a special job on a pool of workers, and connecting the MATLAB client to the parallel pool. Parallel language features include parfor, parfeval, parfevalOnAll, spmd, and distributed. If possible, the working folder on the workers is set to match that of the MATLAB client session.

example

parpool(poolsize) creates and returns a pool with the specified number of workers. poolsize can be a positive integer or a range specified as a 2-element vector of integers. If poolsize is a range, the resulting pool has size as large as possible in the range requested.

Specifying the poolsize overrides any value specified in the PreferredPoolNumWorkers property, and starts a pool of exactly that number of workers, even if it has to wait for them to be available. Most clusters have a maximum number of workers they can start. If the profile specifies a MATLAB Job Scheduler cluster, parpool reserves its workers from among those already running and available under that MATLAB Job Scheduler. If the profile specifies a local or third-party scheduler, parpool instructs the scheduler to start the workers for the pool.

example

parpool(resources) or parpool(resources,poolsize) starts a worker pool on the resources specified by resources.

example

parpool(___,Name=Value) applies the specified values for certain properties when starting the pool.

example

poolobj = parpool(___) returns a parallel.Pool object to the client workspace representing the pool on the cluster. You can use the pool object to programmatically delete the pool or to access its properties. Use delete(pool) to shut down the parallel pool.

example

Examples

collapse all

Start a parallel pool using the default profile to define the number of workers. With default settings, the default pool is on the local machine.

parpool

You can create pools on different types of parallel environments on your local machine.

  • Start a parallel pool of process workers.

    parpool("Processes")
  • Start a parallel pool of 4 thread workers.

    parpool("Threads",4)

For more information on parallel environments, see Choose Between Thread-Based and Process-Based Environments.

Start a parallel pool of 16 workers using a profile called myProf.

parpool("myProf",16)

Create an object representing the cluster identified by the default profile, and use that cluster object to start a parallel pool. The pool size is determined by the default profile.

c = parcluster
parpool(c)

Start a parallel pool with the default profile, and pass two code files to the workers.

parpool(AttachedFiles=["mod1.m","mod2.m"])

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant