I am trying to measure the execution time of a method (C program) that I have parallelized with OpenMP. I need to compare the execution times of the parallelized algorithm (with OpenMP) and its sequential version.
I am using the method omp_get_wtime()
in the parallel case and gettimeofday()
in the sequential case to be able to do the comparison.
I would like to know if this approach to making the comparison is correct or not. Thanks for your help.
Here the code i'm using to define macros:
#ifdef _OPENMP
#include <omp.h>
#define STARTTIME(id) \
double start_time_42_##id, end_time_42_##id; \
start_time_42_##id = omp_get_wtime();
#define ENDTIME(id, x) \
end_time_42_##id = omp_get_wtime(); \
x = end_time_42_##id - start_time_42_##id
#else
#include <sys/time.h>
#include <time.h>
#include <math.h>
#define STARTTIME(id) \
struct timeval start_##id; \
gettimeofday(&start_##id, NULL);
#define ENDTIME(id, x) \
struct timeval end_##id; \
gettimeofday(&end_##id, NULL); \
x = ((end_##id.tv_sec - start_##id.tv_sec) * 1000000u end_##id.tv_usec - start_##id.tv_usec) / 1.e6;
#endif
CodePudding user response:
Sure, why not. The last line looks a bit cumbersome. Why not like this:
x = (end_##id.tv_sec - start_##id.tv_sec) (end_##id.tv_usec - start_##id.tv_usec) * 1.e-6;
Other than that, if wall clock time is all you need, your solution will work just fine.