Eager Future2 is a Common Lisp library that facilitates parallel computation. It is based on the idea of a “future” that acts as a “proxy” for a concurrently computed expression. Unlike the “lparallel” library that I had discussed in the last article, this library does not give us control over the number of “worker threads” to be used in the computation. Even in terms of features, this library is much simpler compared to “lparallel”.
Nevertheless, I wanted to take a quick look at its core functionality, and decided to use the same “Fibonacci” example that I had used in the context of “lparallel”. As before, I used Lispworks Enterprise Edition (64-bit) on Windows 10.
Here are 3 implementations of Fib computation:
“fib” is the classic single-threaded implementation. “fib-par” uses Eager Future2’s “pexec” function (a minor variant of “pcall”) to create “futures” “a” and “b”, and then uses “yield” function to retrieve the respective values. “fib-par2” uses the “plet” construct (similar to the one available in “lparallel”) to compute the previous two Fib values in parallel.
Let us now execute these functions to see the time each one takes.
Looking at the “Elapsed time”, we notice that “fib-par” and “fib-par2” take less time to compute compared to “fib”.
Here is the CPU utilisation as shown by Windows Task Manager.
The three regions, from left to right, correspond to “fib”, “fib-par” and “fib-par2” respectively.
You can download the Lisp code from here.
Have a nice weekend!
Recent Comments