std.parallel

Collection work distributed across CPU cores.

Importuse std.parallel

Functions

extern fn cpu_count() -> int#

Returns the number of logical CPUs available.

fn map<T, R>(entry: string, items: [T]) -> [R]#

Maps values through an isolate entry point in parallel.

  • entry: Name of the isolate entry point applied to each item.
  • items: Values to map, one isolate per item.
fn square(value: int) -> int { value * value }

fn main() {
  println(std.parallel.cpu_count())
  println(std.parallel.map("square", [1, 2, 3, 4]))
  std.parallel.each("square", [5, 6])
}
fn each<T>(entry: string, items: [T])#

Runs an isolate entry point for every value in parallel.

  • entry: Name of the isolate entry point run for each item.
  • items: Values to visit, one isolate per item.
fn map<T, R>(entry: string, items: [T]) -> [R]#

Maps values through an isolate entry point in parallel.

  • entry: Name of the isolate entry point applied to each item.
  • items: Values to map, one isolate per item.
fn square(value: int) -> int { value * value }

fn main() {
  println(std.parallel.cpu_count())
  println(std.parallel.map("square", [1, 2, 3, 4]))
  std.parallel.each("square", [5, 6])
}
fn workers(entry: string, count: int)#

Runs the requested number of long-lived isolate workers.

  • entry: Name of the isolate entry point each worker runs.
  • count: How many long-lived workers to start.
fn worker(lane: int) -> int {
  println("worker ${lane}")
  lane
}

fn main() {
  // Use 0 to start one long-lived isolate per logical CPU.
  std.parallel.workers("worker", 2)
}