我正在嘗試測量與 OpenMP 并行化的方法(C 程式)的執行時間。我需要比較并行化演算法(使用 OpenMP)及其順序版本的執行時間。我omp_get_wtime()在并行情況下和gettimeofday()順序情況下使用該方法能夠進行比較。我想知道這種比較的方法是否正確。謝謝你的幫助。
這是我用來定義宏的代碼:
#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
uj5u.com熱心網友回復:
當然,為什么不呢。最后一行看起來有點麻煩。為什么不喜歡這個:
x = (end_##id.tv_sec - start_##id.tv_sec) (end_##id.tv_usec - start_##id.tv_usec) * 1.e-6;
除此之外,如果您只需要掛鐘時間,您的解決方案就可以正常作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/346542.html
上一篇:未創建sqflite表
