Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multithreaded code runs slow

Status
Not open for further replies.

larrymul

Programmer
Jan 9, 2012
2
US
I wrote two versions of a small test program that calculates sin(x) using a Taylor series expansion. The single thread version calculates each term of the expansion sequentially and then adds them up for the final result. The multi thread version calculates each term in a separate thread then adds them up when all threads have completed. The programs calculate a million values just so I can time them with a stopwatch. On my XP machine with a quad core processor the multi thread version runs much faster than the single thread version. When I moved the programs to a Windows 7 machine with a quad core processor the multi thread version runs SLOWER than the single thread version! Has anyone else seen this type behavior? I have tried changing various Windows parameters, such as processor affinity and thread priority, but to no avail. Thanks in advance.
 
- check using Task Manager or Process Explorer if it's actually using all CPU's
- does the code release cycles to other processes (cooperative multitasking)?
- Is the Win7 system actually a quad-core or a dual-core with hyper threading? (and idem for the XP system?)
 
The Win7 system is a true quad core processor. I have tried it with hyperthreading on and off and it makes no significant difference. Looking at the performance graphs in process manager it appears that the single thread version uses a large percentage of one of the cores. The multi thread version splits its activity between four cores but at a much reduced percentage. I really wanted it to use the highest percentage of each core as possible. My ultimate goal would be to start a big calculation and let it crunch numbers till it's done. In this case I wouldn't really care about how fast the rest of the OS is running.

I wrote no specific code to release cycles to other processes. My code is written using National Instruments LabWindows CVI2010 integrated development envirnoment. I used their multithreading libraries so I can't be sure what's going on beneath the surface. The NI tech reps are also looking into the problem. I have sent them my code and they see the same behavior.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top