![]() |
| | #31 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
|
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #32 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
).
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #33 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| That would definately beat the baseline, which takes 143 seconds using all odd factors less than the root. The assumption of course is that checking compsite odd numbers is completely worthless because if the number being tested where divisible by a composite, then it woudl be divisible by a prime smaller than that composite which has already been checked. So the actual check of the composite itself does nothing but waste compute cycles. Especially for larger primes where the majority of composite numbers are proven composite in fewer than 256 calculations (a naive assumption) but primes take over 32768 calculatons, so reducing the workload for verifying that a prime is in fact prime will have a significant impact on total throughput.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #34 |
| Reverse Engineer Join Date: Aug 2005 Location: Estonia
Posts: 2,236
| I made a simple one for under 2^32 which finishes in 132 seconds. Over 2^32 requires some thinking though. Edit: Oh wait! When I used square root (dumb of me to forget that) I got 100,000 under 2^32 in 0.7sec and 1,000,000 under 2^32 in 18sec. Still no help when doing over 2^32 though.
__________________ The duck is irrelevant to my point. Last edited by maxorator; 12-01-2008 at 09:42 AM. |
| maxorator is offline | |
| | #35 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| Well, generating a list of primes less than the maximum root you expect to encounter should allow for an optimized check of the numbers larger than 2^32 as laserlight and i discussed. I am currently adding LL's code to my own to increase the speed of the base algorithm, which should allow for faster throughput.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #36 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| My submission. Takes 3.8 seconds on my system.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #37 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| It doesnt compile, rand() apparently isnt defined in cmath, so ill include it and also, typedefing __int64 to bignum doesnt work, as the test program expects the actual function declaration to be PrimeFunc(__int64*), not PrimeFunc(BigNum*); ill fix that as well.
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #38 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Okie dokie.
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #39 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| process terminated after 15 minutes, no results returned... the only changes I made to your code are - Code: #include <math.h> #include <stdlib.h> //typedef __int64 Bignum; #define Bignum __int64 Code: #ifdef USE_BUILTIN_MAIN
int main()
{
__int64 output[100000];
PrimeFunc(output);
return 0;
}
#endif
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet Last edited by abachler; 12-01-2008 at 06:43 PM. |
| abachler is offline | |
| | #40 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| ok, here is the base code updated to use laserlights routine to generate the divisors, it then specifically uses the divisors to test primality. The original took 146 seconds, this version took 35, 5 times faster, so definately a worthwhile optimization. Code: #define DWORD unsigned __int32
#define OFFSET 2
extern void laserlight(__int64*);
void abachler(__int64* PrimeList){
__int64 Prime = 4294967297;
__int64 Root = 1;
__int64 PrimeCount = 0;
__int64 Divisors[100000];
laserlight(Divisors);
prime_start:
while(PrimeCount < 100000){
Prime += OFFSET;
while((Prime / Root) > Root) Root++;
for(DWORD Test = 1;Divisors[Test] <= Root;Test++){ // skips the 2
if(Prime % Divisors[Test] == 0) goto prime_start;
}
PrimeList[PrimeCount] = Prime;
PrimeCount++;
}
return;
}
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet Last edited by abachler; 12-01-2008 at 07:51 PM. |
| abachler is offline | |
| | #41 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Stupid signed integer math... Try this:
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #42 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| ahem, PrimeFunc(__int64*) not PrimeFunc(Bignum*), but I went ahead and added this fix Code: void PrimeFunc(__int64* data){
PrimeFunc((Bignum*) data);
return;
}
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet |
| abachler is offline | |
| | #43 | ||
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,381
| Quote:
Quote:
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot | ||
| brewbuck is offline | |
| | #44 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,365
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #45 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| Can we use CUDA (Compute Unified Device Architecture)? Otherwise what's the point of saying you have a 8600GT? ... there's a horse sitting in the stable and I want to play with him! Basically my plan is to adapt brewbuck's code and win :-) the only problem is I need to understand how it works first... Last edited by zacs7; 12-02-2008 at 01:28 AM. |
| zacs7 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| xor linked list | adramalech | C Programming | 23 | 10-14-2008 10:13 AM |
| prime number program with function | mackieinva | C Programming | 17 | 09-20-2007 08:36 AM |
| Prime Number stops after 29, but why? | Daveo | C Programming | 22 | 09-17-2004 10:55 AM |
| Somewhat new to c++, adding Prime number and Sqrt featre to program... | thynksheraze | C++ Programming | 3 | 01-14-2003 10:34 PM |
| Random number generator | Caze | C++ Programming | 6 | 12-03-2002 08:10 AM |