multithreading ; linux adn windows behave differently
  Home FAQ Contact Sign in
comp.lang.c only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.c Profile…
 Up
multithreading ; linux adn windows behave differently         


Author: kumarchi
Date: May 16, 2008 07:02

hello:

I wrote a simple program which does simple math loop and I am testing
under dual core processor

systm1:
intel dual core laptop ; windows xp os
when I spawn of two threads in windows (both under visual c and cygwin
cc) the program behaves as expected.
in single thread mode the time is 2x and clearly one of hte one do of
the processor is being utilized

system2:
amd 4200x2 desktop ubuntu hardy 8.04
here actually the single thread gets slightly better performance. in
multi thereaded both the cpu's are 100%% utilized. but even in single
threaded both the cpu's are alternatively being used 50/100 %%!!

gurus:
any idea why the linux system (i am assuming the difference is due to
OS) is behaving differently?

here is the simple code
Show full article (2.58Kb)
9 Comments
Re: multithreading ; linux adn windows behave differently         


Author: Szabolcs Borsanyi
Date: May 16, 2008 07:44

On May 16, 3:02 pm, kumar...@gmail.com wrote:
> hello:
>
> I wrote a simple program which does simple math loop  and I am testing
> under dual core processor

This question is definitely off topic here, but I managed to find one
topical aspect:
library functions (especially rand()) are not reentrant.
Do not use them without a synchronising mechanism. For better
performance, implement your own or use libc's reentrant
random number generators, where the internal information about
the next random number is stored in automatic variables, which
are on a thread local stack on your platforms.
Avoid calling the same library functions from the threads and

avoid the frequent access of the same memory (page) from
several threads.


Szabolcs
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Keith Thompson
Date: May 16, 2008 09:19

kumarchi@gmail.com writes:
> I wrote a simple program which does simple math loop and I am testing
> under dual core processor
>
[...]
>
> here is the simple code
>
> #include
> #include
> #include
> #include
> #include
> #include
[...]

Try asking in comp.programming.threads.
Show full article (0.56Kb)
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Antoninus Twink
Date: May 16, 2008 10:09

On 16 May 2008 at 14:02, kumarchi@gmail.com wrote:
> amd 4200x2 desktop ubuntu hardy 8.04
> here actually the single thread gets slightly better performance. in
> multi thereaded both the cpu's are 100%% utilized. but even in single
> threaded both the cpu's are alternatively being used 50/100 %%!!

I find dt = 4 running the two threads, versus dt = 7 for one thread
(Debian, 2.6.24 kernel), so I guess there's some problem with your
setup.

Are you running an SMP kernel? Does cat /proc/cpuinfo report both cores?
What was the system load when you ran the test?
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Antoninus Twink
Date: May 16, 2008 10:31

On 16 May 2008 at 14:44, Szabolcs Borsanyi wrote:
> library functions (especially rand()) are not reentrant.
> Do not use them without a synchronising mechanism. For better
> performance, implement your own or use libc's reentrant
> random number generators, where the internal information about
> the next random number is stored in automatic variables, which
> are on a thread local stack on your platforms.

I'm not sure what function you have in mind. The reentrant version of
rand provided by POSIX is rand_r(), which takes a pointer to a seed as
its argument - it's very unlikely that TLS will be needed or desirable.
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Szabolcs Borsanyi
Date: May 16, 2008 14:10

On May 16, 6:31 pm, Antoninus Twink wrote:
> I'm not sure what function you have in mind. The reentrant version of
> rand provided by POSIX is rand_r(), which takes a pointer to a seed as
> its argument - it's very unlikely that TLS will be needed or desirable.

You are right, rand_r() is posix, indeed. I did not mean TLS
as thread local storage for global or static variables, but the stack,
owned by the thread, that holds the object pointed to by the argument
of
rand_r(). And since rand_r takes just an unsigned*, its quality of
RNG is limited by design, this often rules out this function.

Szabolcs
no comments
Re: multithreading ; linux adn windows behave differently         


Author: kumarchi
Date: May 16, 2008 15:11

On May 16, 1:09 pm, Antoninus Twink wrote:
> On 16 May 2008 at 14:02, kumar...@gmail.com wrote:
>
>> amd 4200x2 desktop ubuntu hardy 8.04
>> here actually the single thread gets slightly better performance. in
>> multi thereaded both the cpu's are 100%% utilized. but even in single
>> threaded both the cpu's are alternatively being used 50/100 %%!!
>
> I find  dt = 4 running the two threads, versus dt = 7 for one thread
> (Debian, 2.6.24 kernel), so I guess there's some problem with your
> setup.
>
> Are you running an SMP kernel? Does cat /proc/cpuinfo report both cores?
> What was the system load when you ran the test?

yes my kernel is 2.6.24-17 and the procinfo reports the 2 cores
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Keith Thompson
Date: May 16, 2008 16:24

kumarchi@gmail.com writes:
> On May 16, 1:09 pm, Antoninus Twink wrote:
[...]
>
> yes my kernel is 2.6.24-17 and the procinfo reports the 2 cores

Antoninus Twink is trying to disrupt this newsgroup by encouraging
off-topic posts. Please post any further questions to
comp.programming.threads or to a newsgroup that deals with your
operating system, where you will find experts who can actually answer
your questions. Thank you.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
no comments
Re: multithreading ; linux adn windows behave differently         


Author: kumarchi
Date: May 16, 2008 16:36

On May 16, 1:09 pm, Antoninus Twink wrote:
> On 16 May 2008 at 14:02, kumar...@gmail.com wrote:
>
>> amd 4200x2 desktop ubuntu hardy 8.04
>> here actually the single thread gets slightly better performance. in
>> multi thereaded both the cpu's are 100%% utilized. but even in single
>> threaded both the cpu's are alternatively being used 50/100 %%!!
>
> I find  dt = 4 running the two threads, versus dt = 7 for one thread
> (Debian, 2.6.24 kernel), so I guess there's some problem with your
> setup.
>
> Are you running an SMP kernel? Does cat /proc/cpuinfo report both cores?
> What was the system load when you ran the test?

I compiled with optimization . mo i am getting dt=21(for 2 treads) vs
dt=27 ; some improvement. by the what ishte hardware you are using .
it is way way faster than mine 5x ; that is incredible
no comments
Re: multithreading ; linux adn windows behave differently         


Author: Antoninus Twink
Date: May 17, 2008 02:22

On 16 May 2008 at 23:36, kumarchi@gmail.com wrote:
> I compiled with optimization . mo i am getting dt=21(for 2 treads) vs
> dt=27 ; some improvement. by the what ishte hardware you are using .
> it is way way faster than mine 5x ; that is incredible

Probably not - I reduced the number of outer loops :)
no comments