C Board  

Go Back   C Board > Community Boards > Contests Board

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2008, 03:31 PM   #1
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
Prime Number Generator

OK, the contest is to generate 100 thousand unique Prime numbers from 2^32 to 2^64-1 in the shortest time possible. There are some limits of course.

1. You cannot load any values from external files.
2. Your entire program must be contained in a single cpp file of less than 64K named PrimeFunc.cpp with a function named PrimeFunc(__int64*) which will be called by the test program.
3. You may use no more than 10 'seed' values none of which may be greater than 2^32-1
4. All code must compile under visual studio 2008 express as a win32 console program. Default optimzation settings will be used.
5. All results must be placed into the __int64* array supplied by the test program.
6. You may not use any file or network access functions.
7. You may use inline assembly, OpenMP, threads, even the GPU as long as you limit GPU code to HLSL.
8. There can be no composite numbers returned
9. You must return exactly 100 thousand primes, no more no less.
10. Programs that crash are disqualified.
11. Programs that take more than 5 minutes to complete are disqualified.
12. Entries should be made public.
13. This contest is open ended so further optimizations should be submitted as a new entry.
14. (Optional)The solution should be general enough so that it could in theory be applied to build a comprehensive list of all primes.
15. You may not include any header files other than <math.h>, some exceptions may be made to this ask first.

The test system is a Pentium 4HT 3.2 GHz with 2GB of 800MHz dual channel memory. The GPU is an 8600 with 1GB of ram. A non-optimized test program was run and completed within the alloted time.
__________________
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; 11-26-2008 at 03:36 PM.
abachler is offline   Reply With Quote
Old 11-26-2008, 03:47 PM   #2
Registered User
 
Join Date: Jan 2005
Posts: 7,137
How will you be verifying the correctness of the returned values?
Daved is offline   Reply With Quote
Old 11-26-2008, 04:09 PM   #3
Registered User
 
Join Date: Apr 2006
Location: United States
Posts: 3,201
>> 3. You may use no more than 10 'seed' values none of which may be greater than 2^32-1

Does it not make sense to start from the first number in the range you require?
__________________
Os iusti meditabitur sapientiam
Et lingua eius loquetur indicium

"There is nothing either good or bad, but thinking makes it so." (Shakespeare, Hamlet, Act II scene ii)

http://www.myspace.com/whiteflags99
whiteflags is offline   Reply With Quote
Old 11-26-2008, 04:11 PM   #4
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
the test program will verify the values in the array after the PrimeFunc() returns.. It will test every value both for uniqueness and for primality.

The testing phase of the program is not counted against the runtime of the function.

Starting from 2^32+1 is fine, since it is not prime. By seed value I mean specifically prime numbers or precalculated values used to circumvent doign the actual calculations. Some algorithms require seedign with known primes to operate efficiently, so I allow the use of 10. The rule is to prevent someone from just writing a huge array with all the values and returnign it.
__________________
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; 11-26-2008 at 04:23 PM.
abachler is offline   Reply With Quote
Old 11-26-2008, 04:18 PM   #5
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,139
Do we have to write it in C++?
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 11-26-2008, 04:26 PM   #6
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
Quote:
Originally Posted by zacs7 View Post
Do we have to write it in C++?
as stated, you can also use inline assembly or HLSL. No C# python or java if thats what you mean.

here is an example of one possible solution.
Attached Files
File Type: cpp PrimeFunc.cpp (531 Bytes, 224 views)
__________________
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; 11-26-2008 at 05:35 PM.
abachler is offline   Reply With Quote
Old 11-26-2008, 07:16 PM   #7
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
I think he wanted to ask can we do it in plain C.
2. - Can't we use unsigned long long instead of int64? I'm somehow safer with it.
4. - Why not use mingw? And what's with the optimizations?
__________________
I reinvent the wheel to understand how it works.

Platform:
Windows XP SP2 Professional Edition
Compiler: GCC 4.3.0
Editor: Notepad++ 5.4.2
Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin.

--Quotes--
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
hauzer is offline   Reply With Quote
Old 11-26-2008, 07:30 PM   #8
Nor
‡ †hë Ö†hÈr sîÐè ‡
 
Nor's Avatar
 
Join Date: Nov 2001
Posts: 274
RSA Encryption
Your Going Down baby
__________________
Try to help all less knowledgeable than yourself, within
the limits provided by time, complexity and tolerance.
- Nor
Nor is offline   Reply With Quote
Old 11-26-2008, 07:38 PM   #9
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
Quote:
Originally Posted by hauzer View Post
I think he wanted to ask can we do it in plain C.
2. - Can't we use unsigned long long instead of int64? I'm somehow safer with it.
4. - Why not use mingw? And what's with the optimizations?
yeah plain C is fine.

you can recast the function call internally if you want, but the test program is already written and the test procedure will just invovle drag drop compile and run.
Code:
void YourFunc(long long*);
 
void PrimeFunc(__int64* blah){
   YourFunc((long long*) blah);
   return;
   }
 
void YourFunc(long long* blah){
   return;
   }
is fine

and im not using mingw because I use VS. I stated what compiler so that you know what compiler specific extensions you can and cant use.

The default optimizations on my compiler are compile for speed and it uses the static multithreaded runtimes if thats important, it shouldnt be.
__________________
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   Reply With Quote
Old 11-26-2008, 07:55 PM   #10
Nor
‡ †hë Ö†hÈr sîÐè ‡
 
Nor's Avatar
 
Join Date: Nov 2001
Posts: 274
Where do we need to send our entrys?
__________________
Try to help all less knowledgeable than yourself, within
the limits provided by time, complexity and tolerance.
- Nor
Nor is offline   Reply With Quote
Old 11-26-2008, 07:57 PM   #11
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
just post them here, its an open ended contest, so no need to keep secrets
__________________
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   Reply With Quote
Old 11-26-2008, 08:49 PM   #12
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,139
Can we use the network card, if you catch my drift? :-)
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 11-26-2008, 08:58 PM   #13
The wheel reinvent0^r
 
hauzer's Avatar
 
Join Date: Aug 2008
Location: Србија
Posts: 115
@abachler: Ok, all good.
__________________
I reinvent the wheel to understand how it works.

Platform:
Windows XP SP2 Professional Edition
Compiler: GCC 4.3.0
Editor: Notepad++ 5.4.2
Notes: Successfully using MSYS, loving my Windows makefiles. Never, ever use Cygwin.

--Quotes--
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
hauzer is offline   Reply With Quote
Old 11-26-2008, 09:59 PM   #14
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,924
Quote:
Originally Posted by zacs7 View Post
Can we use the network card, if you catch my drift? :-)
Sure as long as you follow rule #1 and #6, by all means use teh PIC on the NIC to crunch numbers

and good luck accessign it without breakign rule #15 or #2 part b

oh as far as teh earlier statement that plain C is ok, its OK as long as it will compile as C++ code. So make sure you use explicit recasts. Im not going to edit your code to get it to compile.
__________________
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; 11-26-2008 at 10:14 PM.
abachler is offline   Reply With Quote
Old 11-26-2008, 10:16 PM   #15
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 10,352
Quote:
Originally Posted by abachler
2. Your entire program must be contained in a single cpp file of less than 64K named PrimeFunc.cpp with a function named PrimeFunc(__int64*) which will be called by the test program.
5. All results must be placed into the __int64* array supplied by the test program.
Instead of __int64, I suggest that you go with something like sqlite3_int64.

Quote:
Originally Posted by abachler
15. You may not include any header files other than <math.h>, some exceptions may be made to this ask first.
In C++ that should be <cmath>. Actually, why not just allow the C and C++ standard libraries?
__________________
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 offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:40 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22