caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: ls-ocaml-developer-2006@m-e-leypold.de
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml
Date: Fri, 09 Feb 2007 10:06:18 +0100	[thread overview]
Message-ID: <rkhctvbsz9.fsf@hod.lan.m-e-leypold.de> (raw)
In-Reply-To: <20070209.115842.106265091.garrigue@math.nagoya-u.ac.jp> (Jacques Garrigue's message of "Fri, 09 Feb 2007 11:58:42 +0900 (JST)")


Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> writes:

> From: Frédéric Gava <gava@univ-paris12.fr>
>
>> Sorry for the inconvenience and this stupid error: I am a very bad C 
>> programmer.
>> 
>> But, I do not obtain the performance of Jacques Garrigue :-( I try to 
>> bench a parallel matrix multiplication algorithm and test the difference 
>> between C+MPI and OCaml+MPI (I try to prove that OCaml is efficient 
>> enought for high-performance, in this community, they largely prefer 
>> Fortran or C...))
>> 
>> 
>> a) with a "polymorphic" C program (using 
>> "multiply_complex_generic(i,complexe_add,complexe_mult,a,b,c);")
>> 
>> time ./cmult 600 2 602 1
>> real    0m18.402s
>> user    0m17.333s
>> sys     0m0.044s
>> 
>> b) for a monomorphic C programs (using "multiply_complex(i,a,b,c);");
>> 
>> time ./cmult 600 2 602 1
>> real    0m5.604s
>> user    0m5.556s
>> sys     0m0.036s
>
> Interesting. It all depends on the compiler.
> With gcc 3.4, as provided in FreeBSD, I get almost no difference
> between your polymorphic and monomorphic versions. But if I switch to
> gcc 4.1, the monomorphic version is indeed much faster. Actually, what
> I get is:
> gcc 3.4 polymorphic: 15s
> gcc 4.1 polymorphic: 20s
> gcc 3.4 monomorphic: 15s
> gcc 4.1 monomorphic:  7s
> So it looks like gcc 4.1 is better for monomorphic code, but worse for
> function calls...
> Note that in my case, this is still within a factor 2 of ocaml (which
> is about the same as gcc 3.4).

> But your C compiler may be doing some other platform specific
> optimizations. The only way to know what is happening is to look at the
> generated assembler.

I'm just wondering about that. All the data produced during the
matrix-multiplication is AFAICS not used for anything. So I wouldn't
exclude that in the case of monomorphic code gcc 4.1 is just deciding
to ditch most of the actual work after doing some data flow
analysis. Gcc 4.1 is (I think) known to do some aggressive
optimizations. I'd feel better if the code is benchmarked in a way
that the result of the multiplication is output to a file and to
subtract the constant contribution of that to the run time that the
time is measured for various problem sizes (number of matrices). One
would get a linear dependency

   t(n) = C + K*n

and fitting a straight line against the data points could obtain K to
compare the efficiency of C (under various compiler versions and
options) and Ocaml against each other without having to worry about
no-op optimizations or constant startup costs (like load times and run
time initialization: which might be a bit higher with Ocaml, though
certainly not in the order of seconds).

Comparing the output to expected results would also help to ensure
that the code is correct which I still find difficult to assert at
first glance.

Regard -- Markus


  reply	other threads:[~2007-02-09  9:01 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-07 23:42 Frédéric Gava
2007-02-08  2:14 ` [Caml-list] " Jacques Garrigue
2007-02-08  9:27   ` Frédéric Gava
2007-02-08  9:38     ` Frédéric Gava
2007-02-08 12:08     ` Jacques Garrigue
2007-02-08  9:56   ` Frédéric Gava
2007-02-08 10:45     ` Xavier Leroy
2007-02-08 15:16       ` Frédéric Gava
2007-02-09  2:58         ` Jacques Garrigue
2007-02-09  9:06           ` ls-ocaml-developer-2006 [this message]
2007-02-09 10:32             ` ls-ocaml-developer-2006
2007-02-09 14:22               ` skaller
2007-02-09 21:47                 ` ls-ocaml-developer-2006
2007-02-09 21:55                   ` Andrej Bauer
2007-02-09 22:36                     ` ls-ocaml-developer-2006
2007-02-09 23:53                       ` Jon Harrop
2007-02-10  1:41                         ` ls-ocaml-developer-2006
2007-02-10  2:24                           ` Jon Harrop
2007-02-10 14:41                             ` ls-ocaml-developer-2006
2007-02-10 14:52                               ` Jon Harrop
2007-02-10 15:51                                 ` ls-ocaml-developer-2006
2007-02-10 16:10                                   ` Xavier Leroy
2007-02-10 16:11                                   ` Jon Harrop
2007-02-10 14:55                               ` Mattias Engdegård
2007-02-11 13:13                             ` Christophe Raffalli
2007-02-10  1:10                     ` Brian Hurt
2007-02-10  1:16                       ` Robert Roessler
2007-02-09 23:56                 ` Jon Harrop
2007-02-09 12:05             ` Jon Harrop
2007-02-09 12:35               ` ls-ocaml-developer-2006
2007-02-09 13:50             ` Brian Hurt
2007-02-09 14:23               ` Gerd Stolpmann
2007-02-09 14:24 Frederic GAVA

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=rkhctvbsz9.fsf@hod.lan.m-e-leypold.de \
    --to=ls-ocaml-developer-2006@m-e-leypold.de \
    --cc=caml-list@yquem.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).