[Haskell-cafe] Numerical methods in Haskell
droundy at abridgegame.org
Mon Feb 20 09:20:37 EST 2006
On Mon, Feb 20, 2006 at 11:47:49AM +0100, Bjorn Lisper wrote:
> >(a) It's hard to compete with existing libraries. The obvious thing is
> >not to compete; instead, just call them. But somehow that doesn't seem
> >to be as motivating. Perhaps some bindings exist though?
> Hard to compete, yes. But on the other hand, the rewards can be high.
> Numerical library code (especially matrix libraries) tends to be highly
> optimized for the hardware architecture at hand. As a consequence a small
> change in, say, the cache architecture, might require a thorough rewrite of
> the library code to regain high utilisation of the hardware. This is since
> languages like Fortran and C force you to code so close to the hardware. A
> high-level language, with good optimizing compilation, would make also
> library code more portable across hardware architectures. N.b. these
> optimizations are non-trivial to say the least.
The only particularly relevant numerical libraries today (atlas and fftw)
already do far better optimization than any compiler is going to acheive,
and in the case of fftw can respond to changes in memory configuration at
runtime. In both cases they're written in ANSI C (although the C code for
fftw is written by an OCaml program... or at least some dialect of ML). In
order to take advantage of cache behavior properly, it's necesary to allow
adjustments in the actual algorithm used, which isn't something that a
clever compiler is likely to accomplish.
Which is to say that while I'd love native Haskell code to run incredibly
fast, noone can compete with atlas or fftw when writing in any other
language either, unless they're willing to do either runtime or
compile-time (or coding-time) timings on the actual machine on which the
code will run. There really is no reason to try to compete with these
libraries. Unless, I suppose, your interest is in writing libraries...
fwiw, atlas takes close to a day to compile on my machine, since it spends
so long performing timings of various algorithms with various parameters.
I don't want my haskell compiler to take that long to compile *anything*.
More information about the Haskell-Cafe