Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Testing OpenMP
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
neuron
Advocate
Advocate


Joined: 28 May 2002
Posts: 2371

PostPosted: Sat Jun 09, 2007 7:02 am    Post subject: Testing OpenMP Reply with quote

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
View user's profile Send private message
theDOC_23
Tux's lil' helper
Tux's lil' helper


Joined: 02 Dec 2004
Posts: 121
Location: Aachen, GER

PostPosted: Sat Jun 09, 2007 8:53 am    Post subject: Reply with quote

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
View user's profile Send private message
neuron
Advocate
Advocate


Joined: 28 May 2002
Posts: 2371

PostPosted: Sat Jun 09, 2007 12:08 pm    Post subject: Reply with quote

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
View user's profile Send private message
Kirschsaft
n00b
n00b


Joined: 05 Jul 2003
Posts: 22

PostPosted: Sun Jun 10, 2007 5:29 pm    Post subject: Reply with quote

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
View user's profile Send private message
neuron
Advocate
Advocate


Joined: 28 May 2002
Posts: 2371

PostPosted: Sun Jun 10, 2007 5:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10590
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Jun 10, 2007 5:58 pm    Post subject: Re: Testing OpenMP Reply with quote

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
View user's profile Send private message
neuron
Advocate
Advocate


Joined: 28 May 2002
Posts: 2371

PostPosted: Sun Jun 10, 2007 6:32 pm    Post subject: Re: Testing OpenMP Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum