Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. include "stdafx.h"
  2. #include "iostream"
  3. #include <thread>
  4. #include <cmath>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. bool PrimeNumberChecker(int x);
  10. void PrimeIterator(int x, int y);
  11.  
  12.  
  13.  
  14. static const int num_threads = 99;
  15.  
  16. int main()
  17. {
  18. int val1, dividend, divisor, threadIterator1, threadIterator2;
  19. int x, y, i;
  20. thread t[num_threads];
  21.  
  22. cout << "Enter Start Boundary: ";
  23. cin >> x;
  24. cout << "nEnter End Boundary: ";
  25. cin >> y;
  26.  
  27. val1 = (y - x) / 100;
  28. dividend = floor(val1);
  29. divisor = fmod(y-x, 100);
  30.  
  31.  
  32. if (y-x >= 100)
  33. {
  34. thread t2(PrimeIterator, x, divisor);
  35.  
  36. for (i = 1; i <= num_threads; i++)
  37. {
  38. threadIterator1 = dividend * i;
  39. threadIterator2 = dividend * (i + 1);
  40.  
  41. t[i] = thread(PrimeIterator, threadIterator1, threadIterator2, i);
  42. }
  43.  
  44. t2.join();
  45. for (int i = 0; i < num_threads; ++i) {
  46. t[i].join();
  47. }
  48. }
  49.  
  50.  
  51.  
  52. system("pause");
  53. return 0;
  54. }
  55.  
  56. bool PrimeNumberChecker(int x)
  57. {
  58. int i, t;
  59.  
  60. for (i = 2; i <= x ; i++)
  61. {
  62.  
  63. for (t = 2; t <= x; t++)
  64. {
  65. if (i*t == x)
  66. {
  67. return false;
  68. }
  69.  
  70. }
  71.  
  72. }
  73. return true;
  74. }
  75.  
  76.  
  77. void PrimeIterator(int startBoundary, int endBoundary)
  78. {
  79. int i;
  80.  
  81. for (i = startBoundary; i <= endBoundary; i++)
  82. {
  83. if (PrimeNumberChecker(i))
  84. {
  85.  
  86.  
  87. }
  88. }
  89.  
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement