SRL Archive - Other Scripts

Multi-Script Prime Finder


the nerd

2008-03-24 10:48:23

Yes this is another prime finder, but I didn't copy code, i created it from scratch. (I only discovered that there are other when I posted this).

I created the script as a demostration of what I call "multi-script". The first thing you will notice is that there two scripts involved not one (i dont no if any one else has tried this). This allowes to run a slow bit of code at the same time as a fast bit of code without slowing down thee fast bit of code. I relies on the SCAR's inter SCAR messaging ability.

The script can run both in "multi-script" mode or single script mode (except the report client). In this script all of the reports are handled by a client script. This is because creating the report takes alot of time compared to finding prime numbers.

To use multi-script mode open prime finder script in one window, and the report client in a second window. (Must be different windows, not tabs!!!!)

Start the script in any order, they will wait for each other for up to a minute. You can sart the report client even if the prime finder is running, they will detect each other and switch to multi-script mode.
If the report client stops then the prime finder will switch to single script mode. If the prime finder stops then the report client will terminate.

If you download the script can you please post benchmarks.

Post the following information.

Time taken to discover 10,000 primes in multi-script mode.
Time taken to discover 10,000 primes in single-script mode.

CPU configeration:
Hyper threading
Multi-core (number of cores)
Single core (nothing special)

EDIT: I have uploaded a new version with an auto benchmark.

EDIT: Current Script does not work. Will update at a later date. Sorry

mixster

2008-03-24 11:03:45

This is very different from others - I will give you that - though you could probably update your core PrimeCheck using "if num mod num2 = 0 then not prime" (with it being changed to work in scar of course), otherwise it's a good example of inter-scar messaging more than prime number finding. I'm running it at the moment, so I'll post benchmarks, though I'm sure it'll be quite slow because of all the WriteLn's

the nerd

2008-03-24 11:16:11

Thanks for your input. I will update the code with your ideas in the future. However I am not sure how to remove the writeln's. I suppose I could try and use the report client, but I'm not sure if thats the answer.

mixster

2008-03-24 11:18:38

Noticed another problem now - It's supposed to stop when it gets to 10k prime numbers, but it has kind of gone on a bit… to 129000 or so :)
Edit: the problem is you don't have NumToDis assigned to 10000 if it is equal to 0, but in your check (where ti spits out numbers) you make it only run the checking code if NumToDis is above 0.

the nerd

2008-03-24 11:21:04

Did you set the limit to 10,000. (It is not pre-set). I will check the code just make sure i didn't make a stupid mistake

EDIT: You need to set the limit on line 46. I will add this to my original post

mixster

2008-03-24 11:24:51

I left it on 0 as my Scar cut off the end bit, but it may be an idea to make it auto-benchmark if set to 0, as not many people want to find out an unlimited number of primes :)
Edit:
Time Running: 29 Seconds
Number of Prime's Discovered: 9791
Average Time To Discover Prime: 8msec
Prime Numbers Per Min: 7272
For multithreading - testing single now.
Edit2:
Time Running: 1 Minutes and 29 Seconds
Number of Prime's Discovered: 9975
Average Time To Discover Prime: 9msec
Prime Numbers Per Min: 7031
For singlethreading - the time running includes the minute before ti gives up on the client. So it's the same both way, how about that :)
Edit3: My plugin managed the range in 860ms with an average processing speed of 11.61 numbers per ms :p

the nerd

2008-03-24 12:24:36

Ok. Thanks. I will add some updates to the script for the bencmarking and upload again.