|
|
Home » U++ Library support » U++ MT-multithreading and servers » multi-threading slower than single thread
multi-threading slower than single thread [message #24788] |
Fri, 29 January 2010 22:23  |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Hi,
I have a very strange thing happening. Just over 1 year ago I wrote some multi-threading code that scaled the performance of my calculation linearly with number of virtual cores. However, now that same code performs worse than a single thread.
Using my SVN I have stepped back in time one year and recompiled that code and it performs as I remember it.
My code now is many many times slower and the single threaded version performs better than the multithreaded version.
This applies to several very different and separate calculations I do. It applies to the linux and windows builds, both 32 and 64 bit.
I checked out a version from about 7 months ago and it is slower than the 1 year old version but not nearly as slow as my latest version. The code that does the calculations is the same though. It appears to be something to do with the general properties (size?) of the exe that is causing it to perform hundreds of times worse.
Does anybody have any idea as to what might cause this type of slow down please? I am going out of my mind trying to hunt it down. Any ideas welcome.
Nick
EDIT: there is a difference in what the functions do, still hunting down how to fix it but please feel free to delete this thread as a red-herring
[Updated on: Sat, 30 January 2010 01:23] Report message to a moderator
|
|
|
|
Re: multi-threading slower than single thread [message #24793 is a reply to message #24792] |
Sat, 30 January 2010 10:35   |
Didier
Messages: 726 Registered: November 2008 Location: France
|
Contributor |
|
|
Hi,
the same code runs faster with one thread than with several threads !
==> This is not a code performance issue : you would have the same problem with the single threaded version.
So must be a synchronisation problem :either you're use of mutexes has a bug ( maybe the API changed ? ), or more likely some internals use mutexes for GUI protection and you fall into global thread lock situation (all other threads are locked until the current thread has finished) .... and of corse on multi core, this is not good !
Do you're threads interact with GUI ?
[Updated on: Sat, 30 January 2010 10:36] Report message to a moderator
|
|
|
Re: multi-threading slower than single thread [message #24829 is a reply to message #24788] |
Mon, 01 February 2010 07:29   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Quote: |
nixnixnix wrote on Fri, 29 January 2010 16:23
Hi,
I have a very strange thing happening. Just over 1 year ago I wrote some multi-threading code that scaled the performance of my calculation linearly with number of virtual cores. However, now that same code performs worse than a single thread.
Using my SVN I have stepped back in time one year and recompiled that code and it performs as I remember it.
My code now is many many times slower and the single threaded version performs better than the multithreaded version.
Generally, this is a sign that either synchronization costs or thread management costs are higher than gains of using multiple cores....
|
Hi Mirek,
I understand that there can be a significant overhead but my issue is that there was not one before and there is one now.
When I refer to SVN I am refering to my SVN. I stepped back through my SVN to grab a version that did not have this issue but is also not significantly different in terms of what I am trying to do.
Didier,
Thanks for your reply. What you say about the single vs multiple threads makes sense to me. However, because the calculations are grid calculations operating on structures allocated from heap memory, I have not used any mutex's, locks etc. although i agree there appears to be an issue like that. Mirek and Tomas now have my code so hopefully they will see something I don't.
Thanks again,
Nick
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 15:45:43 CEST 2025
Total time taken to generate the page: 0.00499 seconds
|
|
|