Running PAPI FLOPS in the MATLAB Environment
If you want to measure the rate of floating point operations
in a MATLAB program, PAPI FLOPS is a good way to do it.
PAPI FLOPS uses the PAPI library and underlying hardware counters
to accurately compute both the total number of floating point operations
and the rate of floating point execution in a section of
For more information on the flops function,
you can type 'help flops' inside MATLAB.
FLOPS - Has 3 execution possibilities:
Initialize FLOP counting or reset the counters with:
Record the number of floating point instructions since
ops = FLOPS
Record the number of floating point instructions and
the incremental rate of floating point execution
[ops, mflips] = FLOPS
PAPI_flops.c, when compiled, turns into a callable function in MATLAB.
In order to use this function, you need to know a little
about mex. mex is simply the compiler you use to make your
code run in the MATLAB environment. If you don't know
how to use mex, you might want to acquaint yourself a bit.
"mex -setup "might be needed if you encounter problems, but
the simplest explanation might be to substitute "mex" for
"gcc" and you are on your way.
All the other rules for compiling PAPI are the same. mex
compilations can de done inside or outside of the Matlab
environment, but in this case, it is recommended that you
compile outside of Matlab. For some reason, compiling
inside does not work on some systems.
So far, the Linux environment and the Windows environment
have been tested, but _in theory_ this code should work anywhere
PAPI and Matlab both work.
The following instructions are for a Linux/Unix environment:
Assuming papi.h is present in /usr/local/include and libpapi.a
is present in /usr/local/lib, the below should work. If not,
you may need to alter the compile strings and/or the #include
statement in PAPI_flops.c. Also, the compile string will be
different for different platforms.
For instance, if I want to compile and run on a linux
machine assuming PAPI_flops.c is in your current working
directory (you'll have a different compile string on a
1. Compile the wrapper:
mex -I/usr/local/include PAPI_flops.c /usr/local/lib/libpapi.a -output flops
2. Start Matlab:
3. Run the code:
b. Play with FLOPS - the first initializes the counting;
the second returns the number of floating point instructions
since the first call, and the third line does the same as the
first AND reports the incremental rate of floating point
execution since the last call:
ins = FLOPS
[ins, mflips] = FLOPS
c. Try the example m files included with the distribution:
Contact firstname.lastname@example.org with any questions regarding
PAPI calls in Matlab - either errors or questions.
Also, this has just been implemented, so changes could