What's new

How fast can your puter ID prime numbers? (1 Viewer)

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
Gabriel,

The app does not take advantage of multiple CPUs because it does not spawn multiple threads (the whole application runs in the main thread). With a few minor modifications, this could be changed. If you're interested, let me know.
 

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
Gabriel,

I modified (or I should say, re-wrote) this guys application. The application works takes one command-line argument, which is the number of threads to run. So you would run it like this:
PrimeNum 2
and it would process on 2 different threads.

For most of us who only have one CPU, we wont notice an increase. However you should, as now both CPUs should be calculating prime numbers.

Also note that the prime numbers will not be calculated in order. So on your screen, you might see:
0,
1,
7,
5,
17,
11,
13

and so on and so forth. This is because the OS manages the threads. I could have added in synchronization code to make them process in order but this would have greatly reduced efficiency. As it is, there is no thread blocking, no Mutexes or Critical Sections, etc... no thread synchronization code. But be rest assured, all numbers between 1 and 100,000.

Also note that, just as the other guys' application, this will print out the numbers on the screen but will NOT write out to a file. Printing out on the screen is an expensive operation, and I'm not flushing stdout after every pass.

So, ideally, the printing code would be taken out. If you have a C compiler, you are free to recompile the code with the printf() commented out.

Anyway, you can download the file from:
www.geocities.com/stevenkrawczyk/PrimeNum.zip

The ZIP file includes a Release build of the executable file, as well as the source code.
 

Gabriel_Lam

Screenwriter
Joined
Mar 7, 2002
Messages
1,402
Steven,

I can't seem to download the file. Anyone else having these difficulties?

BTW, do you know how it'll handle 4 processors (2 hyperthreaded processors)?
 

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
Gabriel,

I changed the URL... actually the correct file name is PrimeNum.zip and I had it listed as being all lower-case. I just tried it again and it seems to be working now.

Theoretically, it can handle any number of threads. The application works like such:
if you have 5 processors, you'll want to run 5 threads. Each thread will only process 15th of the numbers (20% * 5 = 100%). If you have 2 processors, run 2 threads, and each thread will process half of the numbers, etc...
I've heard that hyperthreading is very misleading. The chip does not actually allow 2 threads to REALLY run concurrently on the same CPU, but I haven't been able to verify this. I do know that in order to make use of the hyperthreading feature, you need to build with Intel's compiler. This was compiled with Microsoft Visual Studio 6.

On your system, try a few different numbers. Try 1 thread, then try 2 threads. You should see a noticeable improvement.

But for the rest of us with only 1 CPU, we wont see much, if any, improvement. For instance, I ran this on my P4 1.8 with 1 GB RAM:
1 Thread- 109719 MS (109.7 seconds)
2 Threads- 109468 MS (109.4 seconds)

Please publish your results if you get a chance and let me know if you have any questions (this extends to everyone) :)
 

Gabriel_Lam

Screenwriter
Joined
Mar 7, 2002
Messages
1,402
OK, here's what I got:

1 thread: 750 milliseconds
2 threads: 500 milliseconds
3 threads: 313 milliseconds
4 threads: 297 milliseconds
5 threads: 250 milliseconds
6 threads: 297 milliseconds
7 threads: 250 milliseconds
8 threads: 234 milliseconds
9 threads: 250 milliseconds
10 threads: 234 milliseconds

Something seems off.
 

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
It definitely could be... multithreading is not a perfect science, and in a multiple CPU environment, the OS isn't perfect at thread-scheduling and dole-ing out equal amounts of time-slices to each thread.

But, you can deinitely see that running more than 1 thread in your environment makes a big difference.

Of course it bothers me that it only takes 750 milliseconds... oops my bad, the version I uploaded only goes to 1-10,000. Try redownloading it... now it is set to 100,000 (this is what I have been testing with the whole time)

What OS are you running?
 

MikeyWeitz

Supporting Actor
Joined
Feb 10, 2002
Messages
939
It will be interesting to run this on various computers to see what kind of results I get. I have a PIII laptop at 1GHz, an Athalon 1600+ at home and my brother has an athalong 1.2GHz. It will be interesting since both our processors are technically 1.2GHz core and mine is just supposed to perform equivilant to 1600Mhz. I will be ticked if his is faster or something.
No, you are correct in that it is still in the Athlon family, it is a new version of it tho (as opposed to the Duron which is a cheaper/less powerful version), your brother is probably a Tbird unless it is a duron.

XP Palomino series (.18 micron process)was right after the regular Athlon tbird series, then you have the Tbred (thoroughbred version of the XP chip which uses the .13 micron process of manufacturing the chip, then a couple of months ago the XP chips with the 333 FSB came out and the latest is the Barton core which not only has the 333fsb, but also has 512k of L2 cache as opposed to 256k making them noticeably more powerful.
Tough o follow I know :), wait until the 400fsb XP chips come out, then the MUCH anticipated HAMMER, 64bit series comes out :)
 

KyleS

Screenwriter
Joined
Jul 24, 2000
Messages
1,232
85 Seconds on my P4 1.6ghz Laptop with 512mb DDR Ram.

Ok I must have been smoking something really good. After re-testing my laptop I ended up with 180, 179, & 185 so I must have accidentally missed that 1 in front of the 85 of my score. Sorry about that Tony. I know that my desktop scored are correct though. :b
I will have to try on my 2.53 and 3.06ghz desktops. Hmmm something to do tonight. ;)

KyleS
 

Tekara

Supporting Actor
Joined
Jan 8, 2003
Messages
783
Real Name
Robert
hmm, i don't see why it wouldn't work on a mac, there shouldn't be any tricky memory addressing in that program. what version of macOS are you running? The reason I ask is that in my programming classes I can run the basic c++ programs on pc's or macs (mac osX) without too many problems. As long as the program makes no hardware specific calls and stays simple it's all the same.
 

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
The version that I wrote will not work on a Mac, because the application uses Windows-specific code for threading and timing.

It could be ported to run on a Mac... 2 things would be required:
1. Write a GetTickCount() function
2. Change code to use pthreads

Of course, a Mac compiler would also be needed...
 

Gabriel_Lam

Screenwriter
Joined
Mar 7, 2002
Messages
1,402
Here are the updated results:

1 thread: 71469 milliseconds (71 sec)
2 threads: 45172 milliseconds (45 sec)
3 threads: 29416 milliseconds (29 sec)
4 threads: 26141 milliseconds (26 sec)
 

Scott L

Senior HTF Member
Joined
Feb 29, 2000
Messages
4,457
Woohoo!!! Gab can you explain how you can choose how many threads (or cpus) are available for use. Do you have to set that up in BIOS or in the OS? And is there any reason you need to select less than 4 threads?
 

Gabriel_Lam

Screenwriter
Joined
Mar 7, 2002
Messages
1,402
Scott:

I just followed Steven K's instructions above:

"primenum 1" to do 1 thread
"primenum 2" to do 2 threads
etc, etc..

I'm curious how multiple threads works on a single processor system. Anyone wanna try it?
 

Tony_Woods

Stunt Coordinator
Joined
Apr 16, 2002
Messages
105
KyleS, how did you manage 85 Seconds on a P4 1.6ghz Laptop with 512mb DDR Ram?

My AXP1600+ @ 2100mhz gets 87 seconds
Thats on an AsusA7NX Nforce2 mobo w/ dual 256mb PC3500. Watercooled, etc.
 

Lee L

Supporting Actor
Joined
Oct 26, 2000
Messages
868
I tried 2 threads on my single proc p3/1.0/256 system and it took 140 seconds with one thread and 142 with 2. This is with Seti running in the BG as a low priority process.
 

Steven K

Supporting Actor
Joined
Jan 10, 2000
Messages
830
Gabriel,

It's the perfect example of how powerful a multiple CPU environment can be, assuming that the application is written to take advantage of it.
 

Users who are viewing this thread

Sign up for our newsletter

and receive essential news, curated deals, and much more







You will only receive emails from us. We will never sell or distribute your email address to third party companies at any time.

Forum statistics

Threads
357,192
Messages
5,132,722
Members
144,320
Latest member
hilogisticz
Recent bookmarks
0
Top