The Flop (Floating Point Operations per Second) Rate of MATLAB Code

조회 수: 27 (최근 30일)
Royi Avital
Royi Avital 2014년 1월 28일
댓글: Walter Roberson 2019년 6월 16일
Hello, I know Intel MKL / IPP libraries performance in simple operations (Multiplication, Summation, Matrix Multiplication, Vector Multiplication) gets something like 80-95% of the theoretical performance of the CPU (Measured in FLOPS).
Yet, doing so using MATLAB I get much worse results.
I have this simple script:
numElements = 2 ^ 16;
numIter = 100;
vecX = randn(numElements, 1, 'single');
vecY = randn(numElements, 1, 'single');
initTime = tic();
for ii = 1:numIter
vecX .* vecY;
end
stopTime = toc(initTime);
gFlops = (numElements * numIter) / stopTime
Yet I get only 1.1 GFLOPS on my i7-860 Which should be closer to 2.8GHz (Frequency) * 4 (Cores) * 4 (Single Precisio Operations per Cycle as SSE Vector - 128 Bit) = 44.8 GFLOPS.
Yet I get something like 1.4 GFLOPS. Which is only 3% of the theoretical performance.
How can MATLAB be so inefficient?
  댓글 수: 2
Amit
Amit 2014년 1월 28일
BTW, MATLAB is only using 1 core, I'd believe. And for a benchmark, is there anything else running besides MATLAB?
Royi Avital
Royi Avital 2014년 2월 19일
MATLAB use more than one core.

댓글을 달려면 로그인하십시오.

채택된 답변

Amit
Amit 2014년 1월 28일
편집: Amit 2014년 1월 28일
I don't think the way you're trying to calculate flops here is right. Even if one assumes that you can calculate Flops like this, you're missing out many overheads that matlab is doing. For example, try something like this:
numElements = 2 ^ 18;
numIter = 100;
vecX = randn(numElements, 1, 'single');
vecY = randn(numElements, 1, 'single');
initTime = tic();
% for ii = 1:numIter
% vecX .* vecY;
% end
vecX + vecY; % I used +, but you can switch to .* as well
stopTime = toc(initTime);
gFlops = (numElements * numIter) / stopTime
And see if you see any difference. I am pretty sure you will. Remember, for loop is slow.
  댓글 수: 4
Salma Hassan
Salma Hassan 2019년 6월 16일
can i use tic and toc only to compue the time elpase
Walter Roberson
Walter Roberson 2019년 6월 16일
tic and toc only provide elapsed time information, which is not the same as the amount of computation done, as elapsed time can include time that the operating system suspended MATLAB in order to work on something else.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 28일
single() is often slower than double()
Your arrays are not that big; I am not sure that it is kicking in calls to the libraries.
  댓글 수: 2
Royi Avital
Royi Avital 2014년 1월 28일
I tried with doubles and larger vectors. Same result.
Feel free to try yourself and show results with better utilization of the CPU.
Such a pity this software isn't close to take a real advantage of the resources.
Walter Roberson
Walter Roberson 2014년 1월 29일
Try with timeit. Or if you have an older MATLAB that does not have that built-in, you can get timeit from the File Exchange.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by