Advertisement
Eeedi

PWiR Lab3 Zad9

Mar 27th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <omp.h>
  3. #define N 5
  4.  
  5. int tab[10] = {4,8,16,25,0,3,2,5,9,10};
  6. int start, i, global_max, local_max;
  7.  
  8. int main(void)
  9. {
  10. global_max = tab[0];
  11. #pragma omp parallel default(none), private(start, i, local_max), shared(tab, global_max)
  12. start=1;
  13. #pragma parallel for
  14.     for(i=0;i<10;i++)
  15.     {
  16.         if(start==1)
  17.         {
  18.             local_max=tab[i];
  19.             start=0;
  20.         }
  21.         if(tab[i]>local_max)
  22.         {
  23.             local_max=tab[i];
  24.         }
  25.     }
  26. #pragma critical
  27. if(local_max>global_max)
  28. {
  29.     global_max=local_max;
  30. }
  31. printf("Max= %d", global_max);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement