canavanin
canavanin

Reputation: 2719

Fortran profiling: get line execution count

I'm using the Intel Fortran Compiler (v. 12.0.3) on Linux. I'd like to perform profiling with gprof and get a basic block count with all lines labelled with their own run count, but all I have managed to obtain is a count on the program/subroutine/function level. My conclusion is that I've got the compiler flags wrong, but despite looking on the web and reading the ifort man page I can't figure out what I should be doing instead of what I am doing...

There are the flags I use when compiling:

-w -O0 -g -pg 

And here's how I invoke gprof:

gprof -l -A -x path/to/exe gmon.out > OUT

At first it looks as if all lines were labelled with how often they were ran, but it turns out that each block/line simply obtains the procedure count (in the following short example the function was called 43679 times, and both 'if' and 'else', for example, got labelled with 43679, which makes no sense):

43679 -> function variance_from_index (indices,array)
               ! declarations

   43679 ->    if (ubound(indices,1).eq.2) then
   43679 ->       variance_from_index = array(indices(1),indices(2))
                     else
   43679 ->        do i=1,ubound(indices,1)-1
   43679 ->           do j=i+1,ubound(indices,1)
   43679 ->                items(1:2)  = (/indices(i),indices(j)/)

I have already posted my question in the Intel forum, and so far I have received one reply, which pointed me to Intel's codecov tool. Despite this being a very helpful application as such, it does not seem to fit my current needs, as there seems to be no option of outputting a run count for every line of code. I'd much prefer using gprof, whose output - in principal - seems to be just what I need.

Thanks for your help!

Upvotes: 1

Views: 2250

Answers (2)

Davide
Davide

Reputation: 306

As far as I understand from my tests, ifort only supports function-level profiling with gprof, so the gprof flag -l is useless in your case. On the other side also gcc/gfortran does not support line profiling with gprof anymore in recent versions, and, as already noted, the tool to use in this case is gcov (see man gcc for more info). However it is stated that gcov is likely not to be compatible with compilers other than gcc (and gfortran of course), so you probably have to use Intel proprietary tools for ifort profiling.

Upvotes: 1

osgx
osgx

Reputation: 94435

To get line execution count, use gcov, not gprof. Gprof is statistical profiling (it will check where is your program running 100 times per second) and Gcov is coverage utility with per-basic block granularity (exactly what you need).

Can't say, is it possible to use gcov with intel fortran compiler directly. But you can use it with gfortran/g95 - per-line count execution should be the same.

Upvotes: 1

Related Questions