IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: 1.0.0b1
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).

parallelize

parallelize[origins: OriginSet, //, func: def(Int) capturing -> None](num_work_items: Int, ctx: Optional[DeviceContext] = None)

Executes func(0) ... func(num_work_items-1) as sub-tasks in parallel, and returns when all are complete.

Parameters:

  • origins (OriginSet): The capture origins.
  • func (def(Int) capturing -> None): The function to invoke.

Args:

  • num_work_items (Int): Number of parallel tasks.
  • ctx (Optional[DeviceContext]): Optional CPU DeviceContext to execute the work on.

parallelize[origins: OriginSet, //, func: def(Int) capturing -> None](num_work_items: Int, num_workers: Int, ctx: Optional[DeviceContext] = None)

Executes func(0) ... func(num_work_items-1) as sub-tasks in parallel, and returns when all are complete.

Parameters:

  • origins (OriginSet): The capture origins.
  • func (def(Int) capturing -> None): The function to invoke.

Args:

  • num_work_items (Int): Number of parallel tasks.
  • num_workers (Int): The number of workers to use for execution.
  • ctx (Optional[DeviceContext]): Optional CPU DeviceContext to execute the work on.

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 sub-tasks in parallel, 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]): Optional CPU DeviceContext to execute the work on.

parallelize[FuncType: def(Int) register_passable -> None](func: FuncType, num_work_items: Int, num_workers: Int, ctx: Optional[DeviceContext] = None)

Executes func(0) ... func(num_work_items-1) as sub-tasks in parallel, 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.
  • num_workers (Int): The number of workers to use for execution.
  • ctx (Optional[DeviceContext]): Optional CPU DeviceContext to execute the work on.