Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <omp.h>
  4. #include <math.h>
  5. //#include "pomiar_czasu.h"
  6.          
  7.  
  8. double function (double x)
  9. {
  10.     return (5*x)/(sqrt(x));
  11. }
  12.          
  13. double x1 = 10, x2 = 100, dx, calka = 0;
  14. int i, n = 1000000;
  15.  
  16. int main(void)
  17. {      
  18.     printf("\n ********************************************************* \n ");
  19.        
  20.     /*printf("\nPodaj x1\n");
  21.     scanf("%f", &x1);
  22.        
  23.     printf("\nPodaj x2\n");
  24.     scanf("%f", &x2);
  25.        
  26.     printf("\nPodaj dokladnosc\n");
  27.     scanf("%d", &n);*/
  28.    
  29.     double start_time = omp_get_wtime();
  30.    
  31.     dx = (x2-x1) / (double) n;
  32.            
  33.     //printf("\nSekwencyjnie\n");
  34.     printf("\nParallel - 4 \n");
  35.     #pragma omp parallel for reduction (+: calka) num_threads(4)
  36.     for (i = 1; i < n; ++i) {
  37.       calka += function(x1+i * dx);
  38.     }
  39.    
  40.     calka += (function(x1) + function(x2)) / 2;
  41.     calka *= dx;
  42.        
  43.     double time = omp_get_wtime() - start_time;
  44.    
  45.     printf("\nCalka wynosi: %lf\n", calka);
  46.     printf("\nCzas wynosi: %lf\n", time);
  47.        
  48.     printf("\n ********************************************************** \n");
  49.        
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement