The program counts FLOPS of a MATLAB file, either as a script or function. By scanning and parsing each line of the MATLAB codes, we infer the floating point operations based on matrix sizes. Arithmetic operations, matrix decompositions, elementary functions and common statistics functions are counted. The program supports user-defined new rules, which can override our predetermined rules by a spreadsheet. For details of software usage, refer to the enclosed PDF documentation ‘User Guide for FLOPS’.
Step 1: Prepare your MATLAB codes in a script or function, say fileName.m.
Step 2: Save all the variables in a MAT file. For example:
Step 3: Profile the MATLAB codes.
(run your MATLAB codes here, say filename(A,B,C,D))
profileStruct = profile('info');
Step 4: Count FLOPS by calling the function
The parsing and counting results will be displayed on the screen and sent to output arguments.
Thank you very much for the bug report. The flop count software does not know how MATLAB parses code, and the software only recognizes simple code patterns. Users are encouraged to simplify code so that the software can identify the operators and the corresponding flops. I try my best to revise the software so that it will recognize more complicated code patterns.
Thank you for this useful tool.
I noticed a bug related to Matlab comments.
I tested your tool putting only: "x = magic(3);%+magic(3);" in a script and I got: "FLOPs = 9 * 1 = 9", where it should be zero.
I got the correct "FLOPs = 0 * 1 = 0" After adding a space between the semicolon and the % symbol for comments.
Thank you for your interest in the FLOPS counter. If we are aware of the theoretic FLOPS for a function, we could add a rule to the spreadsheet ExtendedRules.xlsx. For example, suppose that A is a m-by-p matrix and we believe SVD requires 2np^2+2n^3 FLOPS, we could add a row to the spreadsheet (with three columns), say
First column: svd
Second column: 2*nrow*ncol^2+2*nrow^3
Third column: some arbitrary text for comments
After running the program, the second output argument “Details” should show how much FLOPS are counted for each line of the code. If the extended rule is recognized by the software, we should see the additional FLOPS shown in “Details”.
Since you mentioned this code does not compute flops for nested functions, I was wondering how one can have a work around in order to compute flops for built in matlab functions like null() or svd() etc.. Thanks for your contribution.
Thank you for your interests in the FLOP counting tool.
If the arithmetic operations are based on complex numbers, you may consider overriding the internal rules by editing the spreadsheet ExtendedRules.xlsx. Basically, overload +, -, *,/, ect in the first and second columns of the spreadsheet.
Alternatively, you can modify the codes directly by rewriting the internal rules. From about Line 1130, there is a switch...case... block, in which FLOPS of arithmetic operations + - * / are defined.
Hi Hang Qiang,
Thanks for the nice tool. When I multiply two complex numbers, it shows 1 FLOP, which is actually 6. Any idea that how to fix this? Actually, my application is based on matrices with complex values.
Thanks again for your support.
thank you for valuable and important contribution. It is very much useful to my research.
Thanks Hang for your useful codes. I will cite your codes if I succeed to publish a paper.
Thank you for your interest in my codes. I developed that tool when I was working on a research paper. I tried my best to make the FLOPS counting as accurate as possible. Comments and bug reports are welcome and sincerely appreciated.
As for the citation, I think the file exchange ID and the version number is unique to each MATLAB central submission, and other researchers can retrieve the original file to reproduce the results. So I would suggest citation like
Qian, Hang (2015). Counting the Floating Point Operations (FLOPS), MATLAB Central File Exchange, No. 50608, Ver. 1.0, Retrieved June 30, 2015.
Thanks for the file. It's very useful in my research. How can I cite your work in my papers?
Create scripts with code, output, and formatted text in a single executable document.