Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #pragma omp parallel for shared(vect) num_threads(thr) schedule (static)
- // #pragma omp parallel for shared(vect) num_threads(thr) schedule (dynamic)
- // #pragma omp parallel for shared(vect) num_threads(thr) schedule (guided)
- #include <math.h>
- #include <omp.h>
- #include <iostream>
- #include <vector>
- #include <ctime>
- #define VALUE 10000
- using namespace std;
- int main()
- {
- srand(time(NULL));
- vector<int> vect;
- //Generowanie licz na wtkach 1-8
- for(int thr=1; thr<=8; thr++){
- //Generowanie liczb
- for (int i=0; i<VALUE; i++){
- // vect.push_back(rand()%VALUE);
- vect.push_back(1);
- }
- double start = omp_get_wtime();
- #pragma omp parallel for shared(vect) num_threads(thr)
- // schedule (static)
- // schedule (dynamic)
- // schedule (guided)
- for (int i=0; i<vect.size(); i++){
- bool check = true;
- for (int j=2; j<=sqrt(vect[i]); j++){
- if(vect[j]%j==0){
- check = false;
- break;
- }
- }
- }
- double end = omp_get_wtime();
- int sum = 0;
- #pragma omp parallel for shared(vect) num_threads(thr)
- // reduction(+ : sum)
- for(int i=0; i<vect.size(); i++){
- sum = sum + vect[i];
- }
- // printf("Thread: %d, Time: %lf \n", thr, end-start);
- printf("Thread: %d, Sum: %d \n", thr, sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement