Matlab matrix multiplication speed

后端 未结 2 1213
感情败类
感情败类 2021-01-05 06:44

I was wondering how can matlab multiply two matrices so fast. When multiplying two NxN matrices, N^3 multiplications are performed. Even with the Strassen Algorithm it take

2条回答
  •  灰色年华
    2021-01-05 06:58

    It's a combination of several things:

    • Matlab does indeed multi-thread.
    • The core is heavily optimized with vector instructions.

    Here's the numbers on my machine: Core i7 920 @ 3.5 GHz (4 cores)

    >> a = rand(10000);
    >> b = rand(10000);
    >> tic;a*b;toc
    Elapsed time is 52.624931 seconds.
    

    Task Manager shows 4 cores of CPU usage.

    Now for some math:

    Number of multiplies = 10000^3 = 1,000,000,000,000 = 10^12
    
    Max multiplies in 53 secs =
        (3.5 GHz) * (4 cores) * (2 mul/cycle via SSE) * (52.6 secs) = 1.47 * 10^12
    

    So Matlab is achieving about 1 / 1.47 = 68% efficiency of the maximum possible CPU throughput.

    I see nothing out of the ordinary.

提交回复
热议问题