This project has moved and is read-only. For the latest updates, please go here.

How to increase performance for matrix multiplication? Please help

Aug 30, 2012 at 5:23 PM

I'm writing a code where I'm performing matrix multiplication of 2000x3 into 3x3 matrices a whole lot of times (5000!). The same code in matlab takes less than a 1 sec to run but using Math.Net in C# it took me over a minute.

Is there anyway to speed up the matrix multiplication performance with



Aug 30, 2012 at 6:57 PM

Yes, that takes ~20 secs on my notebook as well (default settings hence parallelization enabled). What you can do is:

  • Disable parallelization and parallelize yourself (i.e. compute the 5000 products in parallel, but each product itself on a single thread only), this is a bit faster on my machine:
    Control.DisableParallelization = true;
    Parallel.ForEach(x, x => { x.res = x.a * x.b }); 
  • Or use a native provider, see Native Linear Algebra Providers. This should be much faster, comparable to Matlab.