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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 9C0C5BBC4 for ; Fri, 20 Feb 2009 19:46:32 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwCALCJnknUGyoGkWdsb2JhbACUVwEBAQEJCwoHEQO/Z4QPBoYk X-IronPort-AV: E=Sophos;i="4.38,242,1233529200"; d="scan'208";a="21465436" Received: from smtp6-g21.free.fr ([212.27.42.6]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 Feb 2009 19:46:31 +0100 Received: from smtp6-g21.free.fr (localhost [127.0.0.1]) by smtp6-g21.free.fr (Postfix) with ESMTP id 90327E080DA; Fri, 20 Feb 2009 19:46:25 +0100 (CET) Received: from [192.168.1.3] (che78-2-82-237-71-191.fbx.proxad.net [82.237.71.191]) by smtp6-g21.free.fr (Postfix) with ESMTP id 3F588E08158; Fri, 20 Feb 2009 19:46:23 +0100 (CET) Message-ID: <499EFA7E.7010400@inria.fr> Date: Fri, 20 Feb 2009 19:46:22 +0100 From: Xavier Leroy User-Agent: Thunderbird 2.0.0.4 (X11/20070620) MIME-Version: 1.0 To: Erick Matsen Cc: caml-list@inria.fr Subject: Re: [Caml-list] speeding up matrix multiplication (newbie question) References: <243054520902200740j1d1874adib27645f6e090b073@mail.gmail.com> In-Reply-To: <243054520902200740j1d1874adib27645f6e090b073@mail.gmail.com> X-Enigmail-Version: 0.95.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; multiplying:01 matrices:01 genericity:01 ocaml:01 ocaml:01 arrays:01 bigarrays:01 bigarrays:01 matrices:01 tear:98 heap:01 caml-list:01 arithmetic:01 algorithm:01 newbie:02 > I'm working on speeding up some code, and I wanted to check with > someone before implementation. > > As you can see below, the code primarily spends its time multiplying > relatively small matrices. Precision is of course important but not > an incredibly crucial issue, as the most important thing is relative > comparison between things which *should* be pretty different. You need to post your matrix multiplication code so that the regulars on this list can tear it to pieces :-) >>From the profile you gave, it looks like you parameterized your matrix multiplication code over the + and * operations over matrix elements. This is good for genericity but not so good for performance, as it will result in more boxing (heap allocation) of floating-point values. The first thing you should try is write a version of matrix multiplication that is specialized for type "float". Then, there are several ways to write the textbook matrix multiplication algorithm, some of which perform less boxing than others. Again, post your code and we'll let you know. > Currently I'm just using native (double-precision) ocaml floats and > the native ocaml arrays for a first pass on the problem. Now I'm > thinking about moving to using float32 bigarrays, and I'm hoping > that the code will double in speed. I'd like to know: is that > realistic? Any other suggestions? It won't double in speed: arithmetic operations will take exactly the same time in single or double precision. What single-precision bigarrays buy you is halving the memory footprint of your matrices. That could result in better cache behavior and therefore slightly better speed, but it depends very much on the sizes and number of your matrices. - Xavier Leroy