| Thread Tools | Search this thread |
|---|
inttel
| July 7, 2009 2:59 PM PDT openmp slower than single threaded | ||||
a program for the sole purpose of trying to demonstrate the advantage of using 4 cores simultaneously is below. however, it runs for 90 seconds on a 4 core xeon (3ghz) versus 2 seconds on a single core machine. any hints greatly appreciated. Tom #include <stdio.h> #include <stdlib.h> #include <omp.h> #include <time.h> #define N 1000 #define CHUNKSIZE 25 main () { time_t sec1; time_t sec2; sec1 = time(NULL); printf("start \n"); int i, chunk; float a[N]; float b[N]; float c[N]; int j; float k; for (i=0; i < N; i++) a[i] = b[i] = i * 1.0; chunk = CHUNKSIZE; #pragma omp parallel for private(i,j,k) schedule(static,chunk) for (i=0; i < N; i++) { for (j = 0; j<200000; j++) { k = rand(); } // c[i] = a[i] + b[i]; } sec2 = time(NULL) - sec1; printf("%ld seconds", sec2); return 0; } compiled using 'gcc -O3 -fopenmp workshare2.c -o workshare2' on gcc 4.3.2 on opensuse64 11.1 | |||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
|
|||||||||||||
| 8286 users have contributed to 31232 threads and 99107 posts to date. |
|---|
| In the past 24 hours, we have 7 new thread(s) 27 new posts(s), and 36 new user(s). In the past 3 days, the most popular thread for everyone has been comparison cilk++, openmp, pthreads first results The most posts were made to comparison cilk++, openmp, pthreads first results The post with the most views is Very amusing... Escalated as Please welcome our newest member titanius.anglesmith |