Hyluss

[Prir] OpenMP Barier

Dec 13th, 2017
537
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <omp.h>
  5.  
  6. #define MAX_NT 4
  7.  
  8. void
  9. thread_work(int id)
  10. {
  11.     clock_t t1, t2;
  12.  
  13.     printf("Watek %d zaczyna prace...\n", id - 1);
  14.  
  15.     t1 = clock();
  16.  
  17.     do {
  18.         t2 = clock();
  19.     }
  20.     while ((((double)t2 - t1) / CLOCKS_PER_SEC) < id);
  21. }
  22.  
  23. int
  24. main(void)
  25. {
  26.     int id;
  27.  
  28.     #pragma omp parallel num_threads(MAX_NT) private(id)
  29.     {
  30.         id = omp_get_thread_num();
  31.         thread_work(id + 1);
  32.         printf("Watek %d zakonczyl prace i czeka przy barierze...\n", id);
  33.  
  34.         #pragma omp barrier
  35.  
  36.         printf("Watek %d juz poza bariera.\n", id);
  37.     }
  38.  
  39.     printf("Nacisnij dowolny klawisz....");
  40.     getchar();
  41.  
  42.     return 0;
  43. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment