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?
2 Answers
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.

- 829,060
-
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 09 '14 at 01: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 '14 at 17:00
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:
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.

- 58,310
-
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 08 '14 at 22:46
-
time
? – slm Apr 15 '14 at 17:03