#include using namespace std; class timer { public: timer() : start_timing(hi_res_clock::now()) {} void reset() { start_timing = hi_res_clock::now(); } double elapsed() const { double temp; temp = std::chrono::duration_cast (hi_res_clock::now() - start_timing).count(); return(temp); } double time_difference() const { double temp; temp = std::chrono::duration_cast (hi_res_clock::now() - last_time).count(); return(temp); } private: typedef std::chrono::high_resolution_clock hi_res_clock; typedef std::chrono::duration > second_; std::chrono::time_point start_timing; std::chrono::time_point last_time; }; #include #include #include #include using namespace std; void print_time(const string & heading , const double & t) { cout << heading << " : " ; cout.setf(ios::right); cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.width(10); cout.precision(6); cout << t << endl; } int main() { double openmp_sum; double real_sum; double * x; int nthreads; int i; int j; int k; int l; int one_mb = 1024 * 1024; int n = 255 * one_mb; double t1,t2; timer timer_01; timer timer_02; string heading; nthreads = omp_get_max_threads(); cout << " Maximum number of threads is " << nthreads << endl; heading = "\nProgram starts"; t1=timer_01.elapsed(); t2=timer_02.elapsed(); print_time( heading , t1); k = 1; x = new double[n]; real_sum=n*1.0; for(i=0;i