-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPI_Plouffe_OpenMP.cpp
43 lines (31 loc) · 1.06 KB
/
PI_Plouffe_OpenMP.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <omp.h>
#include <iostream>
#include <cstdlib>
#include <chrono>
#include <cmath>
#define NB_ITER 10000000
#define NB_THREADS 8
int main(int argc, char const *argv[]) {
uint64_t nb_it = static_cast<uint64_t>(NB_ITER);
uint8_t nb_th = static_cast<uint8_t>(NB_THREADS);
if (argc == 3){
nb_th = static_cast<uint8_t>(atoi(argv[1]));
nb_it = static_cast<uint64_t>(atoi(argv[2]));
}
long double pi = 0.L;
omp_set_dynamic(0);
omp_set_num_threads(nb_th);
using namespace std::chrono;
high_resolution_clock::time_point time = high_resolution_clock::now();
#pragma omp parallel
#pragma omp for reduction(+:pi)
for(unsigned int i = 0; i < nb_it; i++) {
long double k = static_cast<long double>(i);
pi += (4/(k*8 + 1) - 2/(k*8 + 4) - 1/(8*k + 5) - 1/(k*8 + 6)) / std::pow(16,k);
}
#pragma omp barrier
#pragma omp master
std::cout << "Pi : " << std::dec << pi << std::endl;
std::cout << "Effectué en : "<< duration_cast<microseconds>(high_resolution_clock::now() - time).count() << std::endl;
return 0;
}