Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When timing the wall time performance of an OpenMP program on Linux while other programs are running, how can I get the actual running time?

share|improve this question

marked as duplicate by Flup, Anthon, Zelda, Timo, peterph Apr 15 at 22:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@slm I disagree. This question is about the difference between wall clock time and time used by the process. There may well be a dupe for that, but I didn't find it. –  Gilles Apr 15 at 15:29
1  
    
@Gilles - fair enough, I've retracted my close vote. I couldn't find a more appropriate dup, several were very close but talked about real, user and sys, not close enough to qualify as an exact match to this. –  slm Apr 15 at 17:20
add comment

2 Answers 2

up vote 4 down vote accepted

Call time myprogram.

This reports wall clock time, user time and system time. User time is the time spent by the process in computations. If the program is multithreaded and the machine has multiple processors, the time spent on all processors is summed (so for a sufficiently parallel program, the user time can be more than the wall clock time). The system time is time spent in the kernel, i.e. doing input/output.

This is as close as you get to “time not counting interference by other running programs”. The only way to know how much wall clock time the program would take if there were no concurrent programs is to run it without other concurrent programs.

share|improve this answer
    
Thanks! On a shared cluster, it is difficult to run it without other concurrent programs. Some said the scheduler will only run jobs when there are sufficient resources, which still can't prevent the interference from other running programs, correct? –  Tim Apr 9 at 1:02
    
@Tim If you're running things on an actual cluster (SGE as one), these jobs attributes are also tracked by the clustering software. –  slm Apr 15 at 17:00
add comment

If you can get the pid, which shouldn't be hard with either ps, /proc/self or $! depending on whether or not you background it you can find this in:

/proc/$pid/stat:

          utime %lu   (14) Amount of time that this process has been
                      scheduled in user mode, measured in clock ticks
                      (divide by sysconf(_SC_CLK_TCK)).  This includes
                      guest time, guest_time (time spent running a
                      virtual CPU, see below), so that applications that
                      are not aware of the guest time field do not lose
                      that time from their calculations.

          stime %lu   (15) Amount of time that this process has been
                      scheduled in kernel mode, measured in clock ticks
                      (divide by sysconf(_SC_CLK_TCK)).

          cutime %ld  (16) Amount of time that this process's waited-for
                      children have been scheduled in user mode,
                      measured in clock ticks (divide by
                      sysconf(_SC_CLK_TCK)).  (See also times(2).)  This
                      includes guest time, cguest_time (time spent
                      running a virtual CPU, see below).

          cstime %ld  (17) Amount of time that this process's waited-for
                      children have been scheduled in kernel mode,
                      measured in clock ticks (divide by
                      sysconf(_SC_CLK_TCK)).

To get process ids you can do a number of things:

prog ./and/args &
pid=$!

{ prog ./and/args & true ; } && ps -C prog

prog ./and/args

CTRL-Z

jobs -l ; fg %1

There are many ways.

share|improve this answer
    
Thanks! (1) I need the real/elapsed/wall time not counting interference by other running programs. How can I get that? (2) if your case work, how can I know the pid without interfering timing the program? –  Tim Apr 8 at 22:46
    
prog ./and/args & \n pid=$! –  mikeserv Apr 8 at 22:47
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.