Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <omp.h>
  4.  
  5. long long num_steps = 100000000;
  6. double step;
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10. clock_t start, stop;
  11. double x, pi, sum = 0.0;
  12. int i;
  13. step = 1. / (double)num_steps;
  14. start = clock();
  15. #pragma omp parallel for
  16. for (i = 0; i<num_steps; i++)
  17. {
  18. x = (i + .5)*step;
  19. sum = sum + 4.0 / (1. + x*x);
  20. } //synchronizacja
  21.  
  22. pi = sum*step;
  23. stop = clock();
  24.  
  25. printf("Wartosc liczby PI wynosi %15.12f\n", pi);
  26. printf("Czas przetwarzania wynosi %f sekund\n", ((double)(stop - start) / 1000.0));
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement