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=1.0 required=5.0 tests=AWL,SPF_FAIL 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 ABDBEBC6A for ; Thu, 8 Feb 2007 00:42:47 +0100 (CET) Received: from smtp19.orange.fr (smtp19.orange.fr [80.12.242.1]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l17Ngkv4030574 for ; Thu, 8 Feb 2007 00:42:47 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1906.orange.fr (SMTP Server) with ESMTP id DDF0D1C000A8 for ; Thu, 8 Feb 2007 00:42:46 +0100 (CET) Received: from [192.168.0.3] (ARouen-205-1-1-140.w80-11.abo.wanadoo.fr [80.11.112.140]) by mwinf1906.orange.fr (SMTP Server) with ESMTP id 8242F1C0008C for ; Thu, 8 Feb 2007 00:42:46 +0100 (CET) X-ME-UUID: 20070207234246533.8242F1C0008C@mwinf1906.orange.fr Message-ID: <45CA63F5.6020301@univ-paris12.fr> Date: Thu, 08 Feb 2007 00:42:45 +0100 From: =?ISO-8859-1?Q?Fr=E9d=E9ric_Gava?= Reply-To: gava@univ-paris12.fr Organization: =?ISO-8859-1?Q?Universit=E9_de_Paris_12=2C_LACL?= User-Agent: Thunderbird 1.5.0.9 (X11/20070104) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Multiplication of matrix in C and OCaml Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Miltered: at discorde with ID 45CA63F7.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gava:01 gava:01 ocaml:01 ocaml:01 -unsafe:01 typedef:01 struct:01 mult:01 mult:01 12.:98 img:98 img:98 rand:98 rand:98 inline:01 Dear All, I compared multiplication of matrix in C and OCaml and I was a little surprise to see that the following C code (using -O2) is 8 time faster than the OCaml one (even with -unsafe). Anybody have an idea to optimize my OCaml code or know why is there this "big" difference ? many thanks Frédéric Gava ps: the difference is the same even when I use a non-polymorphic multiplication *************** C Code ****************** typedef struct Complexe {double re; double img;} complexe; __inline__ void* add(void *x, void *y) { complexe a=((complexe*) x)[0]; complexe b=((complexe*) y)[0]; return (void *) &((complexe){a.re+b.re, a.img+b.img}); } __inline__ void* mult(void *x, void *y) { complexe a=((complexe*) x)[0]; complexe b=((complexe*) y)[0]; return (void *) &((complexe){a.re*b.re-a.img*b.img, a.re*b.img+a.img*b.re}); } void multiply_generic(int n, void *zero, void* (*add)(void *a, void *b), void* (*mult)(void *a, void *b), void *a, void *b, void *c) { register int i,j,k; void *tmp; void *cc; for (i=0; i random_complex 1000.) let multiplication n zero add mul a b c = let tmp=ref zero in for i=0 to n-1 do for j=0 to n-1 do tmp:=zero; for k=0 to n-1 do tmp:= add (!tmp) (mul b.(k*n+j) a.(i*n+k)) done; c.(i*n+j)<-(!tmp) done done