Thread: Blas

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    10

    Blas

    I tried to call cblas_dgemm from C++ code to do matrix multiplication. But with same matrices, the C++ code is much slower than matlab command C=A*B. Anybody know why? I thought matlab also uses BLAS.

    Thanks!

  2. #2
    Registered User
    Join Date
    Apr 2010
    Posts
    88
    Searching Wikipedia for BLAS and GEMM, the following sentences stands out:

    "Heavily used in high-performance computing, highly optimized implementations of the BLAS interface have been developed by hardware vendors such as Intel and AMD, as well as by other authors"


    "GEMM is often tuned by High Performance Computing vendors to run as fast as possible, because it is the building block for so many other routines. It is also the most important routine in the LINPACK benchmark. For this reason, implementations of fast BLAS library typically focus first on GEMM performance."

    My guess is that Matlab, being expensive as it is, has some proprietary optimization under the hood.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    cblas_dgemm does more than matrix multiplication (IIRC, it actually turns C into x*A*B + y*C or something similar, where x and y are scalars) so is almost certainly not ideally tuned for performance of a simple matrix multiplication (even if its implementation is tuned for each hardware architecture).

    I therefore wouldn't bet that Matlab uses cblas_dgemm for a simple matrix multiplication - either some other more dedicated BLAS function is used, or something optimised by hand.

    Even if Matlab does use cblas_dgemm for a simple matrix multiplication, it probably employs additional techniques designed to optimise performance for storage and access of matrices and vectors.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. blas library
    By shuo in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2007, 07:31 AM
  2. MATLAB user trying to use gcc in cygwin (with BLAS and LAPACK)
    By greek_tragedy in forum C Programming
    Replies: 0
    Last Post: 07-23-2007, 02:29 PM