The functions described in this section are available from
(use-modules (ice-9 threads))
Evaluate each expr expression in parallel, each in its own thread. Return the results as a set of N multiple values (see Multiple Values).
Evaluate each expr in parallel, each in its own thread, then bind the results to the corresponding var variables and evaluate body.
let(see Local Bindings), but all the expressions for the bindings are evaluated in parallel.
Call proc on the elements of the given lists.
par-mapreturns a list comprising the return values from proc.
par-for-eachreturns an unspecified value, but waits for all calls to complete.
The proc calls are
), where each elem is from the corresponding lst. Each lst must be the same length. The calls are made in parallel, each in its own thread.
These functions are like
for-each(see List Mapping), but make their proc calls in parallel.
Call proc on the elements of the given lists, in the same way as
par-for-eachabove, but use no more than n threads at any one time. The order in which calls are initiated within that threads limit is unspecified.
These functions are good for controlling resource consumption if proc calls might be costly, or if there are many to be made. On a dual-CPU system for instance n=4 might be enough to keep the CPUs utilized, and not consume too much memory.
Apply pproc to the elements of the given lists, and apply sproc to each result returned by pproc. The final return value is unspecified, but all calls will have been completed before returning.
The calls made are
)), where each elem is from the corresponding lst. Each lst must have the same number of elements.
The pproc calls are made in parallel, in separate threads. No more than n threads are used at any one time. The order in which pproc calls are initiated within that limit is unspecified.
The sproc calls are made serially, in list element order, one at a time. pproc calls on later elements may execute in parallel with the sproc calls. Exactly which thread makes each sproc call is unspecified.
This function is designed for individual calculations that can be done in parallel, but with results needing to be handled serially, for instance to write them to a file. The n limit on threads controls system resource usage when there are many calculations or when they might be costly.
It will be seen that
n-for-each-par-mapis like a combination of
for-each,(for-each sproc (n-par-map n pproc lst1 ... lstN))
But the actual implementation is more efficient since each sproc call, in turn, can be initiated once the relevant pproc call has completed, it doesn't need to wait for all to finish.