simple-parallel-tasks
2020-12-20
Evaluate forms in parallel
simple-parallel-tasks
This is a simple Common Lisp library to evaluate some forms in parallel.
1Installation
simple-parallel-tasks requires the chanl library.
1.1With Quicklisp
(ql:quickload "simple-parallel-tasks")
1.2With ASDF
Put the directories of simple-parallel-tasks and the dependencies where ASDF can find them and use:
(asdf:load-system "simple-parallel-tasks")
2API
(defmacro plist (&rest forms))
Evaluate forms in parallel and return the results in a list.
(defmacro pvalues (&rest forms))
Evaluate forms in parallel and return the results as multiple values.
(defmacro plet (bindings &body body))
Like let, but the bindings are evaluated in parallel.
(defmacro pprog1 (first-form &body forms))
Evaluate first-form and forms in parallel and return the result of the evaluation of first-form.
(defmacro pprogn (&rest forms))
Evaluate forms in parallel and return the result of the evaluation of the last form.
3Examples
(time (simple-parallel-tasks:plist 1 (+ 4 5) (sleep 2) 8 (sleep 1) (/ 3 5)))
Evaluation took:
2.004 seconds of real time
(1 9 NIL 8 NIL 3/5)
(time (simple-parallel-tasks:pvalues 1 (+ 4 5) (sleep 2) 8 (sleep 1) (/ 3 5)))
Evaluation took:
2.007 seconds of real time
1
9
NIL
8
NIL
3/5
(time (simple-parallel-tasks:plet ((x (sleep 2))
(y (+ 3 4))
a
(b (sleep 3))
(z (floor 12 5)))
(list x y a b z)))
Evaluation took:
3.0000 seconds of real time
(NIL 7 NIL NIL 2)
4Tests
The tests require the fiveam library.
(asdf:test-system "simple-parallel-tasks")