Utilizing Multi-core with Parallel Lisp

Kenichi Sasagawa
2 min readMay 3, 2024

--

Consideration of Takeuchi Function

In the previous article, I introduced Takeuchi function in Parallel Lisp. As expected, simply computing three arguments in parallel does not always reduce the execution time to one-third. The processing load of the second argument is significant.

Please consider the following results: even if we simply divide (tarai 12 6 0) into three parts, the efficiency does not improve much.

Is there a better way to leverage parallelism? I pondered this question. Currently, CPUs are increasing in core count, with some gaming PCs employing CPUs with up to 20 cores. Can’t we make better use of this core count? I thought about methods to utilize idle processes.

Maximizing Multi-core Usage

As mentioned earlier, we could divide computations into parallel tasks for idle cores, but how? In Easy-ISLisp, we utilize Unix’s fork and Pipe to launch child Lisps and communicate with the parent Lisp using pipes. While parent and child processes can communicate, siblings (children of the same parent) cannot communicate directly.

Protocol

Now, what should we do? I pondered whether memory sharing or using sockets could enable communication between siblings. Suddenly, it occurred to me, “What if we communicate through the parent to other children?” When I consulted with ChatGPT, it seemed like a good approach.

By establishing a protocol, child Lisps can further divide computations and delegate parallel calculations to idle sibling Lisps via the parent Lisp. It seems like delegating work in English is called “handing over.” I am currently brainstorming the idea of providing a parallel syntax like (mp-hand fun arg1 ... arg2) for this purpose. With this approach, traditional inter-process communication using pipes can be employed, making the process enjoyable.

Implementation

Easy-ISLisp is open-source software provided under the BSD 2-Clause License. Feel free to enjoy it.

sasagawa888/eisl: ISLisp interpreter/compiler (github.com)

--

--