0

I have a code needs to do some matrix multiplication like

    ML2=ML+uMc+c1+c2
    MC2=v*ML+(u*v+1)*Mc+c2

Where ML is MXM matrix of

    ML=[1 1 1 1....1;2 2 2 2...2......;M M M.....M]
    MC=[1 2 3 4 ...M;1 2 3 4...M......;1 2 3.....M]

u,v,c1 and c2 are constant of 8 bit.

I want to find the values of ML2,MC2 in fast execution time using any fast library

rciovati
  • 27,603
  • 6
  • 82
  • 101
Mousa Farajallah
  • 167
  • 1
  • 1
  • 11
  • I think [this question](http://stackoverflow.com/questions/4501322/c-libraries-for-mathematical-matrix-operations) will help you out. – Josh Jun 17 '13 at 13:37

3 Answers3

1

You did not state the platform you want this for but for matrix operations nothing is faster than the Intel Math Kernel Library for Intel CPUs

http://software.intel.com/en-us/intel-mkl

This gets as close as I have seen to the peak flops possible on the CPU. MKL, however, is expensive and closed source. If you want a good open sourced and free alternative then check out Eigen. This uses C++ but I don't know if you're really restricted to C only code. Eigen also works well on other hardware such as AMD (Intel cripples it's library on AMD CPUs) and ARM.

http://eigen.tuxfamily.org/index.php?title=3.0

A third option to write one yourself. After a few weeks of effort it should not be too difficult to beat Eigen with AVX and OpenMP (Eigen only supports SSE) but it's highly unlikely you will beat MKL.

  • Thanks for all, But I need fast free library to make matrix multiplication in C code, not other languages, also the op is windows 32 bit – Mousa Farajallah Jun 17 '13 at 14:22
0

For multiplication of matrixA(AxB) and matrixB(BxC) matrix to result in matrixC(AxC)

for(int i=0;i<l;i++)
{
    for(int j=0;j<n;j++)
    {
        matrixC[i][j]=0;
        for(int k=0;k<m;k++)
        {
            matrixC[i][j]=matrixC[i][j]+(matrixA[i][k] * matrixB[k][j]);
        }
    }
}
pcbabu
  • 2,219
  • 4
  • 22
  • 32
  • 1
    That's the naive implementation of matrix multiplication which is highly inefficient. It's likely to get less than 1% of the efficiency of the peak FLOPS/s of the CPU. The OP asked for a fast library. –  Jun 17 '13 at 14:00
0

Since ML is bunch of identical vectors 1:M, and MC is just the transpose of ML, you don't need general matrix multiplication. You can take algebraic short-cuts.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135