Pages: [1]
Guest

2005-10-24 14:15:16

I've read some details on the PrimeGrid forum:

http://www.primegrid.com/orig/forum_thread.php?id=102

which lead me to believe the client is nowhere near optimised.

According to one post in that thread the client takes 55 minutes to get through one work unit (1M numbers) on a reasonable PC.

In 5 minutes I knocked up a 15 line program using the GMP library (which can be compiled statically to produce a simple program or DLL).

This program checks 1M numbers (one WU as stated in the post) in 0.73 seconds on a 3.0GHz P4. Even my Mac Mini does this amount of work in 1.4 seconds.

With a few more optimisations I could get it down to 0.5 seconds for a single Work Unit.

Either:

1) I've got it wrong and a work unit contains an awful lot more than 1M numbers.
2) The client is woefully 'optimised'.

Anyone care to comment?
Rytis
BAM!ID: 6
Joined: 2006-01-10
Posts: 234
Credits: 198,293,759
World-rank: 7,362

2005-10-24 15:55:49


I've read some details on the PrimeGrid forum:

http://www.primegrid.com/orig/forum_thread.php?id=102

which lead me to believe the client is nowhere near optimised.

According to one post in that thread the client takes 55 minutes to get through one work unit (1M numbers) on a reasonable PC.

In 5 minutes I knocked up a 15 line program using the GMP library (which can be compiled statically to produce a simple program or DLL).

This program checks 1M numbers (one WU as stated in the post) in 0.73 seconds on a 3.0GHz P4. Even my Mac Mini does this amount of work in 1.4 seconds.

With a few more optimisations I could get it down to 0.5 seconds for a single Work Unit.

Either:

1) I've got it wrong and a work unit contains an awful lot more than 1M numbers.
2) The client is woefully 'optimised'.

Anyone care to comment?


Interesting

You can contact me using rytis.s@gmail.com (or you can reach me by MSN, the same email).
Guest

2005-10-25 09:41:52
last modified: 2005-10-25 09:44:19


Interesting

You can contact me using rytis.s@gmail.com (or you can reach me by MSN, the same email).


Sure, let me just add a few comments and...

http://www.greenbank.org/misc/rsa640.c

The pseudocode is this:-

Code:

n=<number to factor>
curr=sqrt(n)
if( even(curr) ) curr++; // Make sure curr is odd

while( curr > 0 ) {
if( curr is not divisible by 3, 5, 7, 11, 13, 15, 17, 19, 21 or 23 ) {
rem=n%curr;
if( rem == 0 ) {
print out curr;
exit;
}
}
curr-=2;
}


Large integer support provided by the GMP library: http://www.swox.com/gmp

The source is nowhere near optimised. There are much better ways of removing candidate values than the horrible trial division I do. By checking that p doesn't have a factor up to 23 it doubles the speed. So even without this it will still do a block of 1M odd numbers in under 2 seconds on a 3.0GHz P4.

Even with all of this it will take a 3.0GHz P4 roughly 1.7*10^83 years to check all of the possible candidates.
Carlos_Pfitzner
 
BAM!ID: 64
Joined: 2006-05-10
Posts: 44
Credits: 427,688
World-rank: 333,130

2006-05-20 03:33:38
last modified: 2006-05-20 17:25:03


Sure, let me just add a few comments and...

http://www.greenbank.org/misc/rsa640.c

The pseudocode is this:-

Code:

n=<number to factor>
curr=sqrt(n)
if( even(curr) ) curr++; // Make sure curr is odd

while( curr > 0 ) {
if( curr is not divisible by 3, 5, 7, 11, 13, 15, 17, 19, 21 or 23 ) {
rem=n%curr;
if( rem == 0 ) {
print out curr;
exit;
}
}
curr-=2;
}


Large integer support provided by the GMP library: http://www.swox.com/gmp

The source is nowhere near optimised. There are much better ways of removing candidate values than the horrible trial division I do. By checking that p doesn't have a factor up to 23 it doubles the speed. So even without this it will still do a block of 1M odd numbers in under 2 seconds on a 3.0GHz P4.

Even with all of this it will take a 3.0GHz P4 roughly 1.7*10^83 years to check all of the possible candidates.


I am believing that the only optimiztion possible and efficient is rewriting the code into assembly
and optimizing this code carefully , by hand
http://www.primegrid.com/orig/view_profile.php?userid=2820

There are also best algoritms to use ... described on the handbook of the computer above ...
*Now scanned and availabe online ! (do a search on google)
[edit] http://ed-thelen.org/comp-hist/Lehmer-NS-01.html <--- the scaned handbook is here
A interpretation of the contents
Code:
In dealing with Mersenne numbers, it is easy to prove that if 2P-1 is prime, then P must be a prime. Thus, the first step in the search is to create a list of prime exponents to test.


--------------------------------------------------------------------------------

Trial Factoring

--------------------------------------------------------------------------------

The next step is to eliminate exponents by finding a small factor. There are very efficient algorithms for determining if a number divides 2P-1. For example, let's see if 47 divides 223-1. Convert the exponent 23 to binary, you get 10111. Starting with 1, repeatedly square, remove the top bit of the exponent and if 1 multiply squared value by 2, then compute the remainder upon division by 47.

Remove Optional
Square top bit mul by 2 mod 47
------------ ------- ------------- ------
1*1 = 1 1 0111 1*2 = 2 2
2*2 = 4 0 111 no 4
4*4 = 16 1 11 16*2 = 32 32
32*32 = 1024 1 1 1024*2 = 2048 27
27*27 = 729 1 729*2 = 1458 1

Thus, 223 = 1 mod 47. Subtract 1 from both sides. 223-1 = 0 mod 47. Since we've shown that 47 is a factor, 223-1 is not prime.

One very nice property of Mersenne numbers is that any factor q of 2P-1 must be of the form 2kp+1. Furthermore, q must be 1 or 7 mod 8. A proof is available. Finally, an efficient program can take advantage of the fact that any potential factor q must be prime.

Code:
Lucas_Lehmer_Test&#40;p&#41;:
s := 4;
for i from 3 to p do s := s2-2 mod 2p-1;
if s == 0 then
2p-1 is prime
else
2p-1 is composite;The theory for this test was initiated by Lucas in the late 1870's and then made into this simple test about 1930 by Lehmer

http://primes.utm.edu/mersenne/index.html#test


ps:
my CPU, CyryxInstead, I486 does not have any special machine code instructions to get advantage of
on compile time
Thanks
Click signature for team stats
Pages: [1]

Index :: Optimized clients :: Primegrid: Optimisation?
Reason: