matheus__serpa icon

Untitled

matheus__serpa | PRO | 08/21/20 05:07:23 PM UTC | 0 ⭐ | 1612 👁️ | Never ⏰ | []
C |

1.21 KB

|

None

|

0 👍

/

0 👎

#include <stdio.h>
#include <unistd.h>
#include <omp.h>
 
int main(int argc, char **argv){
    int i, x = 1, y = 2, z = 3;
 
 
    printf("start - 4\n");
    sleep(2);
    #pragma omp parallel private(i) num_threads(4)
    {
    printf("Hello from thread %d\n", omp_get_thread_num());
    for(i = 0; i < 1500 * (omp_get_thread_num() + 1); i++){
        x = y + z;
        z = x - y;
        if(i % 500 == 0)
            sleep(1);
    }
    printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
    }
    printf("end - 4\n\n");
    
    printf("start - 6\n");
    sleep(2);
    #pragma omp parallel private(i) num_threads(6)
    {
    printf("Hello from thread %d\n", omp_get_thread_num());
    for(i = 0; i < 1000 * (omp_get_thread_num() + 1); i++){
        x = y + z;
        z = x - y;
        if(i % 500 == 0)
            sleep(1);
    }
    printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
    }
    printf("end - 6\n\n");
 
    printf("start - 2\n");
    sleep(2);
    #pragma omp parallel private(i) num_threads(2)
    {
    printf("Hello from thread %d\n", omp_get_thread_num());
    for(i = 0; i < 3000 * (omp_get_thread_num() + 1); i++){
        x = y + z;
        z = x - y;
        if(i % 500 == 0)
            sleep(1);
    }
    printf("Bye from thread %d - %d\n", omp_get_thread_num(), i);
    }
    printf("end - 2\n\n");
 
    return 0;
}

Comments