time-measurement-openmp
Table of Contents
Time measurement (OpenMP)
Time measurement in OpenMP is done with omp_get_wtime(), which returns elapsed wall-clock time in seconds as a double. Calling it before and after a parallel region gives the actual time the user waited, which is what matters for speedup measurement. CPU time is not useful here: it sums across all threads and grows with thread count rather than shrinking.
double t0 = omp_get_wtime(); #pragma omp parallel for for (int i = 0; i < N; i++) a[i] = foo(i); printf("%.4f s\n", omp_get_wtime() - t0);
Speedup is the serial wall time divided by the parallel wall time. To get a meaningful serial baseline, either run the same binary with OMP_NUM_THREADS=1 or time the region before adding any pragmas.
time-measurement-openmp.txt ยท Last modified: by 127.0.0.1
