caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Christophe TROESTLER <Christophe.Troestler@umh.ac.be>
Cc: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] Bigarray map & set/get (long)
Date: Mon, 22 Jul 2002 11:31:36 +0200	[thread overview]
Message-ID: <20020722113136.A10720@pauillac.inria.fr> (raw)
In-Reply-To: <20020719.155940.19123621.Christophe.Troestler@umh.ac.be>; from Christophe.Troestler@umh.ac.be on Fri, Jul 19, 2002 at 03:59:40PM +0200

> Now, if I specify the
> full type of the arrays I want (here
> 
> type mat =
>   (float, Bigarray.float64_elt, Bigarray.fortran_layout) Bigarray.Array2.t
> 
> ) then the code runs much faster: 0.87 sec (still more than 5 times
> the C version unfortunately).  That sould be mentioned in
> http://caml.inria.fr/ocaml/speed.html IMHO -- and maybe this page
> could be better advertised?.

It should be mentioned, but really this is the same phenomenon as for
regular arrays: efficient array access code cannot be generated unless
the full type of the (big-) array is statically known.

> * The Lacaml modules does contain some "matlab like" operations on
>   vectors (and, in the future, on 2D arrays).  That will make easy to
>   write fast code for this example.  However, one thing that will
>   always be necessary is to make CAML functions act on arrays.

In the applications for which Bigarray was initially intended, the
Caml code that manipulates directly the bigarrays isn't
time-critical: the time-critical computations are done by external
libraries such as BLAS, Lapack, etc.  Your matrix multiplication code
is a good example: if you care about its performances, then you need
to make it a lot more sophisticated so that it will be cache-friendly
(e.g. blocking); better use an existing, well-tuned C or Fortran
implementation than try to do your own in Caml.

Put it another way, bigarrays are oriented towards efficient
communications with external libraries, not towards writing efficient
numerical code in Caml; for the latter purpose, regular arrays are
actually more efficient.

> * Are bound checks responsible for the difference between the "fully
>   typed" version [mac (out:mat) (a:mat) (b:mat) (c:mat)] and C??

Partially responsible, but another source of overhead is the
address computations when accessing a big array: these involve linear
formulas of the form X * dim1(a) + Y, which are not optimized inside
loops, while most C and Fortran compilers do extensive optimizations
for this kind of computations (hoisting of loop-invariant code,
transformation of multiplications into iterated additions, etc).

> P.S.  Is it possible to write a "let module A = B" (i.e., module
> renaming) in camlp4?

That's a standard feature of the OCaml module language; it's written
"module A = B".  What a surprise :-)

- Xavier Leroy
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2002-07-22  9:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-19 13:59 Christophe TROESTLER
2002-07-20 18:29 ` Daniel de Rauglaudre
2002-07-21  0:45 ` Oleg
2002-07-22 13:30   ` [Caml-list] Bigarray map & set/get Christophe TROESTLER
2002-07-22  9:31 ` Xavier Leroy [this message]
2002-07-22 13:03   ` Christophe TROESTLER
2002-07-22 15:43   ` [Caml-list] Bigarray map & set/get (long) Fernando Alegre
2002-07-25  3:02   ` Chris Hecker
2002-07-25  9:30     ` Xavier Leroy
2002-07-25 18:11       ` Chris Hecker
2002-07-26  5:44         ` Michael Vanier
2002-07-26 22:33           ` wanted features (was: Re: [Caml-list] Bigarray map & set/get (long)) Chris Hecker
2002-07-26 22:40             ` Michael Vanier
2002-07-26 22:44               ` Chris Hecker
2002-07-27  0:28                 ` Michael Vanier
2002-07-27  0:32                   ` Chris Hecker
2002-07-27 10:53                     ` Dimitri Ara
2002-07-27 12:06                     ` Dimitri Ara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020722113136.A10720@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=Christophe.Troestler@umh.ac.be \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).