For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
sync_parallelize
sync_parallelize[origins: OriginSet, //, func: def(Int) raises capturing -> None](num_work_items: Int, ctx: Optional[DeviceContext] = None)
Executes func(0) ... func(num_work_items-1) as parallel sub-tasks, and returns when all are complete.
TODO: Currently exceptions raised by func will cause a trap rather than be propagated back to the caller.
Parameters:
- origins (
OriginSet): The capture origins. - func (
def(Int) raises capturing -> None): The function to invoke.
Args:
- num_work_items (
Int): Number of parallel tasks. - ctx (
Optional[DeviceContext]): Optional CPU DeviceContext to execute the tasks on.
sync_parallelize[FuncType: def(Int) register_passable -> None](func: FuncType, num_work_items: Int, ctx: Optional[DeviceContext] = None)
Executes func(0) ... func(num_work_items-1) as parallel sub-tasks, and returns when all are complete.
Parameters:
- FuncType (
def(Int) register_passable -> None): The body function type.
Args:
- func (
FuncType): The closure carrying the captured state of the body function. - num_work_items (
Int): Number of parallel tasks. - ctx (
Optional[DeviceContext]): The CPU DeviceContext to enqueue the work on.