0

I am started to learn parallel programming and for calculating the performance i should know the accurate time that program seek.

so I want to measure the amount of time that my C program seek under the Linux but It just show me some divergent answer.

In my opinion it should be related to other processes get the time,by the way i am using this instructions :

double start ,end;
start = omp_get_wtime();
.
.
.
end = omp_get_wtime();
result = end- start;

Thank you in advance.

pooria
  • 343
  • 2
  • 14
  • Please clarify what "time" you actually want to measure. Are you familiar with the differences between wall time and CPU time? It is also essentially that you show your specific results and how it differs from what you expected. It is completely unclear what "some divergent answer" means. – Zulan Jul 14 '16 at 18:10

2 Answers2

1

For conducting accurate benchmarks, it is imperative that the external influences are suppressed as much as possible. If your system has enough CPU cores, you can isolate some of them using kernel parameters and thus prevent any other process and/or kernel tasks from using those cores:

... isolcpus=3,4,5 nohz_full=3,4,5 rcu_nocbs=3,4,5 ...

Those parameters will almost completely isolate CPUs 3, 4, and 5 by preventing the OS scheduler from running processes on them by default (isolcpus), the kernel RCU system from running tasks of them (rcu_nocbs), and prevent the periodic scheduler timer ticks (nohz_full). Make sure that you do not isolate all CPUs!

You can now explicitly assign a process to those cores using taskset -c 3-5 ... or the mechanism built into the OpenMP runtime, e.g., export GOMP_CPU_AFFINITY="3,4,5" for GCC. Note that, even if you do not use dedicated isolated CPUs, simply turning on thread pinning with export OMP_PROCBIND=true or by setting GOMP_CPU_AFFINITY (KMP_AFFINITY for Intel) should decrease the run time divergence.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
-1

Why not just use clock?

clock_t start = clock();

/* do whatever you like here */

clock_t end = clock();
double total_time = (double)(end - start) / CLOCKS_PER_SEC;

or the function

getrusage(...)

...

inzanez
  • 366
  • 1
  • 16