/* cc -lm t4.c -qsmp */ #include #include #include #include #include #include #define FLT double /* utility routines */ void my_bar(); void explain(char astr[]); FLT system_clock(FLT *x); void start_time(); FLT end_time(); /* array used to determine how much work each thread performs */ int *dist,idid; FLT st; /* routine to reset dist */ void zero(int j); /* work routines */ void all_fast(); void zero_slow(); void a_slow(int i); void all_fast() { int k; k=omp_get_thread_num(); dist[k]++; } void zero_slow() { int k; FLT x,y; k=omp_get_thread_num(); dist[k]++; if(k == 0) { x=system_clock((FLT*)0); y=x+1; while(x < y) { x=system_clock((FLT*)0); } } } void imbalance (int i) { int k; FLT x,y; k=omp_get_thread_num(); dist[k]++; if(i == 1) { idid=k; x=system_clock((FLT*)0); y=x+1; while(x < y) { x=system_clock((FLT*)0); } } else { x=system_clock((FLT*)0); y=x+0.01; while(x < y) { x=system_clock((FLT*)0); } } } main() { int i,k,max_threads,total; max_threads=omp_get_max_threads(); printf("max threads = %d\n",max_threads); dist=(int*)malloc(max_threads*sizeof(int)); zero(max_threads); total=0; explain("report the % of iterations for each thread"); explain("for a set of loops"); explain("******"); explain("default scheduling"); explain("for a subroutine with little work"); k=max_threads*100; start_time(); #pragma omp parallel for for( i=1;i<=k;i++) { all_fast(); } my_bar(); for( i=0;i