Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
nixnixnix is currently offline  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 Embarassed

[Updated on: Sat, 30 January 2010 01:23]

Report message to a moderator

Re: multi-threading slower than single thread [message #24792 is a reply to message #24788] Sat, 30 January 2010 08:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
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....

Hard to comment more withou seeing the code.

When you are speaking about svn, are you speaking about U++ (then it would be useful to at least provide svn revision which appears to break it) or your code?

Quote:


(size?) of the exe that is causing it to perform hundreds of times worse.



Not really impossible. Can be a cache issue. But IMO unlikely.

Mirek
Re: multi-threading slower than single thread [message #24793 is a reply to message #24792] Sat, 30 January 2010 10:35 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
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 Go to previous messageGo to next message
nixnixnix is currently offline  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






Re: multi-threading slower than single thread [message #24839 is a reply to message #24829] Mon, 01 February 2010 12:58 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Thing I would look for first (and I guess Tom will Smile is that maybe some part of code now has Mutex that serializes the access to it - it in turn makes the bottleneck for other threads, as they have to wait for the Mutex.

Such things can happen quite innocently, maybe just call something in GUI and be stopped by GuiLock...

[Updated on: Mon, 01 February 2010 12:58]

Report message to a moderator

Re: multi-threading slower than single thread [message #25031 is a reply to message #24839] Mon, 08 February 2010 21:47 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hi Mirek,

I need to do some more testing but ironically it looks like the RTIMING calls I put in to find out what was wrong became the cause of the poor performance.

I had refactored my code twice and so it seems I got rid of the original problem but the RTIMING calls were still causing it to choke.

Will report back again once I've tested some more.

Nick
Re: multi-threading slower than single thread [message #25038 is a reply to message #25031] Mon, 08 February 2010 23:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
nixnixnix wrote on Mon, 08 February 2010 15:47

Hi Mirek,

I need to do some more testing but ironically it looks like the RTIMING calls I put in to find out what was wrong became the cause of the poor performance.

I had refactored my code twice and so it seems I got rid of the original problem but the RTIMING calls were still causing it to choke.

Will report back again once I've tested some more.

Nick


Ah Smile Well, this is definitely possible... RTIMING can skew the results, especially in MT environment.

Mirek
Re: multi-threading slower than single thread [message #25041 is a reply to message #25038] Tue, 09 February 2010 01:34 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
An MT-friendly version of RTIMING would be extremely handy - I know you have a lot of time on your hands Smile

Not 100% sure about this but it seems that casting from Value to double was another big bottleneck - does that make any sense?

I now have two out of three of my environmental impact grid calculations running at 95-100% utilisation on 8 virtual cores so things are looking up.

Nick
Re: multi-threading slower than single thread [message #25242 is a reply to message #25041] Mon, 15 February 2010 12:44 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
nixnixnix wrote on Mon, 08 February 2010 19:34

An MT-friendly version of RTIMING would be extremely handy - I know you have a lot of time on your hands Smile

Not 100% sure about this but it seems that casting from Value to double was another big bottleneck - does that make any sense?



Depends, while O(1) in principle, I would not use Value e.g. to represents matrix cells for Gauss elimination method Smile

Also, one possible issue is that even if there is 'int' in Value, it is automatically converted to 'double'. 'int' -> 'double' conversions can take quite a long time on many CPUs, because int and fp pipelines are usually running independent and this conversion therefore has to stall the whole pipeline.
Re: multi-threading slower than single thread [message #25581 is a reply to message #25242] Mon, 01 March 2010 21:25 Go to previous message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Thanks for the tip. That is good to know.

Nick
Previous Topic: Linux MT problems with time functions
Next Topic: Why ie cannt catch messages from keyboard and mouse
Goto Forum:
  


Current Time: Thu Mar 28 14:46:13 CET 2024

Total time taken to generate the page: 0.01937 seconds