arrays.parallel #
fn amap #
fn amap[T, R](input []T, worker fn (T) R, opt Params) []R
amap lets the user run an array of input with a user provided function in parallel. It limits the number of worker threads to max number of cpus. The worker function can return a value. The returning array maintains the input order. Any error handling should have happened within the worker function.
Example
squares := parallel.amap([1, 2, 3, 4, 5], 2, fn (i) { return i * i })
fn run #
fn run[T](input []T, worker fn (T), opt Params)
run lets the user run an array of input with a user provided function in parallel. It limits the number of worker threads to min(num_workers, num_cpu) The function aborts if an error is encountered.
Example
parallel.run([1, 2, 3, 4, 5], 2, fn (i) { println(i) })
struct Params #
@[params]
struct Params {
pub mut:
workers int // 0 by default, so that VJOBS will be used, through runtime.nr_jobs()
}
Params contains the optional parameters that can be passed to run
and amap
.