Advertisement
Guest User

Untitled

a guest
May 25th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. // całkaPoj.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <omp.h>
  6. #include <iostream>
  7. #include <math.h>
  8. #include<stdlib.h>
  9. #include <time.h>
  10. using namespace std;
  11.  
  12. double calka=0, czesccalki=0; //poczatkow wartosci
  13. int i, j; //iteratory
  14. double xp = 0; // przedzialy
  15. double xk = 2;
  16. double h = (xk - xp) / 1000; //krok, wysokość prostokąta
  17.  
  18. double f(double x, int iterator)
  19. {
  20. return sin(iterator*x) / (1+iterator); //wzor na calke
  21. }
  22.  
  23. clock_t start;
  24.  
  25. int main()
  26. {
  27. //omp_set_nested(1);
  28.  
  29. start = clock();
  30.  
  31. #pragma omp parallel for private(i,j,calka) shared(h) num_threads(4)
  32. for (i = 1; i< 100 ; i++)
  33. {
  34. calka = 0.0;
  35. #pragma omp parallel for reduction (+:czesccalki)
  36. for (j = 1; j < 1000; j++)
  37. {
  38. czesccalki = f(xp + (j*h), i)*h;
  39. calka += czesccalki;
  40. }
  41. printf("dla k %d calka: %f \n", i, calka);
  42.  
  43. }
  44. printf("Czas obliczania calki= %lu ms \n\n", clock() - start);
  45.  
  46. system("PAUSE");
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement