Import std.concurrent.parallel
std.concurrent.parallel
The parallel algorithms: ParallelForEach, ParallelMap, ParallelReduce, and ParallelSort, each a Parallel For on the job pool, with the calling thread taking its share, over an array of Sendable values and a Sendable Func, which each pass calls on the thread that runs it. What they give comes back in the items' order, the same as their plain loops would give, whichever thread does which part.
std/concurrent/parallel.fb
Functions
ParallelForEach
function
Public Function ParallelForEach<T: Sendable>(items: T[], action: Sendable Func(T))
Calls action with each item, on the pool at once, in no order.
ParallelMap
function
Public Function ParallelMap<T, R>(items: T[], change: Sendable Func(T): R): R[]
A new array of what change makes of each item, in the items' order, made on the pool at
once.
ParallelReduce
function
Public Function ParallelReduce<T: Sendable>(items: T[], combine: Sendable Func(T, T): T): T?
The items combined with combine, which takes two values and gives one, or Null for no items.
They're cut into parts, each combined left to right on the pool at once, and then the parts'
values left to right, so combine must give the same however its calls are grouped, as + and
Max do, though it needn't let its values swap places.
ParallelSort
function
Public Function ParallelSort<T>(items: T[])
Sorts the items in place, smallest first, keeping equal ones in their order, as T[]'s Sort
does: parts sorted on the pool at once, then merged in pairs, each round's merges at once too.
A value that isn't equal to itself, like NaN, has no place in the order, and goes where it may.
ParallelSort
function
Public Function ParallelSort<T: Sendable>(items: T[], before: Sendable Func(T, T): Bool)
Sorts the items in place, those before goes with first, keeping in their order the ones it
puts neither before the other, as Sort(before) does.
Report an issue with this page or with FutureBlitz on GitHub.