Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // ConsoleApplication2.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <omp.h>
  7.  
  8. using namespace std;
  9.  
  10. //zadania 1 i 3 oddane na lab
  11.  
  12. /* zad1 */
  13. /*
  14.  
  15. constexpr int milion = 1000000;
  16. int war = 0;
  17.  
  18. int main()
  19. {
  20. #pragma omp parallel sections num_threads(2) shared(war)
  21. {
  22. #pragma omp section
  23. {
  24. for (int i = 0; i < milion; ++i)
  25. {
  26. #pragma omp critical
  27. war++;
  28. }
  29. }
  30.  
  31. #pragma omp section
  32. {
  33. for (int i = 0; i < milion; ++i)
  34. {
  35. #pragma omp critical
  36. war--;
  37. }
  38. }
  39. }
  40.  
  41. std::cout << war;
  42. }
  43.  
  44. */
  45. /* /zad1 */
  46.  
  47.  
  48. /* zad3 */
  49. /*
  50. float fkw(float x) {
  51. return x*x;
  52. }
  53. float f(float x)
  54. {
  55. return x;
  56. }
  57.  
  58. float oblicz_fragm(int w_od, int w_do) {
  59. //dla funkcji x*x
  60. float h1 = fkw((float)w_od);
  61. float h2 = fkw((float)w_do);
  62. float p1 = h1 * 1.0;
  63. float p2 = ((h2 - h1)*1.0) / 2;
  64. float wynik = (float)p1 + p2;
  65. //cout << wynik << endl;
  66. return wynik;
  67. }
  68.  
  69.  
  70.  
  71. int main() {
  72. int rozmiar = 1000000;
  73. float sum = 0;
  74.  
  75. #pragma omp parallel for reduction(+:sum)
  76. for (int i = 0; i <= rozmiar-1; i++) {
  77. //cout << "i: " << i << endl;
  78. sum += oblicz_fragm(i, i + 1);
  79.  
  80. }
  81.  
  82. cout << "wynik: " << sum << endl;
  83. return 0;
  84. }
  85. */
  86. /* /zad3 */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement