IntelĀ® Developer Zone - P1: A2 - Consecutive Primes (Archived)
https://software.intel.com/en-us/taxonomy/term/36961
Don't miss your chance to ask questions and engage with others also working on this problem.
enCongrats
https://software.intel.com/en-us/forums/topic/282482
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Hi all,</p>
<p>I would like to congratulate all participants, but specially to Rick for winning the second problem and for achieve a fantastic performance. From my side, I am happy to have obtained the third position. My trial division algorithm is nothing special, and even when some improvements can double its speed (gross estimation), it is not good enough to beat Rick's solution. Vovanx86 also did a fantastic job, and there are also some very fast solutions who did not get a better result because of correctness problems. </p>
<p>Once again, Congratulation to everybody. Good job:o)</p>
<p>-Miguel</p>
</div></div></div>Fri, 05 Aug 2011 08:15:07 +0000jmfernandez282482 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/282482#commentsWinners Announced for Apprentice Problem 2, Sums of Consecutive Primes, for Threading Challenge 2011
https://software.intel.com/en-us/forums/topic/282506
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Apprentice Level Problem Set 2 (P1:A2) Sums of Consecutive Primes
</p>
<p><strong>Key Scoring Principles</strong>
<p>Basic scoring principles used for the contest entries judging are described at the <a href="http://software.intel.com/en-us/articles/intel-threading-challenge-2011-official-rules/">official rules</a> page. Here is a short summary: each contest entry was scored according to the following criteria: 1) up to 100 points for solutions performance (speed); 2) a maximum of 25 bonus points for a contestants activity in the forum, calculated as 5 bonus points for each valid forum post/reply. </p>
<p>In addition to that judges decided to reward the most correct contest entries. Successful solutions which found all the possible combinations of consecutive prime number sets and perfect powers got up to 60 points for solutions correctness.</p>
<p><strong>Input Data Sets Used for Performance Scoring</strong>
<p>Six different input data sets were used to compute the execution score for this problem. Each data set defined as a range to find prime numbers and a maximal power to compute perfect powers. Here is the list of data sets used for performance scoring (start and end of the range, max power):</p>
<p> 2 104567 8</p>
<p> 1045 80337 6</p>
<p> 250 60075 7</p>
<p> 2003 30003 14</p>
<p> 5065 40024 5</p>
<p> 10004 70004 3</p>
<p><strong>Points in Performance Scoring</strong>
<p>Each input data set was judged individually. The weights of data sets used in performance scoring were equivalent. The overall performance score was calculated as a sum of all six input data sets individual performance.</p>
<p>We allowed a total of 600 seconds (10 minutes) execution maximum for each input set; for those runs that took longer than 600 seconds or had runtime errors during execution, zero performance points were awarded. Some entries that could not be built on the MTL and those entries that were not able to correctly solve input data set got zero points as well.</p>
<p>Successful contest entries that found all possible number sets in less than 10 minutes were ranked based on their execution time and got performance points according a linear scale. </p>
<p>Only 100% correct entries got performance points.</p>
<p><strong>Correctness points</strong>
<p>To reward 100% correct contest entries, 10 correctness points were awarded to the those entries that found all the possible combinations of sums and powers. 5 or 2 incentive correctness points provided to those entries that missed a few combinations, no more than 20 and 200 combinations respectively.</p>
<p><strong>Execution Results and Point Spread</strong>
<p>Weve received 32 contest entries in the Apprentice Level Sums of Consecutive Primes problem set.</p>
<p>Only eight entries successfully solved all six input data sets. 16 entries solved one or more data sets. Unfortunately, nine entries were incomplete and therefore unable to solve any test data sets. </p>
<p>All the timings, performance and correctness points are available in the final Sums of Consecutive Primes score table (attached).</p>
<p><strong>Forum Activity and Bonus Points</strong>
<p>Additional bonus points were given for contestants forum posts made before the problem entries were closed. Five points per post (maximum 25 points possible) were awarded.</p>
<p><strong>Entry points and penalties.</strong>
<p>Each contest entry got 100 entry points. A penalty of 30 points was taken off in case the entry use significant amount of precompiled information (precompiled prime numbers, for example).</p>
<p><strong>Winners</strong>
<p>The problem winners based on highest point total are:</p>
<p>1. dotcsw</p>
<p>2. VoVanx86</p>
<p>3. jmfernandez </p>
<p>These three contestants provided the solutions which correctly solved all the input data sets. They also had the fastest overall code execution and significant bonus points for activity in the contest forum.</p>
<p><strong><a href="http://software.intel.com/file/m/37969">Scoring Table</a>- You may download the Scoring Table.</strong></p>
</div></div></div>Thu, 04 Aug 2011 00:05:58 +0000Jeff Kataoka (Intel)282506 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/282506#commentsThe Winners for Apprentice Problem 2, Consecutive Primes, will be announced later this week
https://software.intel.com/en-us/forums/topic/282633
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Some final testing and analysis of the entries for Problem 2, Consecutive Primes, is being completed by the judges. We will be announcing the winners by the end of this week. Thanks for your patience.</p>
</div></div></div>Wed, 27 Jul 2011 03:55:01 +0000Jeff Kataoka (Intel)282633 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/282633#commentsThe suspense is killing me!
https://software.intel.com/en-us/forums/topic/282648
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>I keep checking in here to see if there's any announcement on judging Consecutive Primes. It took six weeks to finish judging the first round (Maze of Life). It has now been seven weeks since this problem closed and no word yet on when the winners will be announced. I sure hope they can score the third round (Running Numbers) before the Grand Prize becomes moot.</p>
<p>One challenge for the judges in scoring Consecutive Primes is going to be deciding where to draw the line on pre-computed primes and powers. Rama <a href="http://software.intel.com/en-us/forums/showpost.php?p=151356">suggested a limit of 20</a> but the contestants had widely differing interpretations on this point. This should be interesting!</p>
<p>- Rick</p>
</div></div></div>Mon, 25 Jul 2011 22:29:10 +0000dotcsw282648 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/282648#commentsPost-mortem
https://software.intel.com/en-us/forums/topic/283077
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Problem 2 was a fun one (the one i liked best to be honest) these are the optimalisations i used:</p>
<p>1) Prime generation</p>
<p>Generating primes is fun and can be done quickly but there's one thing even better not having to calculate them! However a table of all primes < 2^32 turned out to be about 800+ megs, too massive,the load time will have eaten me alive. Plus a binary search to find the proper start end end indexes wouldn't have been too snappy either.</p>
<p>But what if there's a way to cut that massive table down in size and pretty much give us a direct index to the numbers we want? Well all primes > 5 you can express as 30k1, 30k7, 30k11, 30k13. Which is exactly 8 bits! Cuts the table down to a nicer 136 megs and it'll give you instant primes!</p>
<p>2) Determining if its a power or not</p>
<p>2a) Do we even need to bother checking a number? </p>
<p>Numbers that are a power of something have a funny property in binary, if you look at the lowest nibble it will *NEVER* be 2,6,10,12 or 14, so that quickly gets rid of about 30% of numbers with a single 'and' instruction and a few compares.</p>
<p>2b) The numbers that are left after that:</p>
<p>The sum of all primes in play is 425649736193687430, which square root is 65241837.5119591 meaning the highest number we would ever see as a base is 65241837. So i figured i'd loop though all numbers [2..65241837] ^ [2..100] see if its below 425649736193687431 and store the base+power+value (only the lowest power+base for numbers that are multiple powers) in a lookup table (i bet by now you all are going 'damn this guy *really* likes his lookup tables' ) </p>
<p>Well turns out that table gets *BIG* really quickly but is quite managable for powers > 2. </p>
<p>But what about the powers of 2 then? </p>
<p>Well powers of 2 have the interesting property that the lower nibble always is 0,1,4 or 9, so if its that run a good old sqrt and see if its a square or not (i tried a lookup table here too but sqrt turned out to be faster)</p>
<p>Further improvements for powers > 2</p>
<p>Initially i had them all in a big sorted list which i did a binary search on which worked well but due to the size of the table not the best performer. So the speed it up i turned it into a really basic hash table using bits 21-43 of the number as a hash which gave me less then 10 numbers in most buckets which is stupidly fast to search through.</p>
<p>3) Threading</p>
<p>Just a parralel loop though the primes adding them up, not much to it really this was by far the easiest of the 3 problems to thread.</p>
<p>Most of my time on this problem was spend trying to figure out why the 40 core windows MTL box *REFUSED* to use all of the cores using both openmp or TBB, you always ended up on a random processor group (either cores 0-9 or 10-39) but never on all of them. Turns out that in the intel v11 compiler which was on the box OpenMP was not aware of processor groups (new in win7/2008R2) and TBB (which was aware) had a subtile bug in the code that assigned threads to cores. Found the bug made a quick work around (Details are somewhere in a thread in the TBB forum) and figured my solution would definitly have an edge over other ones that would end up not using all cores... and then intel moved us all out of the box cause it 'had issues' (i said it before, i'll say it again: BOO!) </p>
<p>In the end i ran out of time and the code ended up being a bit (and by a bit, i mean ALOT) messy but functional.</p>
<p>Warning due to the *MASSIVE* lookup tables the code is a whopping 112 megs compressed.</p>
</div></div></div><div class="field field-name-field-attachments field-type-file field-label-hidden"><div class="field-items"><div class="field-item even"><table class="sticky-enabled">
<thead><tr><th>Attachment</th><th>Size</th> </tr></thead>
<tbody>
<tr class="odd"><td><span class="file"><a href="https://software.intel.com/system/files/69/03/LazyDodo_Problem2.zip" class="button-cta">Download</a> <img class="file-icon" alt="" title="application/zip" src="/sites/all/themes/isn3/css/images/attachment_icon.png" /> <a href="https://software.intel.com/system/files/69/03/LazyDodo_Problem2.zip" type="application/zip; length=117064729">LazyDodo_Problem2.zip</a></span></td><td>111.64 MB</td> </tr>
</tbody>
</table>
</div></div></div>Wed, 29 Jun 2011 02:08:47 +0000lazydodo283077 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283077#commentsMemory
https://software.intel.com/en-us/forums/topic/283493
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>In scoring, are points taken away for memory leaks? Not that I have any, but I was wondering if bad programming is punished at all.</p>
</div></div></div>Mon, 06 Jun 2011 21:13:03 +0000percoction283493 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283493#commentsg++ and OpenMP vs icc and TBB
https://software.intel.com/en-us/forums/topic/283495
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>I tried to compare performances of the compilers and threading libraries.</p>
<p>My conclusion are:</p>
<p>icc produce better binaries than g++ (up to x2.5 time faster).<br />It is easier to code whith OpenMP but TBB has a lower overhead (up to x2).</p>
<p>So use intel tools when possible ...</p>
<p>I'd like to have your opinion.</p>
</div></div></div>Mon, 06 Jun 2011 16:28:30 +0000varslan283495 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283495#commentsClosing Date for Apprentice Level Problem 2, Consecutive Primes, extended to 12:00pm Noon, Pacific Daylight Time, Monday, June 6, 2011.
https://software.intel.com/en-us/forums/topic/283532
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>ApprenticeLevel Participants: My special gift to you. Due to my reminder message error regarding the closing date for theApprentice Level Problem 2, Consecutive Primes, we will formally extend the closing date for Problem 2 to 12:00pm, Noon, Pacific Daylight Time, Monday, June 6, 2011. We will update the website to reflect this change. If you have already submitted your entry, you may submit an updated entry by this new deadline. Hope you can take advantage of this extra time</p>
</div></div></div>Fri, 03 Jun 2011 05:47:08 +0000Jeff Kataoka (Intel)283532 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283532#commentsReminder: Apprentice Problem 2, Consecutive Primes, closes at 12:00pm Noon, Pacific Daylight Time, Monday, June 6, 2011
https://software.intel.com/en-us/forums/topic/283539
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Just a reminder that Apprentice Problem 2, Consecutive Primes, closes at 12:00pm Noon, Pacific Daylight Time, Monday, June 6, 2011. Please make sure to submit your entry by this deadline.</p>
<p>Keep up the good work!</p>
</div></div></div>Thu, 02 Jun 2011 23:08:03 +0000Jeff Kataoka (Intel)283539 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283539#commentsExamples
https://software.intel.com/en-us/forums/topic/283724
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Hello,can you please send me more examples of the script expected results? These has been really useful but I need some with much much higher numbers to stress my script at its limit. Is it possible?Also, I wrote my entire code in C: is this ok?Thanks!J.sum(3:5) = 8 = 2**3<br />sum(17:19) = 36 = 6**2<br />sum(2:23) = 100 = 10**2<br />sum(13:19) = 49 = 7**2<br />sum(5:13) = 36 = 6**2</p>
</div></div></div>Fri, 20 May 2011 18:32:01 +0000saturnix283724 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283724#comments2
https://software.intel.com/en-us/forums/topic/283794
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Can the algorithm we use for generating the prime numbers initially<br />
know that 2 is a prime number, or do we need to discover this fact each time<br />
we run the program?</p>
</p>
</div></div></div>Sun, 15 May 2011 02:09:47 +0000cousseau283794 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283794#commentsAlgorithm use
https://software.intel.com/en-us/forums/topic/283854
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Hi there,</p>
<p>Just a thought regarding the "original creation" phrase in the rules:<br />
how would it be viewed if I said, for example, "I implemented algorithm<br />
ABC by John Smith to solve this problem"? Assuming that the algorithm<br />
is in the public domain, of course, and available to be used by anyone (for non-commercial use at least),<br />
is that all OK?</p>
<p>This wasn't really much of an issue for the Maze of Life, but there's<br />
plenty of commentary out there about calculation of prime numbers. It's<br />
hard to say whether implementing an advanced algorithm would be<br />
practical in a limited time, but well, it'd be interesting to know :)</p>
<p>Thanks!</p>
</div></div></div>Wed, 11 May 2011 22:54:46 +0000yoink283854 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283854#commentsOutput precision
https://software.intel.com/en-us/forums/topic/283885
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>The problem definition states that "the input values will be represented with 32-bit unsigned integers". Is it safe to assume that the output values (including the sums of primes) will also representable with 32-bit unsigned integers?</p>
<p>When you start adding together large 32-bit values, pretty soon you're talking 33 or 34 bits. It will impact the performance of the inner loop if those calculations must be done with 64-bit integers.</p>
<p>- Rick</p>
</div></div></div>Tue, 10 May 2011 18:45:13 +0000dotcsw283885 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283885#commentsSidecases, what to report?
https://software.intel.com/en-us/forums/topic/283902
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>From the example case</p>
<p>sum(17:19) = 36 = 6**2<br />sum(5:13) = 36 = 6**2</p>
<p>I'm able to tell that if several sequences produce the same sum they all have to be reported, but how do we handle duplicates on the power side of things?</p>
<p>for instance:</p>
<p>sum(20063:32987) and sum(2097031:2097287) both produce 33554432 (frist draft of my app, results could be wrong) no problem just report both lines, yet 33554432 gives an interesting sidecase being both 2^25 and 32^5.</p>
<p>Do we just pick one? if so which one should we pick? does it matter? do we pick both? if so how do we report?</p>
<p>like this</p>
<p>sum(20063:32987)=33554432=2**25=32**5<br />sum(2097031:2097287)=33554432=2**25=32**5</p>
<p>or like this:</p>
<p>sum(20063:32987)=33554432=2**25<br />sum(20063:32987)=33554432=32**5<br />sum(2097031:2097287)=33554432=2**25<br />sum(2097031:2097287)=33554432=32**5</p>
<p>Also note this problem is not limited to 2 duplicates, for instance sum(7063741:7064419) gives us 268435456 which I can make out of 2^28, 4^14, 16^7 and 128^4</p>
<p>Please advise.</p>
<p></p>
</div></div></div>Tue, 10 May 2011 05:02:05 +0000lazydodo283902 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283902#commentsIs 1 considered prime?
https://software.intel.com/en-us/forums/topic/283905
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>Wikipedia says that 1 is no longer considered prime by mathematicians. How should it be handled for the purposes of this challenge?</p>
<p>Looking at the example output from "primesums.exe 1 29 6 sumsout.txt" one thing I do not see is:<br />sum(1:9) = 27 = 3**3</p>
<p>So my guess is that 1 is not prime. This leads to my next question...</p>
<p>Can we assume that the first and second command line arguments are prime?</p>
<p>- Rick</p>
</div></div></div>Tue, 10 May 2011 01:54:47 +0000dotcsw283905 at https://software.intel.comhttps://software.intel.com/en-us/forums/topic/283905#comments