Re: little isprime challenge
- From: Bart Vandewoestyne <MyFirstName.MyLastName@xxxxxxxxxx>
- Date: Mon, 29 Aug 2005 09:31:47 +0000 (UTC)
On 2005-08-23, Bart Vandewoestyne <MyFirstName.MyLastName@xxxxxxxxxx> wrote:
> I know there has been a kind of `string-challenge' in this group
> which I have not been following... but it's been taking a while
> and from what I've read I have the feeling that some people got
> bored of it and now are definitely in need for something else...
> so I have another little `isprime-challlenge' :-)
>
> It's just 100% pure for the fun of it, and maybe it will also
> teach some more novices and `less experienced' young fortran
> programmers as me good optimization skills. It might also be usefull for
> some people in need for some prime routines.
OK. The little isprime challenge has come to an end. My final testprogram is
at http://www.cs.kuleuven.ac.be/~bartv/stuff/time_isprime.f95
These are the timing results on my computer:
bartv@archimedes:~/fortran$ make time_isprime
F -o time_isprime -O4 time_isprime.f95
bartv@archimedes:~/fortran$ ./time_isprime
How many numbers should be tested? 1000000
What method (from_1|from_huge) ? from_1
from_1: Brooks's method found 78498 primes in 0.15 seconds.
from_1: Fermat's method found 78498 primes in 0.74 seconds.
from_1: Elliot's method found 78498 primes in 0.56 seconds.
from_1: Rich's method found 78498 primes in 0.61 seconds.
from_1: Bart's method found 78498 primes in 1.08 seconds.
How many numbers should be tested? 1000000
What method (from_1|from_huge) ? from_huge
from_huge: Brooks's method found 46602 primes in 66.60 seconds.
from_huge: Fermat's method found 46602 primes in 1.08 seconds.
from_huge: Elliot's method found 46602 primes in 69.20 seconds.
from_huge: Rich's method found 46602 primes in 21.62 seconds.
from_huge: Bart's method found 46602 primes in 98.68 seconds.
I'll leave it to the reader to decide which version is preferable. What I
have learned from this challenge is the following:
* First of all, look for a fast theoretical algorithm :-)
* The loop-unrolling-alike technique as it is used by Brooks can speedup
dramatically
* I wonder if Fermat's method suffers from overflow problems since we are
testing up until huge(n)-1 and this algorithm requires 8-byte integers...
that would maybe explain the speed of the method, but apparently, it finds
as much primes as the other ones so it seems correct? I haven't looked at
the value of the primes yet, but this could be something for further
investigation... :-)
If I had to choose, I think I would go for Elliot's method because it doesn't
require 8-byte integers and it is definitely more readable than Brooks's method ;-)
See you in the next challenge (coming soon... :-)!
Bart
--
"Share what you know. Learn what you don't."
.
- Follow-Ups:
- Re: little isprime challenge
- From: e p chandler
- Re: little isprime challenge
- From: Brooks Moses
- Re: little isprime challenge
- From: billyboyer
- Re: little isprime challenge
- References:
- little isprime challenge
- From: Bart Vandewoestyne
- little isprime challenge
- Prev by Date: jagged parameter arrays
- Next by Date: Re: ANN: pilib: Platform/Compiler independend RTL
- Previous by thread: Re: little isprime challenge
- Next by thread: Re: little isprime challenge
- Index(es):
Relevant Pages
|