Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <time.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /*   gcc -fopenmp -o aufg3 aufg3.c -lgomp; OMP_NUM_THREADS=7 ./aufg3   */
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     int i, N;
  10.     double h, x, sum, PI;
  11.  
  12.     N = 1999999999;
  13.  
  14.     h = 1.0/N;
  15.     sum = 0;
  16.    
  17.     time_t start, end;
  18.     time(&start);
  19.  
  20. #pragma omp parallel private (i,x) shared (N,h,sum)
  21. {
  22. #pragma omp for reduction (+:sum) schedule (static) nowait
  23.     for ( i=1 ; i<=N ; i++ ) {
  24.         x = h * (i - 0.5);
  25.         sum = sum + 4/( 1 + x*x );
  26.     }
  27. }
  28.  
  29.     time(&end);    
  30.     printf("Dauer: %.2lf Sekunden", difftime(end, start));
  31.  
  32.     PI = h * sum;
  33.  
  34.     printf(" PI = %f\n",PI);
  35.     printf(" woozaaa");
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement