From: Juan Jose Garcia
Subject: Lisp on H.P. proyects?
Date: 
Message-ID: <s99btnextp0.fsf@zo2-c705.uibk.ac.at>
Hi,

Let me introduce myself now that I've dared to post to this group for
the first time. I'm a physicist with what I thought a sound ground on
C.S. but now I've faced Scheme and Lisp and saw what I can do with
them, I begin to doubt about myself :)

Mostly what I want from Lisp is using it to build an extensible
environment where to write small programs for doing numerical
calculations (A personal project with no current commercial
implications).

My first attempt was rather successfull and consisted on glueing
FORTRAN code to several Scheme interpreters in a dynamic way: without
actual C glue code, but much like the FFCALL library which I've later
discovered. The library essentially provided me with a way to allocate
garbage collectable memory, and to manipulate it as if contained any
foreign type. This layer was portable, and most of the other code
relied on using Meroon, an OO layer for Scheme. The best results were
with a Gambit, a scheme to C compiler --it gave benchmarks comparable
to Scilab, a free clone of Matlab-- because with it I could compile
Meroon, which indeed took most of the CPU time.

Anyway I now wanted to have a look at Common Lisp, for several
reasons: the main one is that it has a well stablished standard for
the OO programming; the second one is that all implementations I know
of do handle both interpreted and compiled code in a graceful way; and
the third one is that also all of them provide the user with a native
FFI.

As I tell you, this is still a field research, looking for a stable
way to go ahead. An example: right before this I was considering
EuLisp (Youtoo) as an alternative to Scheme which provides OO and
beatifully integrates with C/C++/FORTRAN code. However, then I saw
CMULISP compile code that is half as fast as C without turning any
optimization on, and I began to think about the possibility of coding
everything in LISP. Now I have a dozen possible branches and, tough
I'm still doubtful, I keep on reading the Cltl2 manual (Sorry, I'm far
away from and have no means to reach a decent book on Lisp)

Anyone here has experience on doing high performance programs with
Lisp? What about FFI, optimization, etc? Is there a most suitable
compiler for what I'm doing?

Regards

	Juanjo

From: Paolo Amoroso
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <36263123.50724@news.mclink.it>
On 15 Oct 1998 07:47:23 +0200, Juan Jose Garcia
<········@zo2-c705.uibk.ac.at> wrote:

> Mostly what I want from Lisp is using it to build an extensible
> environment where to write small programs for doing numerical
> calculations (A personal project with no current commercial
> implications).
[...]
> Anyway I now wanted to have a look at Common Lisp, for several

You may check "Fast Floating Point in Common Lisp" by R.J. Fateman, K.A.
Broughan, D.K. Willcock and D. Rettig (I don't have a bibliographic
reference, but the paper appeared around 1994 in an ACM publication). It's
available at:

ftp://peoplesparc.berkeley.edu/pub/papers/lispfloat.ps (PostScript)
ftp://peoplesparc.berkeley.edu/pub/papers/lispfloat.tex (LaTeX source)

Here's the abstract:

"Lisp, one of the oldest higher-level programming languages has rarely been
used for fast numerical (floating-point) computation. We explore the
benefits of Common Lisp, an emerging new language standard with some
excellent implementations, for numerical computation. We compare it to
Fortran in terms of the speed of efficiency of generated code, as well as
the structure and convenience of the language. There are a surprising
number of advantages to Lisp, especially in cases where a mixture of
symbolic and numeric processing is needed."


Paolo
-- 
Paolo Amoroso <·······@mclink.it>
From: Pierre Mai
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <87k9217o8m.fsf@dent.isdn.cs.tu-berlin.de>
Juan Jose Garcia <········@zo2-c705.uibk.ac.at> writes:

> Mostly what I want from Lisp is using it to build an extensible
> environment where to write small programs for doing numerical
> calculations (A personal project with no current commercial
> implications).

I'd think that Common Lisp is a very sound basis for this, given the
evidence before us: Many of the (commercially) available shells for
numerical calculation and symbolic manipulation either started out as
Lisp-based products, or at least include a scripting language that is
heavily Lisp-based.

Indeed, doing symbolic manipulation of mathematical formulas has been
a large driving-force in the evolution of Lisp.

> foreign type. This layer was portable, and most of the other code
> relied on using Meroon, an OO layer for Scheme. The best results were
> with a Gambit, a scheme to C compiler --it gave benchmarks comparable
> to Scilab, a free clone of Matlab-- because with it I could compile
> Meroon, which indeed took most of the CPU time.

This would imply that you not only need an implementation which is
very good at optimizing mathematics, but also one which is very good
at optimizing CLOS.

So I'd suggest that you try to stay as portable as possible, and then
check all the available options for your plattform, to find out which
of them gives you the best performance.  Since this will probably
depend on the trade-off between numerical and CLOS performance, it is
difficult to predict which implementation will win in the end.  But
I'd suggest that you try out at least CMUCL[1], ACL5.0 Trial Edition
for Linux[2] and Harlequin's Lispworks Personal Edition for Win95[3],
depending on the platform your using.

> beatifully integrates with C/C++/FORTRAN code. However, then I saw
> CMULISP compile code that is half as fast as C without turning any
> optimization on, and I began to think about the possibility of coding
> everything in LISP. Now I have a dozen possible branches and, tough

Yes, CMUCL has achieved FP speeds that have equalled or surpassed
those of C, C++ and Java[4].  Also CMU CL offers you very useful
diagnostics (performance notes) as to where and how your program is
inducing performance penalties, how severe they are, and what to do
about them (just compile a simple numeric function with (declaim
(optimize (speed 3))), and look ;).  If you combine this with
profiling, you will quickly get a handle on program performance, at
least in the numeric areas.

> I'm still doubtful, I keep on reading the Cltl2 manual (Sorry, I'm far
> away from and have no means to reach a decent book on Lisp)

The Harlequin HyperSpec is also available online and for download, and 
since it very closely matches the ANSI Standard for Common Lisp, you
will get a much clearer look at what really is current Common Lisp (a
number of things have changed 'since' CLtL2).  So even if you read
CLtL2 as your introduction manual, occasionally glance at the
HyperSpec...  Available at http://www.harlequin.com/books/HyperSpec

> Anyone here has experience on doing high performance programs with
> Lisp? What about FFI, optimization, etc? Is there a most suitable
> compiler for what I'm doing?

Well, I'm currently leading a project that has decided to reimplement
a complex factory-floor simulation program (logistics, assembly, etc.)
in Common Lisp, and I'd say that this program (suite) is high
performance, since the old C++ based simulation took between 3-12
hours to complete a simulation run[5], and we will have to remain in
this  region somewhere, or we will have problems ;)

Regs, Pierre.

Footnotes: 
[1]  CMU CL is really good at numerical code, and it's performance
notes will give you much information on further optimizations
possible.  It also includes a relatively good FFI and a really good
random number generator (MT19937).  It's CLOS implementation (based on 
PCL) is not as fast as e.g. ACL 5.0's CLOS for the simple cases (like
e.g. single primary methods on generic functions, etc., and wired
instance creation is a factor of 10 slower, because of the trade-offs
chosen(?)), but surpases ACL if one uses `more advanced' CLOS
techniques like :around methods, or EQL specializers.

[2]  ACL 5.0 Trial Edition for Linux is available free of charge for
personal or educational, non-commercial purposes via Franz's web site
at http://www.franz.com/.

[3]  Harlequin is offering their LispWorks Personal Edition (similar
legal restrictions as Franz's offering, but also some implementation
restrictions like limited run-time and heap-size) for Win32.  See
http://www.harlequin.com/.  BTW: I'd really like Harlequin to make
availabe their Lispworks for Linux, which would make available all
three major Windows CL implementations on Linux, too. ;)

[4]  See diverse benchmark results posted to this group in the last
years, searchable via DejaNews ;) 

[5]  This depends on simulated run-time in days, complexity of
factory, and on a number of algorithmic changes that we performed
during the maintenance of the simulation, which resulted in a
substantial speed up (12 -> 3 ;).  There still remained a number of
algorithmic speed-ups, as well as advanced features, we had
considered, but couldn't implement, because of implementation
complexities, which had prompted this rewrite in CL.

-- 
Pierre Mai <····@cs.tu-berlin.de>	http://home.pages.de/~trillian/
  "Such is life." -- Fiona in "Four Weddings and a Funeral" (UK/1994)
From: Johann Hibschman
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <mtr9w9mwm3.fsf@astron.berkeley.edu>
Juan Jose Garcia <········@zo2-c705.uibk.ac.at> writes:

> Let me introduce myself now that I've dared to post to this group for
> the first time. I'm a physicist with what I thought a sound ground on
> C.S. but now I've faced Scheme and Lisp and saw what I can do with
> them, I begin to doubt about myself :)

Lisping physicists of the world unite!  Or something like that...

> Anyone here has experience on doing high performance programs with
> Lisp? What about FFI, optimization, etc? Is there a most suitable
> compiler for what I'm doing?

I am just starting work again on a CL numeric program, after spending
a few days tracking down a mysterious memory leak in a previous
C/Python version.  I had done some similar work in CL about a year
ago, but was stopped at that time by a bug in CMUCL which made
floating point calculations intolerably slow on my UltraSparc.  That
bug's been fixed for several months now, so I'm slowly going back to
CL.

I have found CMUCL to be very useful, as it provides great numeric
performance, useful diagnostics, and is free.  (As a Starving Graduate
Student (tm), this is rather important to me.)  The FFI is good,
although it only supports doubles, not floats, on the sparc version.

You may want to check out Raymond Toy's version of the fortran-to-lisp
converter, at:

http://www.mindspring.com/~rtoy/software/f2cl/index.html

For me, CL could really use a good library of array-manipulation
routines.  I'm trying to learn a bit of APL and implement it in CL,
but progress is slow.  (I'm not that familiar with matrix languages,
having only used a bit of matlab, but I want to Do It Right.)  If you
want numeric code, the clmath package in the CMU Lisp repository has a
useful matrix package, along with a number of useful routines.

Good luck,

--Johann Hibschman
From: Raymond Toy
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <4n1zo9ilap.fsf@rtp.ericsson.se>
>>>>> "Johann" == Johann Hibschman <······@physics.berkeley.edu> writes:

    Johann> Student (tm), this is rather important to me.)  The FFI is good,
    Johann> although it only supports doubles, not floats, on the sparc version.

This bug has been fixed.  You might want to get a new version.

Ray
From: Rainer Joswig
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <joswig-1510982341260001@194.163.195.67>
In article <··············@astron.berkeley.edu>, Johann Hibschman
<······@physics.berkeley.edu> wrote:

> For me, CL could really use a good library of array-manipulation
> routines.  I'm trying to learn a bit of APL and implement it in CL,
> but progress is slow.  (I'm not that familiar with matrix languages,
> having only used a bit of matlab, but I want to Do It Right.)  If you
> want numeric code, the clmath package in the CMU Lisp repository has a
> useful matrix package, along with a number of useful routines.

Typical software areas in which Lisp has been used that may need
strong numerical maths capabilities includes

- math packages: Axiom/Scratchpad, Reduce, Macsyma, MuMath, ...
- sound synthesis
- statistics: XlispStat, Clasp
- image processing
- 3d/rendering/modelling
- CAD systems
- neural network simulations
- speech

-- 
http://www.lavielle.com/~joswig
From: Rainer Joswig
Subject: Re: Lisp on H.P. proyects?
Date: 
Message-ID: <joswig-1510981004500001@pbg3.lavielle.com>
In article <···············@zo2-c705.uibk.ac.at>, Juan Jose Garcia
<········@zo2-c705.uibk.ac.at> wrote:

> Anyone here has experience on doing high performance programs with
> Lisp? What about FFI, optimization, etc? Is there a most suitable
> compiler for what I'm doing?

Get some inspiration from for example Common Lisp Music:

 http://ccrma-www.stanford.edu/CCRMA/Software/clm/clm.html

  Common Lisp Music is a music synthesis and signal processing package
  in the   Music V family. I think it works in the following environments:

  NeXTstep ACL, Clisp, or GCL 
  SGI with ACL, GCL, CMU-CL, or Clisp 
  Mac (PowerPC only) with MCL-PPC and Code Warrior C 
  Sun with ACL (perhaps CLisp or GCL also, but not tested) 
  Linux with ACL, GCL or Clisp 
  FreeBSD, DEC Alpha, Windoze, and mkLinux with Clisp 

It compiles restricted numerical Lisp code either to DSP native
(obsolete?), C, or Lisp. For example you could do physical
modelling of sound instruments with Lisp like this:


; flute.ins         physical model of flute (Nicky Hind) 

(definstrument stereo-flute (start dur freq flow 
              &key
              (flow-envelope '(0  1 100 1))
              (decay 0.01)       ; additional time for instrument to decay
              (noise 0.0356) 
              (embouchure-size 0.5)
              (fbk-scl1 0.5)     ; these two are crucial for good results
              (fbk-scl2 0.55)
              (offset-pos 0.764264) ; from 0.0 to 1.0 along the bore
              (out-scl 1.0)
              (a0 0.7) (b1 -0.3)  ; filter coefficients
              (vib-rate 5) (vib-amount 0.03)
              (ran-rate 5) (ran-amount 0.03))

  (let* ((current-excitation 0.0)
    (current-difference 0.0)
    (current-flow 0.0)
    (out-sig 0.0)
    (tap-sig 0.0)
    (previous-out-sig 0.0)
    (previous-tap-sig 0.0)
    (dc-blocked-a 0.0)
    (dc-blocked-b 0.0)
    (previous-dc-blocked-a 0.0)
    (previous-dc-blocked-b 0.0) 
    (delay-sig 0.0)
    (emb-sig 0.0)
    (beg (floor (* start sampling-rate)))
    (end (+ beg (floor (* dur sampling-rate))))
    (flowf (make-env :envelope flow-envelope 
           :scaler flow 
           :start beg 
           :end (+ beg (* (- dur decay) sampling-rate))))
    (periodic-vibrato (make-oscil :frequency vib-rate))
    (random-vibrato (make-randi :frequency ran-rate))
    (breath (make-randh :frequency (/ sampling-rate 2) :amplitude 1))
    (period-samples (floor (/ sampling-rate freq)))
    (embouchure-samples (floor (* embouchure-size period-samples)))
    (embouchure (make-delay embouchure-samples :initial-element 0.0))
    (bore (make-delay period-samples :initial-element 0.0))
    (offset (floor (* period-samples offset-pos)))
    (reflection-lowpass-filter (make-one-pole a0 b1))) 

    (run
     (loop for i from beg to end
      do
      (setf delay-sig (delay bore out-sig))
      (setf emb-sig (delay embouchure current-difference))
      (setf current-flow (+ (* vib-amount (oscil periodic-vibrato)) 
             (* ran-amount (randi random-vibrato)) 
             (env flowf)))
      (setf current-difference 
       (+  (+ current-flow (* noise (* current-flow (randh breath))))
           (* fbk-scl1 delay-sig)))
      (setf current-excitation (cubic-polynomial emb-sig))
      (setf out-sig (one-pole reflection-lowpass-filter 
               (+ current-excitation (* fbk-scl2 delay-sig))))
      (setf tap-sig (tap bore offset))
      ;; NB the DC blocker is not in the cicuit. It is applied to the out-sig 
      ;; but the result is not fed back into the system.
      (setf dc-blocked-a 
       (dc-blocker out-sig previous-out-sig previous-dc-blocked-a))
      (setf dc-blocked-b 
       (dc-blocker tap-sig previous-tap-sig previous-dc-blocked-b))
      (outa i (* out-scl dc-blocked-a))
      (outb i (* out-scl dc-blocked-b))
      (setf previous-out-sig out-sig previous-dc-blocked-a dc-blocked-a)
      (setf previous-tap-sig tap-sig previous-dc-blocked-b dc-blocked-b)))))

-- 
http://www.lavielle.com/~joswig