System.Parallel
Work spread over the workers that run tasks (System.Task): a function of
each element of an array, and a graph of steps each run once the steps it
depends on have finished.
Each runs its function concurrently with itself when there is more than one worker, so what the calls share must be safe to share: reading data nothing writes meanwhile, and writing only what is the call's own. Every result is the function's, in the order of the input, whatever order the calls ran in.
With one worker each is the sequential loop it stands for, in order, with no tasks.
Work is split into chunks, a few per worker, each one task that runs its elements in turn. A task is a coroutine with a stack of its own, so a task per element would hold as many stacks as there are elements.
How many workers run tasks, the program's own included.
f of each of xs, in order.
map, with state of each chunk's own: perChunk() is made once for the
elements one task runs, in turn, and each call is given it. Scratch space
worth reusing across elements is the use, and so a call's result must not
depend on what an earlier one left in it.
f of each of xs, for what it does.
f of each of xs, each result handed to use with its index, in order,
on the caller, as soon as it and every result before it are made. At most a
few chunks per worker are made ahead of the one use is waiting for, so
the results held at once stay bounded however many elements there are.
The steps of a dependency graph, run once each.
Step i runs, as run(i, finished), once every step dependsOn(i) names
has finished; finished(j) is step j's result, for any step i depends
on. The results are in step order. A cycle among the steps is an error,
found before any step runs.
One task per worker takes ready steps from a queue, rather than a task per step waiting on its dependencies: a waiting task holds its stack.
graph, with state of each worker's own: perWorker() is made once for
each task taking steps, and every step that task runs is given it. A cache
of answers that do not depend on which steps have run is the use: a step
may run on any worker, so what it finds there must not change its result.