From radford at cs.toronto.edu  Tue Aug 24 04:39:58 2010
From: radford at cs.toronto.edu (Radford Neal)
Date: Mon, 23 Aug 2010 22:39:58 -0400
Subject: [Rd] Speeding up matrix multiplies
In-Reply-To: <95C122CC-D17A-4007-ABDF-C77841E4000C@r-project.org>
References: <20100823233927.GA21529@cs.toronto.edu>
	<95C122CC-D17A-4007-ABDF-C77841E4000C@r-project.org>
Message-ID: <20100824023958.GA10777@cs.toronto.edu>

> On Aug 23, 2010, at 7:39 PM, Radford Neal wrote:

> > In particular, all matrix x vector and vector x matrix products will 
> > in this version be done in the matprod routine, not the Fortran routine.
> > And this is the right thing to do, since the time for the ISNAN check
> > before calling the Fortan routine will be comparable to the time for
> > the matrix multiply.  So avoiding it will be desirable unless the Fortran
> > routine is really, really faster than the C code in matprod.
>
> It is, many times in fact, if you use threaded BLAS on a multi-core machine 
> and large matrices.

Well, it can't get any faster than taking zero time.  And even in that
case, using the C code in matprod will slow the program down (compared
to the existing version of R) by only about a factor of two.  

> > Of course, the real solution is to change the Fortran routine (which
> > seems to be in src/extra/blas/blas.f, and isn't all that complicated)
> 
> Nope - it can be external and BLAS standard doesn't handle NAs.

OK.  I see the problem if people can link in their own version of BLAS.
I wonder if there is any way of telling whether they did that?  Presumably
many people will use the BLAS routine supplied with R, which could be
made safe for NAs.

   Radford Neal



[Rd] Speeding up matrix multiplies
Radford Neal