Next: , Previous: , Up: Miscellaneous   [Contents]


3.3.2 Parallel Execution

It is possible to run pipelines in parallel.

(use-module (ice-9 threads))
(par-map run-blocks `((,a ,b)
                      (,c))) ;=> (list (run-blocks `(,a ,b)) (run-blocks `(,c)))
;; Alternatively
(use-module (blocks utils))
(parallel-pipelines `((,a ,b)
                      (,c))) ;=> (list (run-blocks `(,a ,b)) (run-blocks `(,c)))

parallel-pipelines also has a variant form, parallel-pipelines*. Instead of returning results in a list, results are returned as multiple values. This allows for conveniently binding the results into separate variables.

(define-values (a b)
  (parallel-pipelines* `(,pipeline1
                         ,pipeline2)))
a ;=> (run-blocks pipeline1)
b ;=> (run-blocks pipeline2)