Hello,
Assuming the following code, I want to measure how much cpu time is spent on executing funcA and funcB, respectively. FuncA and FuncB can invoke (multiple) parallel_for routines.
[cpp]int main() {
...
parallel_invoke( []{ funcA(); }, []{ funcB(); } );
...
}
void funcA( void ) {
...
parallel_for( ... ) {
...
}
...
}
void funcB( void ) {
...
parallel_for( ... ) {
...
}
...
}[/cpp]
What's the best way to do this (this does not need to be super accurate)? I googled a lot and what I have found is to use clock_gettime (with CLOCK_THREAD_CPUTIME_ID) or getrusage (with RUSAGE_THREAD) and use this function at the beginning and the end of every code block like the code below, but this becomes pretty ugly if there are multiple parallel_for routines (and those routines also invoke parall_for routinesin a nested fashion) and these are spread in multiple files.
[bash]void funcA( void ) {
start;
end;
time = 0;
clock_gettime( ..., &start );
...
clock_gettime( ..., &end );
time += diff( end, start );
parallel_for( ... ) {
lStart;
lEnd;
clock_gettime( ..., &lSTart );
...
clock_gettime( ..., &lEnd );
time += diff( lEnd, lStart );//atomic
}
clock_gettime( ..., &start );
...
clock_gettime( ..., &end );
time += diff( end, start );
}[/bash]
Is there a better way to do this? Such as invoking some function just at the beginning and the end of funcA and funcB and get the same results...