spmdIndex
Syntax
Description
returns the index of the worker
currently executing the function in an id = spmdIndexspmd block or a communicating job. When workers run an spmd
block or a communicating job begins execution, a unique index is assigned to each worker.
The value of spmdIndex is an integer between 1 and
the number of workers running in the current spmd block or
communicating job. To get the number of workers running the current spmd block, use the
spmdSize
function.
A worker gets the same value id inside every
spmd block for the duration of a parallel pool.
Examples
Output Arguments
Tips
In an spmd block, because you have access to all workers individually
and control what the workers execute, each worker has a unique index.
However, inside a parfor-loop, spmdIndex always
returns a value of 1 on all workers in all iterations.
Extended Capabilities
Version History
Introduced in R2022b