parfeval — Schedule one asynchronous function invocation on a pool.
parfeval freezes a callable, output count, and arguments into a typed work request and returns its future.
Syntax
future = parfeval(pool, function, outputs, arguments...)
future = parfeval(function, outputs, arguments...)Inputs
pool- Type
Any- Required
- Yes
- Default
- —
- Description
- Pool on which the function is scheduled.
function- Type
Any- Required
- Yes
- Default
- —
- Description
- Function handle to execute.
outputs- Type
IntegerScalar- Required
- Yes
- Default
- —
- Description
- Number of requested function outputs.
arguments- Type
Any- Required
- Variadic
- Default
- —
- Description
- Arguments supplied to the scheduled function.
function- Type
Any- Required
- Yes
- Default
- —
- Description
- Function handle to execute on the current or automatic pool.
Returns
future- Type
Any- Description
- Future representing the scheduled invocation.
Errors
RunMat:parallel:LoweringRequired- When
- The call bypasses the executor's semantic async lowering path.
- Message
parallel call requires executor-aware lowering
Behavior
The scheduler freezes the callable identity, requested output count, arguments, executable bundle, and pool generation into a typed work request. The returned future records its state, outputs, failure, cancellation, and owning generation.
Omitting the pool uses the current pool or creates an automatic one. Worker and transport failures retain structured error identity and source information; program errors are not retried as infrastructure failures.
Execution placement
Scheduling does not reinterpret the callable on a worker. The worker executes the compiler-owned function identity and transferred values using the host adapter selected by the pool.
Examples
Schedule work on the current or automatic pool
future = parfeval(@(x) x + 1, 1, 4);
answer = fetchOutputs(future)Expected output:
answer = 5Schedule work on an explicit pool
pool = parpool(2);
future = parfeval(pool, @(x) x.^2, 1, 5);
answer = fetchOutputs(future)Expected output:
answer = 25Using parfeval with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how parfeval changes the result.
Run a small parfeval example, explain the result, then change one input and compare the output.
FAQ
What does the output-count argument mean?⌄
It is the number of outputs requested from the scheduled callable and retained by the future.
Can I omit the pool?⌄
Yes. RunMat uses the current compatible pool or creates an automatic pool.
Can a future outlive its pool?⌄
No. It is fenced to the pool generation that scheduled it.
How are worker failures reported?⌄
Structured identifiers, messages, call stacks, and source locations cross the execution boundary.
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 · numlabs · parfevalOnAll · parpool · redistribute · spmdBarrier · spmdBroadcast · spmdCat · spmdIndex · spmdPlus · spmdProbe · spmdReceive · spmdReduce · spmdSend · spmdSendReceive · spmdSize
Related guides
Source you can read
Every RunMat function's source is public. Read exactly how parfeval is executed, line by line, in Rust.
- View the source for parfeval 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.