matheus__serpa

Untitled

Aug 21st, 2020
1,475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <omp.h>
  4.  
  5. int main(int argc, char **argv){
  6.     int i, x = 1, y = 2, z = 3;
  7.  
  8.  
  9.     printf("start - 4\n");
  10.     sleep(2);
  11.     #pragma omp parallel private(i) num_threads(4)
  12.     {
  13.     printf("Hello from thread %d\n", omp_get_thread_num());
  14.     for(i = 0; i < 1500 * (omp_get_thread_num() + 1); i++){
  15.         x = y + z;
  16.         z = x - y;
  17.         if(i % 500 == 0)
  18.             sleep(1);
  19.     }
  20.     printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
  21.     }
  22.     printf("end - 4\n\n");
  23.    
  24.     printf("start - 6\n");
  25.     sleep(2);
  26.     #pragma omp parallel private(i) num_threads(6)
  27.     {
  28.     printf("Hello from thread %d\n", omp_get_thread_num());
  29.     for(i = 0; i < 1000 * (omp_get_thread_num() + 1); i++){
  30.         x = y + z;
  31.         z = x - y;
  32.         if(i % 500 == 0)
  33.             sleep(1);
  34.     }
  35.     printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
  36.     }
  37.     printf("end - 6\n\n");
  38.  
  39.     printf("start - 2\n");
  40.     sleep(2);
  41.     #pragma omp parallel private(i) num_threads(2)
  42.     {
  43.     printf("Hello from thread %d\n", omp_get_thread_num());
  44.     for(i = 0; i < 3000 * (omp_get_thread_num() + 1); i++){
  45.         x = y + z;
  46.         z = x - y;
  47.         if(i % 500 == 0)
  48.             sleep(1);
  49.     }
  50.     printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
  51.     }
  52.     printf("end - 2\n\n");
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment