openmp(1)----計時


時間是用來評價一個算法或代碼的重要指標。

clock_t 為時鍾周期數,在並行程序中這種方式不能測量時間。

#include <time.h>
clock_t start,finish;  
start = clock();
finish = clock();
std::cout<<"完成需要 "<<finish - start<<"個時鍾周期"<<std::endl;
std::cout<<"消耗時間為:"<<(finish - start)/CLOCKS_PER_SEC*1000<<"ms\n"<<std::endl;
// CLOCKS_PER_SEC 每秒德時鍾周期數

double omp_get_wtime() 返回絕對時間,單位為s

 

#include<omp.h>
double start = omp_get_wtime( );
double end = omp_get_wtime( );

 

double  omp_get_wtick()   返回單個時鍾周期的時間,s

#include "omp.h"
#include <stdio.h>

//獲得一個時鍾周期是多少秒
double wtick = omp_get_wtick( );
printf("wtick = %.16g\n1/wtick = %.16g\n", wtick, 1.0 / wtick);  // 每s的時鍾周期數


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM