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 D290EBC69 for ; Thu, 8 Feb 2007 10:56:50 +0100 (CET) Received: from smtp19.orange.fr (smtp19.orange.fr [80.12.242.17]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l189uoAD026713 for ; Thu, 8 Feb 2007 10:56:50 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1909.orange.fr (SMTP Server) with ESMTP id 5792E1C00046; Thu, 8 Feb 2007 10:56:50 +0100 (CET) Received: from [192.168.0.9] (ARouen-205-1-4-25.w80-11.abo.wanadoo.fr [80.11.106.25]) by mwinf1909.orange.fr (SMTP Server) with ESMTP id BCB801C000AE; Thu, 8 Feb 2007 10:56:49 +0100 (CET) X-ME-UUID: 20070208095649773.BCB801C000AE@mwinf1909.orange.fr Message-ID: <45CAF3E2.7020807@univ-paris12.fr> Date: Thu, 08 Feb 2007 10:56:50 +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: Jacques Garrigue Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Multiplication of matrix in C and OCaml References: <45CA63F5.6020301@univ-paris12.fr> <20070208.111401.55511744.garrigue@math.nagoya-u.ac.jp> In-Reply-To: <20070208.111401.55511744.garrigue@math.nagoya-u.ac.jp> Content-Type: multipart/mixed; boundary="------------000707080809030905000102" X-Miltered: at discorde with ID 45CAF3E2.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; gava:01 gava:01 ocaml:01 ocaml:01 memcpy:01 matrices:01 matrices:01 iteration:01 ocamlopt:01 -unsafe:01 mult:01 argv:01 argv:01 maxi:01 iter:01 X-Attachments: type="text/x-csrc" name="mult.c" name="mult.c" name="mult.ml" name="mult.ml" This is a multi-part message in MIME format. --------------000707080809030905000102 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: 8bit I attached the pure sequential version of my program. In the file, I give how I compile, How I run and the result. Here C is 5 time faster than OCaml Many thanks to tell me why my OCaml code is so slow. Regards, Frédéric Gava ps: note that in a more generic version of the C code (that is, do memcpy because the data could be of any size, (for example, matrices of polynomials) the ocaml code is faster and faster than the C one :-) ) --------------000707080809030905000102 Content-Type: text/x-csrc; name="mult.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="mult.c" /* param 1 = size of the matrices at the beginning param 2 = incrementation param 3 = size of the matrices at the end param 4 = number of iteration gcc -O2 -o cmult mult.c time ./cmult 600 2 602 1 real 0m3.800s user 0m3.764s sys 0m0.020s */ #include #include #include typedef struct Complexe {double re; double img;} complexe; complexe zero; /* version generic */ __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}); } complexe random_complexe(void) { complexe c = {c.re=(double)(rand()%1000), c.img=(double)(rand()%1000)}; return c; } 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 _ = Random.self_init(); let i = ref (int_of_string (Sys.argv).(1)) and pas=(int_of_string (Sys.argv).(2)) and maxi=(int_of_string (Sys.argv).(3)) and iter=(int_of_string (Sys.argv).(4)) in while !i