Path: news.mathworks.com!not-for-mail
From: "Tim Davis" <davis@cise.ufl.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: faster way to multiply 100,000 times (in ODE)
Date: Tue, 13 May 2008 13:21:02 +0000 (UTC)
Organization: University of Florida
Lines: 33
Message-ID: <g0c4ju$4f5$1@fred.mathworks.com>
References: <g0biif$g5p$1@fred.mathworks.com>
Reply-To: "Tim Davis" <davis@cise.ufl.edu>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1210684862 4581 172.30.248.35 (13 May 2008 13:21:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 13 May 2008 13:21:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:468136


"Chris " <cag44@removethispitt.edu> wrote in message
<g0biif$g5p$1@fred.mathworks.com>...
> One step is bogging down an ode file that simulates network 
> activity.  I've got to multiply an initial conditions 
> vector of length 1000 by the 1000x1000 connectivity 
> matrix.  The 1Kx1K matrix has 10% ones and is declared 
> sparse.  Essentially I'm just running IC*Connectivity.
> 
> This multiplication needs to occur once every iteration of 
> solving the ODE's.  It's such a basic operation, but I'm 
> wondering if there is anything that may speed it up.   90% 
> of the ODE run time is spent doing this multiplication (an 
> it's not a simple set of ODE's either).
> 
> Thanks!

If you don't have MATLAB 7.6, upgrade; the sparse-times-full
is faster there (see the release notes).  The speedup is
more for A*B when B has more than one column, though, so you
might not see much improvement.

Another option is to compute C'*B instead, where C=A'.  That
sounds counter-intuitive, but it's faster in MATLAB 7.6 (and
perhaps earlier), if I recall.  It has to do with the sparse
matrix storage.  For sparse-times-full matrix, I think it's
faster if the sparse matrix is stored in row major order. 
That's from memory, though (mine, not the computers...) from
lots of experiments I've played with.  Memory may be faulty.

Storing a matrix in row order is the same as doing C=A'. 
Then when MATLAB does C'*B it's smart enough not to compute
C' first.