From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id A6E79BC69 for ; Thu, 31 May 2007 11:13:45 +0200 (CEST) Received: from pih-relay06.plus.net (pih-relay06.plus.net [212.159.14.133]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4V9Djn1023898 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Thu, 31 May 2007 11:13:45 +0200 Received: from [80.229.56.224] (helo=beast.local) by pih-relay06.plus.net with esmtp (Exim) id 1Htgj2-0006aF-ND for caml-list@yquem.inria.fr; Thu, 31 May 2007 10:13:44 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Comparison of OCaml and MLton for numerics Date: Thu, 31 May 2007 10:08:16 +0100 User-Agent: KMail/1.9.7 References: <5195a210705302250u6a9e5adey4ed857480f9e5cd8@mail.gmail.com> <200705310717.01553.jon@ffconsultancy.com> <5195a210705310031n19f035e7sc5d96568e86496ae@mail.gmail.com> In-Reply-To: <5195a210705310031n19f035e7sc5d96568e86496ae@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200705311008.16662.jon@ffconsultancy.com> X-Miltered: at discorde with ID 465E91C9.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 unboxed:01 img:98 img:98 height:98 frog:98 heap:01 wrote:01 caml-list:01 computation:01 tar:01 width:97 floats:02 floats:02 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 img.(y).(x) else 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 http://www.ffconsultancy.com/products/ocaml_for_scientists/?e