Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: speeding up floating point operations
Date: Mon, 11 May 2009 20:41:01 +0000 (UTC)
Organization: Cornell University
Lines: 30
Message-ID: <gua2gt$j1q$1@fred.mathworks.com>
References: <gu2c2m$mup$1@fred.mathworks.com> <gu2kj1$ea8$1@fred.mathworks.com> <gu7iul$cut$1@fred.mathworks.com> <gu9rhq$plj$1@fred.mathworks.com> <gu9vud$nek$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1242074461 19514 172.30.248.38 (11 May 2009 20:41:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 11 May 2009 20:41:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1327593
Xref: news.mathworks.com comp.soft-sys.matlab:539089


"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu9vud$nek$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu9rhq$plj$1@fred.mathworks.com>...
> > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu7iul$cut$1@fred.mathworks.com>...
> > > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu2kj1$ea8$1@fred.mathworks.com>...
> > > > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> > > > > Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx).  Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?
> > > > 
> > > > For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.
> > > > 
> > > > James Tursa
> > > 
> > > In the version of MATLAB I have, r2008a, MATLAB uses INTEL MKL for matrix multiplication and it is really quick.  The computation I am doing doesn't require high precision and I was hoping it was possible to speed up the computation by doing lower precision computations, like some compilers allow (see above), within this library call.
> > 
> > As I understand it, the Intel MKL includes optimized BLAS routines for things such as matrix multiplication. So Intel has already gone to great lengths to make these operations as fast as possible. Are you saying you want something even faster than that?
> > 
> > James Tursa
> 
> P.S.  If you really don't care much about precision, consider using single precision. I just did a quick test of a simple A * B matrix multiply where A and B are both large double matrices. Converting both operands to single, calling SGEMM from the MATLAB supplied BLAS library, and then converting the result back to double does give you a significant time savings over the A * B operation at the MATLAB prompt. So the benefit of doing the multiply in single far outweighs the overhead of the conversions, at least for large matrices. The key is using an optimized BLAS library for the SGEMM call.
> 
> James Tursa

I am currently using single precision matrix mult and my data (input and output) is in single and it is almost 2x as quick as double.  Is the MATLAB '*' operator on singles calling the optimized BLAS SGEMM that you are referring to?  Also, I have a dual core processor and have enabled multithreading (about 1.7x speedup for matrices i'm working with).

I just found that some MKL operations allow control of precision - 
http://www.intel.com/software/products/mkl/data/vml/vmldata.htm - but I'm not sure if this is just for vector operations (like sqrt, acos, etc.) or if there is a way to set low precision for operations like matrix multiply.  I am asking if there was a similar flag to be set in MATLAB or if it is possible to set such a flag for ops like mat mult.

The reason I am asking is I have a very intensive compuation where essentially all the time is spent doing a matrix mult but the result only needs a few decimal digits of accuracy.  So any small speedup in this operation would speed up my entire computation.

Thanks again,
Nick