2

I want to know if my program was run in parallel over multiple cores. I can get the perf tool to report how many cores were used in the computation, but not if they were used at the same time (in parallel).

How can this be done?

ivarec
  • 2,542
  • 2
  • 34
  • 57

2 Answers2

1

You can try using the command top in another terminal while the program is running. It will show the usage of all the cores on your machine.

optimist
  • 1,018
  • 13
  • 26
  • It might be a good solution. When top reports a CPU usage of 200%, will it always mean that two cores are being used? And so on? – ivarec Jun 21 '15 at 18:07
  • 2
    A small script running top in batch mode and some awk magic did the job. – ivarec Jun 21 '15 at 22:05
1

A few possible solutions:

  • Use htop on another terminal as your program is being executed. htop shows the load on each CPU separately, so on an otherwise idle system you'd be able to tell if more than one core is involved in executing your program.

    It is also able to show each thread separately, and the overall CPU usage of a program is aggregated, which means that parallel programs will often show CPU usage percentages over 100%.

  • Execute your program using the time command or shell builtin. For example, under bash on my system:

    $ dd if=/dev/zero bs=1M count=100 2>/dev/null | time -p xz -T0 > dev/null
    real 0.85
    user 2.74
    sys 0.14
    

    It is obvious that the total CPU time (user+sys) is significantly higher than the elapsed wall-clock time (real). That indicates the parallel use of multiple cores. Keep in mind, however, that a program that is either inefficient or I/O-bound could have a low overall CPU usage despite using multiple cores at the same time.

  • Use top and monitor the CPU usage percentage. This method is even less specific than time and has the same weakness regarding parallel programs that do not make full use of the available processing power.

thkala
  • 84,049
  • 23
  • 157
  • 201