Petalisp is an attempt to generate high performance code for parallel computers by JIT-compiling array definitions. It is not a full blown programming language, but rather a carefully crafted extension of Common Lisp that allows for extreme optimization and parallelization.
1. Install Lisp and a suitable IDE.
The fastest way to get everything up and running is to use Portacle.
2. Download Petalisp.
In order to be able to load Petalisp, you may have to place it in the appropriate project directory.
For Portacle users
cd ~/portacle/projects && git clone https://github.com/marcoheisig/Petalisp.git
For Quicklisp users
cd ~/quicklisp/local-projects && git clone https://github.com/marcoheisig/Petalisp.git
3. Load Petalisp
Launch your Lisp IDE and evaluate the following commands:
(ql:quickload :petalisp) (ql:quickload :petalisp-test-suite)
You may also want to run the Petalisp test suite.
Congratulations, you have now access to a highly experimental parallel programming environment! You should now be able to run the examples.
Petalisp is still under development, so the following examples may still change slightly. Nevertheless they give a good glimpse on what programming with Petalisp will be like.
Example 1: transposing a matrix
(defun transpose (A) (reshape A (τ (m n) (n m))))
Example 2: matrix-matrix multiplication
(defun matrix-multiplication (A B) (β #'+ (α #'* (reshape A (τ (m n) (n m 1))) (reshape B (τ (n k) (n 1 k))))))
Example 3: the numerical Jacobi scheme in two dimensions
(defun jacobi-2d (grid iterations) (let ((interior (interior grid))) (if (zerop iterations) grid (jacobi-2d (fuse x (α #'* 0.25 (α #'+ (reshape x (τ (i0 i1) ((+ i0 1) i1)) interior) (reshape x (τ (i0 i1) ((- i0 1) i1)) interior) (reshape x (τ (i0 i1) (i0 (+ i1 1))) interior) (reshape x (τ (i0 i1) (i0 (- i1 1))) interior)))) (- iterations 1)))))
Frequently Asked Questions
Why the Greek letters?
There are several reasons:
- It underlines the beautiful, mathematical nature of this programming model.
- The α and β functions are a tribute to Connection Machine Lisp.
- Compared to programming a computer with billions of transistors and terabytes of memory, typing Greek letters is easy. Right?
Why is Petalisp licensed under AGPL?
I am aware that this license prevents some people from using or contributing to this piece of software, which is a shame. But unfortunately the majority of software developers have not yet understood that
- In a digital world, free software is a necessary prerequisite for a free society.
- When developing software, open collaboration is way more efficient than competition.
So as long as distribution of non-free software is socially accepted, copyleft licenses like the AGPL seem to be the lesser evil.
That being said, I am willing to discuss relicensing on an individual basis.
Why is Petalisp written in Common Lisp?
I couldn’t wish for a better tool for the job. Common Lisp is extremely rich in features, standardized, fast, safe and mature. The Lisp community is amazing and there are excellent libraries for every imaginable task.