Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. //  #pragma omp parallel for shared(vect) num_threads(thr) schedule (static)
  2. //  #pragma omp parallel for shared(vect) num_threads(thr) schedule (dynamic)
  3. //  #pragma omp parallel for shared(vect) num_threads(thr) schedule (guided)
  4.  
  5. #include <math.h>
  6. #include <omp.h>
  7. #include <iostream>
  8. #include <vector>
  9. #include <ctime>
  10.  
  11. #define VALUE 10000
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.     srand(time(NULL));
  18.     vector<int> vect;
  19.  
  20.     //Generowanie licz na wtkach 1-8
  21.     for(int thr=1; thr<=1; thr++){
  22.  
  23.             //Generowanie liczb
  24.             for (int i=0; i<VALUE; i++){
  25.                 vect.push_back(rand()%VALUE);
  26. //                vect.push_back(5);
  27.             }
  28.  
  29.             double start = omp_get_wtime();
  30.  
  31. #pragma omp parallel for shared(vect) num_threads(8) schedule (guided)
  32.             //  schedule (static)
  33.             //  schedule (dynamic)
  34.             //  schedule (guided)
  35.  
  36.             for (int i=0; i<vect.size(); i++){
  37.                 bool check = true;
  38.                 for (int j=2; j<=sqrt(vect[i]); j++){
  39.                     if(vect[j]%j==0){
  40.                         check = false;
  41.                         break;
  42.                     }
  43.                 }
  44.             }
  45.             double end = omp_get_wtime();
  46.  
  47.             int sum = 0;
  48.  
  49. //#pragma omp parallel for shared(vect) num_threads(thr) reduction(+ : sum)
  50.  
  51. //            for(int i=0; i<vect.size(); i++){
  52. //                sum = sum + vect[i];
  53. //            }
  54.  
  55.             printf("Thread: %d, Time: %lf \n", thr, end-start);
  56.             //printf("Thread: %d, Sum: %d \n", thr, sum);
  57.     }
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement