Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment