#include #include #include long long num_steps = 1000000000; double step; int main(int argc, char* argv[]) { clock_t start, stop; volatile double x; double pi, sum = 0.0, tab[40]; int i; step = 1. / (double)num_steps; start = clock(); #pragma omp parallel { int id = omp_get_thread_num(); tab[id] = 0; #pragma omp for reduction(+:sum) for (i = 0; i < num_steps; i++) { x = (i + .5)*step; tab[id] += 4.0 / (1. + x*x); } #pragma atomic sum += tab[id]; } pi = sum*step; stop = clock(); printf("Wartosc liczby PI wynosi %15.12fn", pi); printf("Czas przetwarzania wynosi %f sekundn", ((double)(stop - start) / 1000.0)); return 0; }