labindex

Index of this worker

Syntax

id = labindex

Description

id = labindex returns the index of the worker currently executing the function. labindex is assigned to each worker when a job begins execution, and applies only for the duration of that job. The value of labindex spans from 1 to n, where n is the number of workers running the current job, defined by numlabs.

More About

expand all

Tips

In an spmd block, because you have access to all workers individually and control what gets executed on them, each worker has a unique labindex.

However, inside a parfor-loop, labindex always returns a value of 1.

Was this topic helpful?