#include #include #include #include "omp.h" #define NELEMENTS 1024*8*2 int global_NumThreads; double time; float A[NELEMENTS], B[NELEMENTS], C[NELEMENTS]; int main(){ for (int i = 0; i < NELEMENTS; i++) { A[i] = 1.5*i; B[i] = 3.5*i; } time = omp_get_wtime(); #pragma omp parallel for schedule(static) for(int i=0; i < NELEMENTS; i ++) { //C[i] = A[i] + B[i]; usleep(3*i); } printf("STATIC: %f \n", omp_get_wtime() - time); time = omp_get_wtime(); // tukaj T0: 0..3, 64..67, 128..131, ... T1: 4..7, 68..71, ... #pragma omp parallel for schedule(static, 4) for(int i=0; i < NELEMENTS; i ++) { //if (omp_get_thread_num() == 0) printf("T%d: i=%d \n", omp_get_thread_num(), i); //C[i] = A[i] + B[i]; usleep(3*i); } printf("STATIC BLOČNO: %f \n", omp_get_wtime() - time); time = omp_get_wtime(); #pragma omp parallel for schedule(dynamic, 4) for(int i=0; i < NELEMENTS; i ++) { //if (omp_get_thread_num() == 0) printf("T%d: i=%d \n", omp_get_thread_num(), i); //C[i] = A[i] + B[i]; usleep(3*i); } printf("DYNAMIC BLOČNO: %f \n", omp_get_wtime() - time); /* for (int i = 0; i < NELEMENTS; i++) { printf("%2f ", C[i]); } */ return 0; }