<<

LISP IN HPC MARCO HEISIG [email protected]

0 TABLE OF CONTENTS Motivational Quotes The Lisp Language Performance Our Research Questions & Answers

1 MOTIVATIONAL QUOTES … showing you that Lisp is not just another

2 EDSGER W. DIJKSTRA 1972 contributions to: compiler design algorithms formal verification programming languages

3 EDSGER W. DIJKSTRA

FORTRAN's tragic fate has been its wide acceptance, mentally chaining thousands and thousands of to our past mistakes.

3 - 1 EDSGER W. DIJKSTRA

Lisp has jokingly been called "the most intelligent way to misuse a computer". I think that description is a great compliment because it transmits the full flavor of liberation […]

3 - 2 Turing Award 2003 Inventor of Object Oriented Programming

4 ALAN KAY

I invented the term Object-Oriented, and I can tell you I did not have C++ in mind.

Java and C++ make you think that the new ideas are like the old ones. Java is the most distressing thing to hit computing since MS-DOS.

4 - 1 ALAN KAY

[Lisp is] … the greatest single programming language ever designed

4 - 2 RICHARD M. STALLMAN Founder of the Free Foundation Author of GCC GDB Emacs GNU Make …

5 RICHARD M. STALLMAN

The most powerful programming language is Lisp. […] Once you learn Lisp you will see what is missing in most other languages.

5 - 1 OUR MOTIVATION The primary goal of a language should be the elegant notation of algorithms. Mandatory requirements should therefore be automatic memory management proper integers, fractions and complex numbers higher order functions (also at runtime) the possibility of reaching machine peak performance (computational completeness ?)

6 THE LISP LANGUAGE

7 THE LISP LANGUAGE discovered 1958 by John McCarthy short for LISt Processing Modern dialects: Common Lisp Scheme Clojure

8 PAIRS AND LISTS ;; basic datastructure: The pair!

(a . b)

;; pairs can be nested:

(a . (b . (c . ()))) ; note: () is the empty list

;; convenient abbreviation - a list

(a b c)

9 TREES lists of lists first element is the node rest are children

;; A tree made of pairs (child (father (grandfather-1) (grandmother-1)) (mother (grandfather-2) (grandmother-2)))

10 FROM C TO LISP

// standard C notation 2567 + 876 * some_func(23);

// uniform prefix notation +(2567 *(876 some_func(23)))

;; lisp notation, also called S-ex pression (+ 2567 (* 876 (some_func 23)))

;; indented lisp notation (+ 2567 (* 876 (some_func 23))) Code is Data!

11 LAMBDA - CREATE A FUNCTION ;; a function without name

(lambda (x y) (* x y))

;; a named function

(defun factorial (n) (if (= n 0) 1 (* n (factorial (- n 1)))))

;; functions are just objects

(defun get-incrementor (n) (lambda (x) (+ x n)))

12 THE REPL ;; start an interactive lisp session!

(loop (print (eval (read))))

read stdin -> lisp data eval evaluate data print print data loop do something repeatedly

13 PROPER MATHEMATICS Garbage Collection Objects exist as long as needed Integers Not just 32bit of storage Sane operators

(sqrt -1) ; is #C(0.0 1.0) (integerp 4.0) ; is true (/ 1 8) ; is 1/8

14 LISP IS DYNAMICALLY TYPED (type-of 5) -> (INTEGER 0 4611686018427387903)

(setf foo "Hello, world!")

(type-of foo) -> (SIMLPE-ARRAY CHARACTER (5))

(type-of foo) -> SYMBOL

(type-of (function *))

15 MACROS - SUCCESSFUL METAPROGRAMMING f: data -> data (+ side effects) user defined allows to introduce new notation

(defun f1 (x) (derivative (+ (expt x 4) 2) x))

-> (defun f1 (x) (* 4 (expt x 3)))

(math-syntax "(2*x) / foo(x) + 9!")

-> (+ (/ (* 2 x) (foo x)) (factorial 9))

16 TOPICS NOT COVERED Object Oriented Programming Interactive Development Exception Handling Module System Pretty Printing Writing Macros …

17 WHERE TO GO FROM HERE easy to learn: Scheme for professional use: Common Lisp

18 PERFORMANCE

19 IS LISP SLOWER THAN C/C++?

19 - 1 HOW CAN I WRITE FAST LISP CODE Example code:

(defun factorial (n) (if (= n 0) 1 (* n (factorial (- n 1)))))

19 - 2 OUR RESEARCH

20 FEMLISP A Common Lisp Toolbox for solving PDEs Written by Nicolas Neuss

21 FEMLISP FEATURES unstructured grids in arbitrary dimensions finite elements of arbitrary order time dependent problems mesh refinement geometric and algebraic multigrid methods graphics (data explorer, gnuplot) interactive

21 - 1 CL-MPI Lisp bindings for the Interface Developed at AM3 Features: the speed of MPI automatic error handling well typed convenient

22 CL-MPI EXAMPLE Send message in a circle - "Flüsterpost"

(let ((left-neighbor (mod (- rank 1) size)) (right-neighbor (mod (+ rank 1) size))) (cond ((= 0 rank) (mpi-send buffer right-neighbor) (mpi-receive buffer left-neighbor)) (otherwise (mpi-receive buffer left-neighbor) (mpi-send buffer right-neighbor))))

22 - 1 C COUNTERPART MPI_Status status; int left = (rank - 1) % size; int right = (rank + 1) % size; if (rank == 0) { MPI_Send( &value, msg_length, MPI_INT, right, 0, MPI_COMM_WORLD ); MPI_Recv( &value, msg_length, MPI_INT, left, 0, MPI_COMM_WORLD, &status ); } else { MPI_Recv( &value, msg_length, MPI_INT, left, 0, MPI_COMM_WORLD, &status ); MPI_Send( &value, msg_length, MPI_INT, right, 0, MPI_COMM_WORLD ); } // no error handling, can only send INT

22 - 2 INTERACTIVE PARALLEL PROGRAMMING (loop (print (eval (if (= 0 (mpi-comm-rank)) (mpi-broadcast-anything 0 :object (mpi-receive-anything +mpi-any-source+ )) (mpi-broadcast-anything 0))))) note: mpi-ACTION-anything really works on anything! numbers trees bananas

22 - 3 DYNAMIC DISTRIBUTED OBJECTS Efficient and painless parallel programming

23 USAGE

;; get a list of all ranks

(ddo (mpi-comm-rank))

(let ((mesh (make-distributed-object (make-instance 'mesh) *all-processors*))) (DO-SOME-MODIFICATION mesh) (synchronize) ;; propagate all changes (DO-MORE))

23 - 1 FEATURES automatically works on any object fast, uses cl-mpi easy to use dynamic automatic cleanup ownership querys merge conflict resolution

23 - 2 FUTURE WORK Exa Lisp?

24 QUESTIONS & ANSWERS … and Feedback!

25