RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • codistributed
    • codistributed.build
    • codistributor
    • codistributor1d
    • codistributor2dbc
    • distributed
    • fetchNext
    • fetchOutputs
    • gcat
    • gcp
    • getCodistributor
    • getCurrentJob
    • getCurrentTask
    • getCurrentWorker
    • getLocalPart
    • globalIndices
    • gop
    • gplus
    • iscodistributed
    • isComplete
    • labBarrier
    • labBroadcast
    • labindex
    • labProbe
    • labReceive
    • labSend
    • labSendReceive
    • numlabs
    • parfeval
    • parfevalOnAll
    • parpool
    • redistribute
    • spmdBarrier
    • spmdBroadcast
    • spmdCat
    • spmdIndex
    • spmdPlus
    • spmdProbe
    • spmdReceive
    • spmdReduce
    • spmdSend
    • spmdSendReceive
    • spmdSize

numlabs — Return the number of labs in the current SPMD gang.

numlabs is the compatible lab-oriented name for the size returned by spmdSize.

Syntax

size = numlabs

Returns

size
Type
NumericScalar
Description
Number of workers in the current SPMD group.
NameTypeDescription
sizeNumericScalarNumber of workers in the current SPMD group.

Errors

RunMat:numlabs:TooManyOutputs
When
More than one output is requested.
Message
numlabs: too many output arguments
IdentifierWhenMessage
RunMat:numlabs:TooManyOutputsMore than one output is requested.numlabs: too many output arguments

Behavior

Each admitted worker in an spmd region has a stable one-based rank and observes the same gang size. spmdIndex and its labindex alias return the rank; spmdSize and its numlabs alias return the size.

The values are ordinary scalar doubles inside the worker. When assigned in an spmd region, the driver receives one value per worker in a Composite, like other worker-local outputs.

Outside an active spmd gang, the serial context is rank 1 of size 1. This makes helper functions that inspect the context usable in both serial and SPMD execution.

Each name accepts no inputs and produces one scalar double. An unrequested result may be discarded; requesting more than one output is an error.

Execution placement

The values come from the active typed collective context. Reading them does not communicate with another worker, move array data, or invoke an accelerator provider.

Example

Use the compatible lab-count name

pool = parpool(2);
spmd
  count = numlabs;
end

Expected output:

each worker reports count = 2

Using numlabs with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how numlabs changes the result.

Run a small numlabs example, explain the result, then change one input and compare the output.

FAQ

Are worker indices zero-based or one-based?⌄

They are one-based and range from 1 through the active gang size.

Can the rank change during one SPMD region?⌄

No. Admission fixes each worker's rank for the lifetime of that region.

Do these functions synchronize workers?⌄

No. They only read the current worker's collective context.

What do they return outside SPMD?⌄

The serial context reports rank 1 and size 1.

Related Parallel functions

codistributed · codistributed.build · codistributor · codistributor1d · codistributor2dbc · distributed · fetchNext · fetchOutputs · gcat · gcp · getCodistributor · getCurrentJob · getCurrentTask · getCurrentWorker · getLocalPart · globalIndices · gop · gplus · iscodistributed · isComplete · labBarrier · labBroadcast · labindex · labProbe · labReceive · labSend · labSendReceive · parfeval · parfevalOnAll · parpool · redistribute · spmdBarrier · spmdBroadcast · spmdCat · spmdIndex · spmdPlus · spmdProbe · spmdReceive · spmdReduce · spmdSend · spmdSendReceive · spmdSize

Related guides

  • Parallel execution

Source you can read

Every RunMat function's source is public. Read exactly how numlabs is executed, line by line, in Rust.

  • View the source for numlabs in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Returns
  • Errors
  • Behavior
  • Execution placement
  • Example
  • Use the compatible lab-count name
  • Using numlabs with coding agents
  • FAQ
  • Related Parallel functions
  • Related guides
  • Source you can read
  • About RunMat