[plt-scheme] Experience Using Mz(Dr)Scheme for Numerical Work
Thanks for the suggestions; I would definitely use _fixnum when
implementing the loops, as I wouldn't be dealing with bignum-sized sets
of bodies. Unfortunately, I'm trying to implement my own integrators
(which are much more specialized to the n-body problem, and
correspondingly more advanced, than the ones in the GSL or other
libraries), so I really don't have other libraries to pull them out of.
I would really prefer to use scheme (not the least because of your
excellent FFI), but I am currently leaning toward CL; I'm going to keep
playing around with MzScheme for a while, however, and see if I can
squeeze a bit more performance out if it without just implementing the
whole thing in C.
Thanks again,
Will
On 17 Apr 2005, at 5:00 PM, Eli Barzilay wrote:
> On Apr 17, Will M. Farr wrote:
>> [...]
>> Unfortunately, after writing the same simple integrators in C,
>> common lisp, and scheme, I find that, even with a C-coded inner
>> loop, DrScheme/MzScheme are about 10 times slower than SBCL, and 15
>> times slower than straight C. The difficulty seems to be that
>> computing m1*m2/r12^2 isn't enough work to offset the baggage that
>> comes with a FFI call, and the looping overhead.
>> [...]
>
> Yes, looping would be the computational bottleneck if you use Scheme
> with lots of simple computations. One thing to consider is to use
> _fixnum if you know you'll never get bignums -- _fixnum uses a cheaper
> translation when going to/from C.
>
> Another thing that might be viable is to use bindings from something
> like GSL -- using the foreign interface it is really simple to pull a
> few functions out. I don't know whether this can be a solution or not
> since I don't know what an advanced integrator is -- and the same
> holds for moving the loops on to C. (If you want to do that, then it
> is also simple to write straight C code and use foreign to interface
> that.)
>
> If there is no clear way to separate out some computation intensive
> core out to C, then for now CL would be a better choice -- you could
> in that case use one of the packages that allow porting simple code
> from Scheme to CL, even if it results in incomprehensible Lisp code.
> (You could use some Scheme macro for loops and translate that to Lisp
> iterations. With modules you will be stuck -- CL is much poorer in
> that department.)
>
> --
> ((lambda (x) (x x)) (lambda (x) (x x))) Eli
> Barzilay:
> http://www.barzilay.org/ Maze is
> Life!