From: Heiko Schaefer
Subject: Fast numerics
Date: 
Message-ID: <861yftwj4r.fsf@koepke.myip.org>
Dear all,

thanx first of all for answers to my previous posting about optimising
a passed function, it worked.

I am currently obsessed with alternative languages for fast numerical
programming (e.g. PDE solvers). I spend some time trying a simple
solver in Lisp to be as fast as C, I specifically used the hints in
Martin Cracauers page. I got only up to a factor of 3 slower than C (I
use cmucl). This is not bad, better than my smalltalk expericence, but
I had hoped for more.

Would you share your experience about getting Lisp to crunch numbers
with me? 

Heiko


PS. the algorithm is of course the same in C and Lisp
PPS have a look at 

http://www.cons.org/cracauer/lisp-c-fp-bench/

I went along his lines (I checked the benchmark, its 50% slower than
C, very good)

From: larry
Subject: Re: Fast numerics
Date: 
Message-ID: <7b8f89d6.0202101513.170212de@posting.google.com>
Assuming you haven't done so already, why don't you try searching the
lisp newsgroup for "floating point". This returns a lot of hits.


Heiko Schaefer <··············@swissonline.ch> wrote in message news:<··············@koepke.myip.org>...
> Dear all,
> 
> thanx first of all for answers to my previous posting about optimising
> a passed function, it worked.
> 
> I am currently obsessed with alternative languages for fast numerical
> programming (e.g. PDE solvers). I spend some time trying a simple
> solver in Lisp to be as fast as C, I specifically used the hints in
> Martin Cracauers page. I got only up to a factor of 3 slower than C (I
> use cmucl). This is not bad, better than my smalltalk expericence, but
> I had hoped for more.
> 
> Would you share your experience about getting Lisp to crunch numbers
> with me? 
> 
> Heiko
> 
> 
> PS. the algorithm is of course the same in C and Lisp
> PPS have a look at 
> 
> http://www.cons.org/cracauer/lisp-c-fp-bench/
> 
> I went along his lines (I checked the benchmark, its 50% slower than
> C, very good)
From: Siegfried Gonzi
Subject: Re: Fast numerics
Date: 
Message-ID: <3C67782C.69159E5@kfunigraz.ac.at>
Heiko Schaefer wrote:

> I am currently obsessed with alternative languages for fast numerical
> programming (e.g. PDE solvers). I spend some time trying a simple
> solver in Lisp to be as fast as C, I specifically used the hints in
> Martin Cracauers page. I got only up to a factor of 3 slower than C (I
> use cmucl). This is not bad, better than my smalltalk expericence, but
> I had hoped for more.
>
> Would you share your experience about getting Lisp to crunch numbers
> with me?

A factor of 3 is excellent (there isn't more you will gain); this is
reality (the often said 80% of C speed is based on some theories ala
"Alice in Wonderland").

There is an interesting paper how about implementing some numerical stuff
in the language Scheme and then converting it to C (the end result shows
that the native C code and translated one are about the same when it comes
to execution speed):

www.math.purdue.edu/~lucier/615/abstract.pdf


S. Gonzi

>
>
From: Raymond Toy
Subject: Re: Fast numerics
Date: 
Message-ID: <4n8za0ulxb.fsf@rtp.ericsson.se>
>>>>> "Siegfried" == Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

    Siegfried> Heiko Schaefer wrote:

    >> I am currently obsessed with alternative languages for fast numerical
    >> programming (e.g. PDE solvers). I spend some time trying a simple
    >> solver in Lisp to be as fast as C, I specifically used the hints in
    >> Martin Cracauers page. I got only up to a factor of 3 slower than C (I
    >> use cmucl). This is not bad, better than my smalltalk expericence, but
    >> I had hoped for more.
    >> 
    >> Would you share your experience about getting Lisp to crunch numbers
    >> with me?

    Siegfried> A factor of 3 is excellent (there isn't more you will gain); this is
    Siegfried> reality (the often said 80% of C speed is based on some theories ala
    Siegfried> "Alice in Wonderland").

Well, a long time ago, I did a matrix addition function in Lisp.  It
ran as fast as the Fortran version.

Ray
From: Siegfried Gonzi
Subject: Re: Fast numerics
Date: 
Message-ID: <3C67E4C2.5BCFB605@kfunigraz.ac.at>
Raymond Toy wrote:

> Well, a long time ago, I did a matrix addition function in Lisp.  It
> ran as fast as the Fortran version.

I pay it; but  not that Lisp does perform well on large projects (emphasize is on
execution speed compared to Fortran and not how to manage code; the latter one is not
more complicated in Lisp than in any other language). I personally have got no problem
with a performance hit of 10.

The last week I wrote some code for evaluating some observing-stations; I wrote the
code  in Clean long ago (but after a while the project failed due to some reasons); the
next time I wrote it in R (about 2000 lines of code: comments included). But in R I do
not foster good programming style. Lisp is not bad in this respect and I wrote some
part of the code in Lisp (except the plotting-part).

Lisp performs well (compared to R) and I bet that I couldn't have it completed in that
short time in any other compiled-language (Fortran, C, Ada).

Lisp astounds me quite often (I had this all at my disposal in my Clean-career; but I
cannot remember that I even had used it, due to the fight against the type-system).

For example: the following function (maybe it is not the most sophisticated one; but it
just works for me) retrieves some values from a vector if as specific relation is true:

(defun retrieve-vector-values (vector bedingung)
  (let ((cols (nth 0 (array-dimensions vector)))
        (occ 0)
        (vectorErg nil)
        (countOcc 0))
    (loop :for j :from 0 :below cols :do
          (when
              (funcall bedingung (aref vector j))
            (setf occ (1+ occ))))
    (if (> occ 0)
        (progn
          (setf vectorErg (make-array occ))
          (loop :for j :from 0 below cols :do
                (when
                    (funcall bedingung (aref vector j))
                  (progn
                    (setf (aref vectorErg countOcc) (aref vector j))
                    (setf countOcc (1+ countOcc)))))
vectorErg))))


e.g.:

(setf g (span-vector 6))
(retrieve-vector-values g  #'(lambda (x) (> x 2.34)))

delivers:

#(3.0d0 4.0d0 5.0d0)


I couldn't think on any reasonably time where I would be capable of implementing this
lets say in C. I would have absolutely now clue how to write a function which gets a
vector and another function which becomes used on that vector.


S. Gonzi
From: Marco Antoniotti
Subject: Re: Fast numerics
Date: 
Message-ID: <y6cwuxk3qkx.fsf@octagon.mrl.nyu.edu>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> Raymond Toy wrote:
> 
> > Well, a long time ago, I did a matrix addition function in Lisp.  It
> > ran as fast as the Fortran version.
> 
> I pay it; but  not that Lisp does perform well on large projects (emphasize is on
> execution speed compared to Fortran and not how to manage code; the latter one is not
> more complicated in Lisp than in any other language). I personally have got no problem
> with a performance hit of 10.
> 
> The last week I wrote some code for evaluating some observing-stations; I wrote the
> code  in Clean long ago (but after a while the project failed due to some reasons); the
> next time I wrote it in R (about 2000 lines of code: comments included). But in R I do
> not foster good programming style. Lisp is not bad in this respect and I wrote some
> part of the code in Lisp (except the plotting-part).
> 
> Lisp performs well (compared to R) and I bet that I couldn't have it completed in that
> short time in any other compiled-language (Fortran, C, Ada).
> 
> Lisp astounds me quite often (I had this all at my disposal in my Clean-career; but I
> cannot remember that I even had used it, due to the fight against the type-system).
> 
> For example: the following function (maybe it is not the most sophisticated one; but it
> just works for me) retrieves some values from a vector if as specific relation is true:
> 
> (defun retrieve-vector-values (vector bedingung)
>   (let ((cols (nth 0 (array-dimensions vector)))
>         (occ 0)
>         (vectorErg nil)
>         (countOcc 0))
>     (loop :for j :from 0 :below cols :do
>           (when
>               (funcall bedingung (aref vector j))
>             (setf occ (1+ occ))))
>     (if (> occ 0)
>         (progn
>           (setf vectorErg (make-array occ))
>           (loop :for j :from 0 below cols :do
>                 (when
>                     (funcall bedingung (aref vector j))
>                   (progn
>                     (setf (aref vectorErg countOcc) (aref vector j))
>                     (setf countOcc (1+ countOcc)))))
> vectorErg))))

Just by small rewrites.

(defun retrieve-vector-values (vector bedingung)
  (declare (type (vector <what>) vector))
  (let ((cols (length vector))
	(occ 0)
	)
    (declare (type fixnum occ cols))
    (loop :for j :from 0 :below cols
	  :when (funcall bedingung (aref vector j))
	    :do (incf occ))
    (when (plusp occ)
      (let ((vectorErg (make-array occ))
	    (countOcc 0)
	    )
	(declare (type fixnum countOcc)
		 (type (vector <what>) vectorErg))
	(loop :for j :from 0 :below cols
	      :when (funcall bedingung (aref vector j))
	        :do (setf (aref vectorErg countOcc) (aref vector j))
		:and (incf countOcc))
	vectorErg))))

Or better,

(defun retrieve-vector-values (vector bedingung)
  (declare (type (vector <what>) vector))
  (let ((occ (count-if bedingung vector)))
    (when (plusp occ)
      (let ((vector-erg (make-array occ
				    :element-type (array-element-type vector)
				    :initial-element (aref vector 0))))
	(loop for x across vector
	      for vector-erg-index from 0
	      when (funcall bedingung x)
	        do (setf (aref vector-erg vector-erg-index) x))
	vector-erg))))

And this does not even use things like VECTOR-PUSH-EXTEND.

(defun retrieve-vector-values (vector bedingung)
  (let ((vector-erg (make-array 0
				:adjustable t
				:element-type (array-element-type vector)
				:initial-element (aref vector 0))))
    (loop for x across vector
	  when (funcall bedingung x)
	    do (vector-push-extend x vector-erg))
    vector-erg))

This last version has the advantage to always return a (possibly
empty) vector.

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Pierpaolo BERNARDI
Subject: Re: Fast numerics
Date: 
Message-ID: <6sX98.49429$om6.1324944@news1.tin.it>
"Siegfried Gonzi" <···············@kfunigraz.ac.at> ha scritto nel messaggio
······················@kfunigraz.ac.at...

> For example: the following function (maybe it is not the most
sophisticated one; but it
> just works for me) retrieves some values from a vector if as specific
relation is true:
>
> (defun retrieve-vector-values (vector bedingung)
>   (let ((cols (nth 0 (array-dimensions vector)))
>         (occ 0)
>         (vectorErg nil)
>         (countOcc 0))
>     (loop :for j :from 0 :below cols :do
>           (when
>               (funcall bedingung (aref vector j))
>             (setf occ (1+ occ))))
>     (if (> occ 0)
>         (progn
>           (setf vectorErg (make-array occ))
>           (loop :for j :from 0 below cols :do
>                 (when
>                     (funcall bedingung (aref vector j))
>                   (progn
>                     (setf (aref vectorErg countOcc) (aref vector j))
>                     (setf countOcc (1+ countOcc)))))
> vectorErg))))
>
>
> e.g.:
>
> (setf g (span-vector 6))
> (retrieve-vector-values g  #'(lambda (x) (> x 2.34)))
>
> delivers:
>
> #(3.0d0 4.0d0 5.0d0)

CL-USER 114 > (defun retrieve-vector-values (vector bedingung)
                (remove-if-not bedingung vector))
RETRIEVE-VECTOR-VALUES

CL-USER 115 > (retrieve-vector-values #(1 2 3 4 5 4 3 2 1 2 3 4 5)
                                      #'(lambda (x) (> x 2.34)))
#(3 4 5 4 3 3 4 5)

CL-USER 116 > *sigh*
From: Marco Antoniotti
Subject: Re: Fast numerics
Date: 
Message-ID: <y6cofiuvjdp.fsf@octagon.mrl.nyu.edu>
"Pierpaolo BERNARDI" <··················@hotmail.com> writes:

> "Siegfried Gonzi" <···············@kfunigraz.ac.at> ha scritto nel messaggio
> ······················@kfunigraz.ac.at...
> 
> > For example: the following function (maybe it is not the most
> sophisticated one; but it
> > just works for me) retrieves some values from a vector if as specific
> relation is true:
> >


> CL-USER 114 > (defun retrieve-vector-values (vector bedingung)
>                 (remove-if-not bedingung vector))
> RETRIEVE-VECTOR-VALUES
> 
> CL-USER 115 > (retrieve-vector-values #(1 2 3 4 5 4 3 2 1 2 3 4 5)
>                                       #'(lambda (x) (> x 2.34)))
> #(3 4 5 4 3 3 4 5)
> 
> CL-USER 116 > *sigh*


... and of course, the above makes me look like a bozo too! :{

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Marco Antoniotti
Subject: Re: Fast numerics
Date: 
Message-ID: <y6cpu3c59zh.fsf@octagon.mrl.nyu.edu>
Siegfried Gonzi <···············@kfunigraz.ac.at> writes:

> Heiko Schaefer wrote:
> 
> > I am currently obsessed with alternative languages for fast numerical
> > programming (e.g. PDE solvers). I spend some time trying a simple
> > solver in Lisp to be as fast as C, I specifically used the hints in
> > Martin Cracauers page. I got only up to a factor of 3 slower than C (I
> > use cmucl). This is not bad, better than my smalltalk expericence, but
> > I had hoped for more.
> >
> > Would you share your experience about getting Lisp to crunch numbers
> > with me?
> 
> A factor of 3 is excellent (there isn't more you will gain); this is
> reality (the often said 80% of C speed is based on some theories ala
> "Alice in Wonderland").

And you refutation looks like base of a Mad-hatter theory.
Let's see the code and let's see what can be done with it.


> There is an interesting paper how about implementing some numerical stuff
> in the language Scheme and then converting it to C (the end result shows
> that the native C code and translated one are about the same when it comes
> to execution speed):
> 
> www.math.purdue.edu/~lucier/615/abstract.pdf

Which is almost exactly what you can do with CL as well.

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group        tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA                 http://bioinformatics.cat.nyu.edu
                    "Hello New York! We'll do what we can!"
                           Bill Murray in `Ghostbusters'.
From: Brian P Templeton
Subject: Re: Fast numerics
Date: 
Message-ID: <87adufr2hm.fsf@tunes.org>
Heiko Schaefer <··············@swissonline.ch> writes:

> Dear all,
> 
> thanx first of all for answers to my previous posting about optimising
> a passed function, it worked.
> 
> I am currently obsessed with alternative languages for fast numerical
> programming (e.g. PDE solvers). I spend some time trying a simple
> solver in Lisp to be as fast as C, I specifically used the hints in
> Martin Cracauers page. I got only up to a factor of 3 slower than C (I
> use cmucl). This is not bad, better than my smalltalk expericence, but
> I had hoped for more.
> 
> Would you share your experience about getting Lisp to crunch numbers
> with me? 
> 
Have you published the source anywhere?

> Heiko
> 
> 
> PS. the algorithm is of course the same in C and Lisp
> PPS have a look at 
> 
> http://www.cons.org/cracauer/lisp-c-fp-bench/
> 
> I went along his lines (I checked the benchmark, its 50% slower than
> C, very good)

-- 
BPT <···@tunes.org>	    		/"\ ASCII Ribbon Campaign
backronym for Linux:			\ / No HTML or RTF in mail
	Linux Is Not Unix			 X  No MS-Word in mail
Meme plague ;)   --------->		/ \ Respect Open Standards
From: Heiko Schaefer
Subject: Re: Fast numerics
Date: 
Message-ID: <86eljpb905.fsf@koepke.myip.org>
Thanks for all your contributions! I will try whether I can
make some more improvements to the code.
For those who wanted to have a look, I put the code on the web:
koepke.myip.org
Please note that the machine is only up between approx 6am GMT
and 8pm GMT
Any suggestions are greatly appreciated!

Thanks a lot,

Heiko