Nimony

The road to Nim 3

parfor

nimony/lib/std/parfor.nim

Structured data parallelism: for i in a || b: x[i] = f(input[i]).

The || iterator is a for-loop plugin: at sem time the plugin rewrites the loop into a set of chunk runners submitted to the shared std/threadpool worker pool plus a structured join at the loop's closing. The join is the loop end -- there is no spawn, no Flowvar, no handle, and (by construction of the static race rules) no data race.

A chunk runner is a .passive coroutine, so an iteration that performs I/O parks its worker instead of pinning it -- the parallel for therefore covers I/O-bound maps, not just CPU-bound ones.

This module provides the runtime the lowering targets; see deps/parfor.nim for the plugin that emits calls into it.