Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <omp.h>
- long long num_steps = 100000000;
- double step, table[40];
- int main(int argc, char* argv[])
- {
- clock_t start, stop;
- double x, pi, sum = 0.0;
- int i,j;
- omp_set_num_threads(2);
- step = 1. / (double)num_steps;
- for (j = 0; j < num_steps; j++){
- start = clock();
- double sum = 0;
- #pragma omp parallel
- {
- int id = omp_get_thread_num();
- table[j + id] = 0;
- #pragma omp for
- for (i = 0; i < num_steps; i++)
- {
- double x = (i + .5)*step;
- //unieważnienie całej linii danych
- table[j + id] += 4.0 / (1. + x*x);
- }
- #pragma omp atomic
- sum += table[j + id];
- }
- pi = sum*step;
- stop = clock();
- printf("Wartosc liczby PI wynosi %15.12f\n", pi);
- printf("Czas przetwarzania wynosi %f sekund\n", ((double)(stop - start) / 1000.0));
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment