This project is read-only.

ParallelFox: Use with HyperThreading single core

Topics: Enhancement Request, General
Feb 21, 2011 at 8:14 PM

Hi Joel (and others).  

I check the ParallelFox class videos and this is impressive.  Especially the part where a worker can pass cursors to the parent thread!

I download the class and tried the demo prg that were included.  I don't know why, but the demos runs something like 10 seconds more WITH ParallelFox than WITHOUT.  It may be caused by the fact that my computer is a single core with HyperThreading (ParallelFox then starts 2 workers).  But I would have thought that an HyperThreading single core would still be faster that a normally running VFP as a single core.

The demos run multi-threaded as expected, only slower than expected.  Is there something wrong I did?

Thanks.

Feb 21, 2011 at 11:23 PM

Hi,

I'm not an expert on HyperThreading, but it is very difficult to predict how it will affect performance.  See these links for more info:

http://www.agner.org/optimize/blog/read.php?i=6

http://www.pcstats.com/articleview.cfm?articleID=1302

Which example program did you run? 

Feb 22, 2011 at 2:01 PM

Thanks for your response.

I did try all of the sample that are included with ParallelFox and all of them are slower on my computer.

Those articles are very technical...  What I can understand is that it is slower on my HyperThreading single core because the threaded tasks of your sample are very CPU extensive.  If there was some "wait" involve in the task then probably the multi-threaded sample would be faster.  I don't know how I could describe the "wait" that should be involved here...  Maybe like this one:  There is one function that I developed that need to go and fetch many picture from the Internet following a search (so there cal be from 1 to 150 more images to get).  Probably that having this "image fetching" multi-threaded should be faster since the task would have to "wait" for the internet to respond.  I guess that it would be faster but I would have to try.

Now, I think I know why it is slower.  But now here is a question:  Is there a way for ParalleleFox to identify the number of REAL processors or cores without the logical ones?  If I want to speed up a program by integrating ParallelFox, I do not want to slow it on a single core computer.  If it could be detected that there is no multiple core, than ParallelFox could start only one worker.

What do you think about that?

Thanks.

Feb 22, 2011 at 2:56 PM

Yeah, those articles are technical for me too, but I think you are on the right track.  The examples simulate work by counting to a large number, effectively running the same line of code over and over.  My guess is that this causes the workers to compete for the same execution units on the CPU.  In a real world app, there may be less of a bottleneck and you may get a benefit from HyperThreading.  I recommend trying your own code to see the results. 

I think I have a single-code HyperThreading machine at work, so I'll do some testing on it when I get a chance.  I'll also see if I can figure out how to detect when HyperThreading is in use.  In the meantime, you have control over the number of workers by using Parallel.SetWorkerCount() before starting the workers.  If you're good with the Windows API, you may be able to detect HyperThreading with this function: http://msdn.microsoft.com/en-us/library/ms683194%28VS.85%29.aspx.

Feb 22, 2011 at 6:35 PM

Thanks.  I'll check that.

Keep up the good work!

Mar 28, 2011 at 7:27 PM

I finally got a chance to do some testing.  On our single-cpu machine with HT (HyperThreading) turned on, I can confirm that running the Call_After.prg example with two workers is slower than using one worker.  As I indicated before, I think the examples that ship with ParallelFox are exceptionally bad with HT, or rather make the problem look worse than it really is.  I want to do more research on the subject and more testing with code that is closer to real-world.  I hope to add detection for HT in the next release of ParallelFox.

Apr 3, 2011 at 12:39 AM

This issue is addressed in ParallelFox 1.0 RC1.

http://weblogs.foxite.com/joel_leach/archive/2011/04/02/13940.aspx

Apr 4, 2011 at 4:02 PM

Hi.  Will try that.

Thanks.