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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id ECAEDBBCA for ; Mon, 12 May 2008 15:22:27 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwCAM/hJ0hQRFuwiGdsb2JhbACSDgEBAQ8gmAU X-IronPort-AV: E=Sophos;i="4.27,473,1204498800"; d="scan'208";a="12496250" Received: from discorde.inria.fr ([192.93.2.38]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 May 2008 15:22:27 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m4CDMQmH009073 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 12 May 2008 15:22:27 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmwCAM/hJ0hQRFuwiGdsb2JhbACSDgEBAQ8gmAU X-IronPort-AV: E=Sophos;i="4.27,473,1204498800"; d="scan'208";a="12496248" Received: from furbychan.cocan.org ([80.68.91.176]) by mail3-smtp-sop.national.inria.fr with ESMTP; 12 May 2008 15:22:25 +0200 Received: from rich by furbychan.cocan.org with local (Exim 4.63) (envelope-from ) id 1JvXyy-0000dh-4D for caml-list@inria.fr; Mon, 12 May 2008 14:22:24 +0100 Date: Mon, 12 May 2008 14:22:24 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Re: Why OCaml rocks Message-ID: <20080512132223.GA24858@annexia.org> References: <200805090139.54870.jon@ffconsultancy.com> <200805091910.41381.jon@ffconsultancy.com> <1210371949.6399.62.camel@Blefuscu> <200805102059.54856.jon@ffconsultancy.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200805102059.54856.jon@ffconsultancy.com> User-Agent: Mutt/1.5.13 (2006-08-11) From: Richard Jones X-Miltered: at discorde with ID 48284492.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 fwiw:01 rdwr:01 trunc:01 ocaml:01 lapack:01 model:01 12%:98 unix:01 unix:01 caml-list:01 unsafe:01 unsafe:01 bounds:02 match:02 FWIW this is an implementation using Ancient: ---------------------------------------------------------------------- let n = 1024 let a = Array.make_matrix n n 6.7 let b = Array.make_matrix n n 8.9 (* Result array, stored in shared memory. *) let c = let c = Array.make_matrix n n 0. in let fd = Unix.openfile "/tmp/zero" [Unix.O_RDWR;Unix.O_TRUNC;Unix.O_CREAT] 0o644 in let md = Ancient.attach fd 0x440000000000n in Ancient.follow (Ancient.share md 0 c) let parmul_aux i0 i1 n a b = for i = i0 to i1 - 1 do let ai = a.(i) in for j = 0 to n - 1 do let r = ref 0.0 in for k = 0 to n - 1 do r := !r +. Array.unsafe_get ai k *. Array.unsafe_get (Array.unsafe_get b k) j done; c.(i).(j) <- !r done; done let parmul n a b = (match Unix.fork () with 0 -> parmul_aux 0 (n/2) n a b; exit 0 | _ -> ()); parmul_aux (n/2) n n a b; ignore (Unix.wait ()) ;; parmul n a b ---------------------------------------------------------------------- This is just barely faster than Jon's OCaml version using message passing (12% faster on my test machine[0]). Which just seems to show that the overhead of message passing _isn't_ the problem here[1]. Perhaps it's the bounds checking in the assignment back to the matrix? Anyhow, in real life situations we'd all be using a super-optimized hand-coded-in-assembly matrix multiplication library (LAPACK?), so this is all very academic. Rich. [0] Quad core Intel hardware: model name : Intel(R) Core(TM)2 Quad CPU Q9450 @ 2.66GHz [1] Creation of the result matrix and copying it to shared memory is almost instantaneous in my tests. -- Richard Jones Red Hat