spmdSize - Number of workers running current spmd block - MATLAB (original) (raw)

Main Content

Number of workers running current spmd block

Since R2022b

Syntax

Description

[n](#mw%5F686276a8-cd4e-424d-b9d9-bf109eebc09a) = spmdSize returns the number of workers running the current spmd block or communicating job. This value is the maximum value that you can use as the destination input to spmdSend and source input to spmdReceive.

example

Examples

collapse all

This example shows how to run spmdSize inside and outside an spmd block.

Create a parallel pool with four workers.

When you execute an spmd block after creating a parallel pool, by default all available workers in the pool run the code inside thespmd block.

Run spmdSize inside and outside an spmd block. In the block, the returned value is equal to the number of workers. Outside the block, the returned value is 1.

spmd disp(spmdSize) end disp(spmdSize)

Worker 1: 4

Worker 2: 4

Worker 3: 4

Worker 4: 4

 1

Output Arguments

collapse all

Number of workers running the current spmd block or communicating job, returned as a positive integer. In an spmd block,n is the number of workers running the spmd block. Outside an spmd block, n is1.

When you create a communicating job using createCommunicatingJob, you can run a function or script onn workers. When one of the workers runsspmdSize, the returned value is n.

Extended Capabilities

Version History

Introduced in R2022b