|
|
@ -17,29 +17,5 @@ int main(int argc, char* argv[]) { |
|
|
|
MainWindow w; |
|
|
|
MainWindow w; |
|
|
|
w.show(); |
|
|
|
w.show(); |
|
|
|
|
|
|
|
|
|
|
|
for (int threads = 1; threads <= 16; threads++){ |
|
|
|
|
|
|
|
int num_steps = 100'000; |
|
|
|
|
|
|
|
double step = 1.0 / double(num_steps); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
omp_set_num_threads(threads); |
|
|
|
|
|
|
|
double pi = 0; |
|
|
|
|
|
|
|
auto t = high_resolution_clock ::now(); |
|
|
|
|
|
|
|
#pragma omp parallel |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int numThreads = omp_get_num_threads(); |
|
|
|
|
|
|
|
int threadId = omp_get_thread_num(); |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
double localSum = 0; |
|
|
|
|
|
|
|
for (i = threadId; i < num_steps; i += numThreads){ |
|
|
|
|
|
|
|
double x = (i + 0.5) * step; |
|
|
|
|
|
|
|
localSum += 4.0 / (1.0 + x * x); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#pragma omp atomic |
|
|
|
|
|
|
|
pi += localSum * step; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::cout << threads << " " << duration_cast<microseconds>(high_resolution_clock::now() - t).count() << " "; |
|
|
|
|
|
|
|
std::cout << pi << std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return QApplication::exec(); |
|
|
|
return QApplication::exec(); |
|
|
|
} |
|
|
|
} |
|
|
|