English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Comparison of OCaml and MLton for numerics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-31 (09:13)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics
On Thursday 31 May 2007 08:31:04 Yuanchen Zhu wrote:
> http://www.people.fas.harvard.edu/~yzhu/hdrRc.tar.bz2

You are doing all this computation in your inner loop unnecessarily:

let getReflected (img:t) y x yr xr = 
  let w = width img and h = height img in
    if x >= 0 && x < w && y >= 0 && y < h then
      let x = abs x and y = abs y in
      let xx = x/w and x' = x mod w and yy = y/h and y' = y mod h in
      let x',xr = if xx mod 2 = 0 then (x',1.0) else (w - 1 - x',xr) in
      let y',yr = if yy mod 2 = 0 then (y',1.0) else (h - 1 - y',yr) in
        img.(y').(x') *. xr *.yr

Hoist as much as you can from the inner loop and this program will run much 
faster in any language.

> > As I can autogenerate my code, I would much rather the OCaml developers
> > concentrated on things that I cannot get around, like the lack of a
> > 32-bit float storage type and a more efficient internal representation of
> > complex numbers.
> That sounds very interesting. Could you elaborate or give an example?

Complex numbers are unboxed in OCaml. If they were equivalent to a C struct 
then performance would be much better.

OCaml only handles 64-bit floats because there is no point in computing with 
32-bit floats any more. However, there is point in storing 32-bit floats as, 
when you have a lot of them, your program uses half as much heap and is twice 
as cache coherent. My ray tracer is an excellent example of a program that 
can benefit from this.

Dr Jon D Harrop, Flying Frog Consultancy Ltd.
OCaml for Scientists