View previous topic :: View next topic |
Author |
Message |
neuron Advocate
Joined: 28 May 2002 Posts: 2371
|
Posted: Sat Jun 09, 2007 7:02 am Post subject: Testing OpenMP |
|
|
I just installed Gcc 4.2.0 to test openmp, but... I'm getting odd results.
I tried the tutorial available here: http://www.kallipolis.com/openmp/1.html
Specifically the http://www.kallipolis.com/openmp/taylor.c and http://www.kallipolis.com/openmp/taylor_mp.c files.
Now when I compile with : gcc -O2 -fopenmp I do see the _mp spawning 2 threads and doing simultaneous work... but...
#gcc -fopenmp taylor.c && ./a.out
Reached result 8.539734 in 5990.000 seconds
#gcc -O2 -fopenmp taylor.c && ./a.out
Reached result 8.539734 in 4090.000 seconds
Fair enough, single threaded works, using -O2 speeds things up. Now to test openmp:
#gcc -fopenmp taylor_mp.c && ./a.out
Reached result 0.001322 in 8890.000 seconds
#gcc -O2 -fopenmp taylor_mp.c && ./a.out
Reached result 10.876776 in 6980.000 seconds
Using OpenMP consistently slows things down (seemingly random amounts), and the results are different based on optimization (and never what it's supposed to be). What am I missing? |
|
Back to top |
|
|
theDOC_23 Tux's lil' helper
Joined: 02 Dec 2004 Posts: 121 Location: Aachen, GER
|
Posted: Sat Jun 09, 2007 8:53 am Post subject: |
|
|
I think, there is something else broken. Look at your results of the multi threaded program. 0.001322 and 10.876776? They should be 8.539734 too.
I would try this example myself, but I cannot find an openmp ebuild in my portage tree... |
|
Back to top |
|
|
neuron Advocate
Joined: 28 May 2002 Posts: 2371
|
Posted: Sat Jun 09, 2007 12:08 pm Post subject: |
|
|
theDOC_23 wrote: | I think, there is something else broken. Look at your results of the multi threaded program. 0.001322 and 10.876776? They should be 8.539734 too.
I would try this example myself, but I cannot find an openmp ebuild in my portage tree... |
Yeah I know the results are different, but I think this must be a bug in gcc's openmp implementation or something..
And openmp is included in gcc 4.2 |
|
Back to top |
|
|
Kirschsaft n00b
Joined: 05 Jul 2003 Posts: 22
|
Posted: Sun Jun 10, 2007 5:29 pm Post subject: |
|
|
I think the first openmp pragma should be like this:
Code: | #pragma omp parallel sections shared(e, pi) private(i) |
As far as I know i is assumed to be shared otherwise and would thus need access protection. |
|
Back to top |
|
|
neuron Advocate
Joined: 28 May 2002 Posts: 2371
|
Posted: Sun Jun 10, 2007 5:42 pm Post subject: |
|
|
Kirschsaft wrote: | I think the first openmp pragma should be like this:
Code: | #pragma omp parallel sections shared(e, pi) private(i) |
As far as I know i is assumed to be shared otherwise and would thus need access protection. |
You are entirely correct, scary.. I've found that code sample in two tutorials now. It's slower still though, but I'm not terribly worried about that, the first calculation finishes so quickly it's not really part of the whole thing. But I kept comming back to that sample, as the results differed.
Thanks a lot!
//edit, oh, and another fun pitfall:
Code: |
Running test # gcc -O2 -fopenmp , Threads = 2
e started
pi started
e done
pi done
Reached result 8.539734 in 10670.000 seconds
real 0m7.860s
user 0m10.662s
sys 0m0.016s
--------------------------------------------------------------------------------
Running test # gcc -O2 -fopenmp , Threads = 1
e started
e done
pi started
pi done
Reached result 8.539734 in 10670.000 seconds
real 0m10.678s
user 0m10.666s
sys 0m0.012s
|
Use accurate timing for tests :p |
|
Back to top |
|
|
John R. Graham Administrator
Joined: 08 Mar 2005 Posts: 10590 Location: Somewhere over Atlanta, Georgia
|
Posted: Sun Jun 10, 2007 5:58 pm Post subject: Re: Testing OpenMP |
|
|
neuron wrote: | Using OpenMP consistently slows things down (seemingly random amounts), and the results are different based on optimization (and never what it's supposed to be). What am I missing? | If this is too obvious, then, I apologize, but, do you actually have multiple processors (or a multicore CPU)? If there's no hardware to actually run your code in parallel, then the extra task switching overhead is guaranteed to slow you down.
- John |
|
Back to top |
|
|
neuron Advocate
Joined: 28 May 2002 Posts: 2371
|
Posted: Sun Jun 10, 2007 6:32 pm Post subject: Re: Testing OpenMP |
|
|
john_r_graham wrote: | neuron wrote: | Using OpenMP consistently slows things down (seemingly random amounts), and the results are different based on optimization (and never what it's supposed to be). What am I missing? | If this is too obvious, then, I apologize, but, do you actually have multiple processors (or a multicore CPU)? If there's no hardware to actually run your code in parallel, then the extra task switching overhead is guaranteed to slow you down.
- John |
As you can see the problem has been solved, and yes, I'm on a quad system |
|
Back to top |
|
|
|