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

fetchNext — Return the next completed unread future result.

fetchNext selects a completed unread future by completion order and returns its one-based index followed by requested outputs.

Syntax

[index, outputs...] = fetchNext(futures)
[index, outputs...] = fetchNext(futures, timeout)

Inputs

futures
Type
Any
Required
Yes
Default
—
Description
Future array from which to retrieve the next unread result.
timeout
Type
NumericScalar
Required
Yes
Default
—
Description
Maximum number of seconds to wait for an unread result.
NameTypeRequiredDefaultDescription
futuresAnyYes—Future array from which to retrieve the next unread result.
timeoutNumericScalarYes—Maximum number of seconds to wait for an unread result.

Returns

index
Type
NumericScalar
Description
Linear index of the completed future.
outputs
Type
Any
Description
Outputs produced by the selected future.
NameTypeDescription
indexNumericScalarLinear index of the completed future.
outputsAnyOutputs produced by the selected future.

Returned values from fetchNext depend on how many outputs the caller requests.

Errors

InvalidFutureArray
When
The first argument is not a parallel future scalar or array.
Message
fetchNext expects a parallel.FevalFuture scalar or array
NoUnreadFutures
When
The future array has no unread results.
Message
fetchNext found no unread futures
OutputCountMismatch
When
The caller's requested output count does not match the selected future.
Message
fetchNext output count must match the selected future
InvalidTimeout
When
The timeout is not a finite nonnegative real scalar.
Message
fetchNext timeout must be a finite nonnegative real scalar
IdentifierWhenMessage
InvalidFutureArrayThe first argument is not a parallel future scalar or array.fetchNext expects a parallel.FevalFuture scalar or array
NoUnreadFuturesThe future array has no unread results.fetchNext found no unread futures
OutputCountMismatchThe caller's requested output count does not match the selected future.fetchNext output count must match the selected future
InvalidTimeoutThe timeout is not a finite nonnegative real scalar.fetchNext timeout must be a finite nonnegative real scalar

Behavior

Fetching waits through the session's async execution service. A single future returns the scheduled callable's requested outputs and structured errors; fetching several worker results assembles each output by vertical concatenation by default.

Future arrays retain one-based source indices. fetchNext marks one completed result as read; a timeout can return [] in every requested output slot. fetchOutputs(..., "UniformOutput", false) returns cell arrays instead of concatenating multiple results.

Execution placement

Fetch operations cross the worker-to-client result boundary. Numeric placement after transfer follows the scheduled callable and result-assembly contract rather than a provider rule owned by the fetch builtin.

Example

Read completed futures one at a time

pool = parpool(2);
first = parfeval(pool, @(x) x + 1, 1, 4);
second = parfeval(pool, @(x) x + 2, 1, 8);
futures = first; futures(2) = second;
[index, value] = fetchNext(futures)

Expected output:

index identifies the completed future and value is its result

Using fetchNext with coding agents

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

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

FAQ

Does fetching change output classes?⌄

A single future returns its callable's output. Fetching multiple results concatenates them by default; UniformOutput, false instead returns cells.

Can fetching suspend?⌄

Yes. It waits through the session async runtime until a matching result, timeout, cancellation, or failure is available.

What does UniformOutput control?⌄

For future arrays, false preserves each result in a cell instead of concatenating compatible values.

Can the same result be returned twice by fetchNext?⌄

No. A selected future is marked read before the next completion-order selection.

Related Parallel functions

codistributed · codistributed.build · codistributor · codistributor1d · codistributor2dbc · distributed · 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

Related guides

  • Parallel execution

Source you can read

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

  • View the source for fetchNext 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
  • Inputs
  • Returns
  • Errors
  • Behavior
  • Execution placement
  • Example
  • Read completed futures one at a time
  • Using fetchNext with coding agents
  • FAQ
  • Related Parallel functions
  • Related guides
  • Source you can read
  • About RunMat