Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 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<=8; thr++){
  22.  
  23.         //Generowanie liczb
  24.         for (int i=0; i<VALUE; i++){
  25. //            vect.push_back(rand()%VALUE);
  26.                 vect.push_back(1);
  27.         }
  28.  
  29.         double start = omp_get_wtime();
  30.  
  31. #pragma omp parallel for shared(vect) num_threads(thr)
  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)
  50. //        reduction(+ : sum)
  51.  
  52.             for(int i=0; i<vect.size(); i++){
  53.                 sum = sum + vect[i];
  54.             }
  55.  
  56. //        printf("Thread: %d, Time: %lf \n", thr, end-start);
  57.         printf("Thread: %d, Sum: %d \n", thr, sum);
  58.     }
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement