User Tools

Site Tools


haas:fall2017:discrete:projects:pnc1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
haas:fall2017:discrete:projects:pnc1 [2017/07/13 14:26] wedgehaas:fall2017:discrete:projects:pnc1 [2017/10/15 21:09] (current) wedge
Line 4: Line 4:
 </WRAP> </WRAP>
  
-~~TOC~~ +======Project: ALGORITHM OPTIMIZATION - PRIME NUMBER COMPUTATION (pnc1)======
- +
-======Project: ALGORITHMS - PRIME NUMBER CALCULATION (pnc1)======+
  
 =====Errata===== =====Errata=====
Line 14: Line 12:
  
 ====Revision List==== ====Revision List====
-  * revision 0: initial release (20170712)+
   * revision #: <description> (DATESTRING)   * revision #: <description> (DATESTRING)
  
Line 20: Line 18:
  
 =====Objective===== =====Objective=====
-To apply your skills in the implementation of prime number calculating algorithms.+To continue our exploration of algorithms and optimizations applied to them, through further work on the prime number computation programs started in pnc0.
  
 =====Background===== =====Background=====
Line 92: Line 90:
   * you know the starting value and the terminating condition, so you have a clear starting and ending point to work with.   * you know the starting value and the terminating condition, so you have a clear starting and ending point to work with.
   * I want you to use two **DIFFERENT** kind of loops in your programs. If you use a **for()** loop in your outer loop, I want you to use a **while()** or **do-while()** loop in your inner loop (and whatever combination you end up with).   * I want you to use two **DIFFERENT** kind of loops in your programs. If you use a **for()** loop in your outer loop, I want you to use a **while()** or **do-while()** loop in your inner loop (and whatever combination you end up with).
 +  * I do **NOT** want to see ambiguous, one-letter variables used in your implementation(s). Please use //meaningful// variable names.
 +    * Some good examples of variable names would be:
 +      * **number**: the number being tested
 +      * **factor**: the value being divided into number to test for primality
 +      * **step**: the rate by which some variable is changing
 +      * **qty**: the count of the current tally of primes
 +      * **max**: the maximum count we seek
 +      * **start**: a value we are starting at
 +      * **lower**: a lower bound
 +      * **upper**: an upper bound
 +      * see how much more readable and meaningful these are, especially as compared to **a**, **i**, **n**, **x**? You may even find it helps with debugging and understanding your code better.
   * let the loops drive the overall process. Identify prime/composite status separate from loop terminating conditions.   * let the loops drive the overall process. Identify prime/composite status separate from loop terminating conditions.
     * and remember, the baseline brute force algorithm (**primereg**) may well identify a value as composite, but won't terminate the loop.     * and remember, the baseline brute force algorithm (**primereg**) may well identify a value as composite, but won't terminate the loop.
-  * your timing should start before the loop (just AFTER argument processing), and terminate immediately following the terminating newline outside the loops.+  * your timing should start before the loop (just AFTER argument processing), and terminate immediately following the terminating output newline outside the loops
 +  * you may **NOT** split **qty** and **range** functionality into two separate code blocks (ie have two sets of two loops). Only the one set as indicated
  
 =====prime algorithm optimizations===== =====prime algorithm optimizations=====
Line 118: Line 128:
 That is, if your program to implement is **primerego**, that means you are ONLY to implement the brute force algorithm and odds-only checking. **NO** break on composite, **NO** sqrt() trick, etc. We are establishing separate data points for analytical comparison. That is, if your program to implement is **primerego**, that means you are ONLY to implement the brute force algorithm and odds-only checking. **NO** break on composite, **NO** sqrt() trick, etc. We are establishing separate data points for analytical comparison.
  
-Some of these optimizations can co-exist easily (break + map, odd + sqrt()), others are conditionally compatible (map + odd can coexist in a certain form), while others are mutually exclusive (sqrt() and approximated square root conflict). So there are definitely a few combinations that are possible using this scheme.+Some of these optimizations can co-exist easily (break + map, odd + sqrt()), others are partially compatible (map + odd can coexist in a certain form), while others are mutually exclusive (sqrt() and approximated square root conflict). So there are definitely a few combinations that are possible using this scheme.
  
-Here are the variants you'll be implementing for this project:+=====A note on comments===== 
 +Something I noticed (and have historically noticed) in relation to comments that I'd like to point out:
  
-====break on composite (primeregb)==== +Comments should be describing what is going on in your code.
-This optimization to primereg will make but one algorithmic change, and that takes place at the moment of identifying a number as compositeSo, if we had our 119 example above, and discovered that 7 was a factor:+
  
-There is no further need to check the remaining valuesas once we have proven the non-primality of numberthe state is set: it is composite. So be sure to use a **break** statement to terminate the computation loop (how does this impact overall performance???).+With projects like thisoften relying on common basecomments become even more important, as they allow me to see specifically what is changed or unique about one variant over the other.
  
-Make no other optimizations- this first project is to set up some important base line values that we can use for algorithmic comparison later on.+As such, when evaluating the project, I will be looking for pertinent comments specifically covering the how or why of the particular change unique to the variant in question.
  
-====mapping factors of 6 (primeregm)==== +And notice I said the "how" and/or "why". NOT the "what". I see all the time vague comments like "<nowiki>// doing the sqrt() optimization</nowiki>"..but:
-This optimization will check only the numbers that fall on either side of a factor of 6 for primality.+
  
-NOTE: If applicable, just display the initial "2" and "3" as hardcoded values.+  * WHY is that important to the process? 
 +  * HOW does it impact the efficiency of the algorithm?
  
-====odds-only checking (primerego)==== +These are things I'd like to see addressed in your comments, as there were some cases where the WHAT was claimed, yet what actually followed had little resemblance (if anyon the requirements for that variant.
-This optimization will check only the odd numbers for primality, skipping the evens entirely.+
  
-NOTE: If applicable, just display the initial "2" as a hardcoded value. +Just like if you can't do it by hand you have no business trying to code it- if you cannot adequately explain the WHY and HOW, you similarly will have trouble.
- +
-====sqrt() trick (primeregs)==== +
-This optimization employs the square root trick utilizing the C library's **sqrt()** function. +
- +
-====sqrt()-less square root approximation (primerega)==== +
-This optimization employs the approximated square root trick (**NOT** utilizing an existing square root function, but using simpler logic you implement to approximate the square root point). +
- +
-====primeregbm==== +
-To get a taste for combining optimizations, you'll also implement a variant that incorporates both the **break** AND the **map** optimizations. +
- +
-NOTE: If applicable, just display the initial "2" and "3" as hardcoded values. +
- +
-====primeregbo==== +
-To get a taste for combining optimizations, you'll also implement a variant that incorporates both the **break** AND the **odds-only checking** optimizations. +
- +
-NOTE: If applicable, just display the initial "2" as a hardcoded value. +
- +
-====primeregbs==== +
-To get a taste for combining optimizations, you'll also implement a variant that incorporates both the **break** AND the **sqrt()** optimizations. +
- +
-====primeregba==== +
-To get a taste for combining optimizations, you'll also implement a variant that incorporates both the **break** AND the **approximated square root** optimizations.+
  
 =====Programs===== =====Programs=====
 It is your task to write the following prime number variants: It is your task to write the following prime number variants:
  
-  **primereg.c**: our baseline (does JUST the process, no optimizations) +  * the remainder of the viable double optimization combinations: 
-  **primeregb.c**: tests specifically the break optimization +    * **primeregmo.c**: map + odd traversal optimizations 
-  **primeregm.c**: tests specifically the map traversal +    **primeregms.c**: map traversal + sqrt() trick 
-  **primerego.c**: tests specifically the odd traversal +    * **primeregma.c**: map treversal + approximated square root trick 
-  **primeregs.c**: tests specifically the square root trick (using sqrt()) +    * **primeregos.c**: odd traversal + sqrt() trick 
-  **primerega.c**: tests specifically the square root trick by approximating square root +    **primeregoa.c**: odd traversal + approximated square root trick 
-  **primeregbm.c**: tests the break and map optimizations (together+  * all of the viable triple optimization combinations: 
-  **primeregbo.c**: tests the break and odd optimizations (together+    * **primeregbmo.c**: break + map + odd traversal 
-  **primeregbs.c**: tests the break and sqrt() optimizations (together) +    * **primeregbms.c**: break + map + sqrt() trick 
-  **primeregba.c**: tests the break and approximated square root optimizations (together)+    **primeregbma.c**: break + map + approximated square root trick 
 +    * **primeregbos.c**: break + odd + sqrt() trick 
 +    * **primeregboa.c**: break odd + approximated square root trick 
 +    * **primeregmos.c**: map + odd traversal + sqrt() trick 
 +    * **primeregmoa.c**: map + odd traversal + approximated square root trick 
 +  * all of the viable quadruple optimizations combinations: 
 +    * **primeregbmos.c**: break + map + odd + sqrt() trick 
 +    * **primeregbmoa.c**: break + map + odd + approximated square root trick
  
 ====Program Specifications==== ====Program Specifications====
Line 215: Line 209:
  
 To "grab" it: To "grab" it:
- 
-NOTE: You will **NEED** to specify the semester as indicated as the semester in question has not yet started. 
  
 <cli> <cli>
-lab46:~/src/discrete$ SEMESTER=fall2017 grabit discrete pnc0 +lab46:~/src/discrete$ grabit discrete pnc1 
-make: Entering directory '/var/public/fall2017/discrete/pnc0+make: Entering directory '/var/public/SEMESTER/discrete/pnc1
-Commencing copy process for fall2017 discrete project pnc0+Commencing copy process for SEMESTER discrete project pnc1
- -> Creating project pnc0 directory tree           ... OK + -> Creating project pnc1 directory tree           ... OK 
- -> Copying pnc0 project files                     ... OK + -> Copying pnc1 project files                     ... OK 
- -> Synchronizing pnc0 project revision level      ... OK + -> Synchronizing pnc1 project revision level      ... OK 
- -> Establishing sane file permissions for pnc0    ... OK+ -> Establishing sane file permissions for pnc1    ... OK
  
-*** Copy COMPLETE! You may now go to the '/home/USER/src/discrete/pnc0' directory ***+*** Copy COMPLETE! You may now go to the '/home/USER/src/discrete/pnc1' directory ***
  
-make: Leaving directory '/var/public/fall2017/discrete/pnc0'+make: Leaving directory '/var/public/SEMESTER/discrete/pnc1'
 lab46:~/src/discrete/ lab46:~/src/discrete/
-lab46:~/src/discrete$ cd pnc0 +lab46:~/src/discrete$ cd pnc1 
-lab46:~/src/discrete/pnc0$ ls +lab46:~/src/discrete/pnc1
-Makefile      primereg.c    primeregb.c    primeregm.c +
-primeregbm.c  primeregba.c  primerego.c    primeregbs.c +
-primeregs.c   primerega.c   primeregbo.c +
-lab46:~/src/discrete/pnc0+
 </cli> </cli>
  
-NOTE: You do NOT want to do this on a populated pnc0 project directory-- it will overwrite files.+NOTE: You do NOT want to do this on a populated pnc1 project directory-- it will overwrite files.
  
 And, of course, your basic compile and clean-up operations via the Makefile. And, of course, your basic compile and clean-up operations via the Makefile.
Line 251: Line 239:
  
 <cli> <cli>
-lab46:~/src/discrete/pnc0$ make help +lab46:~/src/discrete/pnc1$ make help 
-******************[ Discrete Structures pnc0 Project ]******************+******************[ Discrete Structures pnc1 Project ]******************
 ** make                     - build everything                        ** ** make                     - build everything                        **
 ** make showerrors          - display compiler warnings/errors        ** ** make showerrors          - display compiler warnings/errors        **
-**                                                                    ** 
 ** make debug               - build everything with debug symbols     ** ** make debug               - build everything with debug symbols     **
-** make check               - check implementation for validity       **+** make checkqty            - runtime evaluation for qty              ** 
 +** make checkrange          - runtime evaluation for range            ** 
 +**                                                                    ** 
 +** make verifyqty           check implementation for qty validity   ** 
 +** make verifyrange         - check implementation for range validity ** 
 +** make verifyall           - verify project specifications           ** 
 +**                                                                    ** 
 +** make link                - link in previous prime programs         ** 
 +** make delink              - remove links to previous prime programs **
 **                                                                    ** **                                                                    **
 ** make save                - create a backup archive                 ** ** make save                - create a backup archive                 **
Line 269: Line 264:
 ** make help                - this information                        ** ** make help                - this information                        **
 ************************************************************************ ************************************************************************
-lab46:~/src/discrete/pnc0+lab46:~/src/discrete/pnc1
 </cli> </cli>
  
Line 281: Line 276:
   * **make save**: make a backup of your current work   * **make save**: make a backup of your current work
   * **make submit**: archive and submit your project   * **make submit**: archive and submit your project
 +
 +The various "check" options do a runtime performance grid, allowing you to compare timings between your implementations.
 +
 +The various "verify" options do more aggressive checks, helping to ensure your project falls within stated project specifications.
  
 Just another "nice thing" we deserve. Just another "nice thing" we deserve.
  
 =====Command-Line Arguments===== =====Command-Line Arguments=====
-To automate our comparisons, we will be making use of command-line arguments in our programs. As we have yet to really get into arrays, I will provide you some code that you can use that will allow you to utilize them for the purposes of this project.+To automate our comparisons, we will be making use of command-line arguments in our programs.
  
 ====header files==== ====header files====
Line 303: Line 302:
 int main(int argc, char **argv) int main(int argc, char **argv)
 </code> </code>
 +
 +There are two very important variables involved here (the types are actually what are important, the names given to the variables are actually quite, variable; you may see other references refer to them as things like "ac" and "av"):
 +
 +  * int argc: the count (an integer) of tokens given on the command line (program name + arguments)
 +  * <nowiki>char **argv</nowiki>: an array of strings (technically an array of an array of char) that contains "strings" of the various tokens provided on the command-line.
  
 The arguments are accessible via the argv array, in the order they were specified: The arguments are accessible via the argv array, in the order they were specified:
Line 311: Line 315:
   * argv[3]: conditionally optional; represents lower bound   * argv[3]: conditionally optional; represents lower bound
   * argv[4]: conditionally optional; represents upper bound   * argv[4]: conditionally optional; represents upper bound
 +
 +Additionally, let's not forget the **argc** variable, an integer, which contains a count of arguments (argc == argument count). If we provided argv[0] through argv[4], argc would contain a 5.
 +
 +===example===
 +For example, if we were to execute the **primeregbms** program:
 +
 +<cli>
 +lab46:~/src/discrete/pnc1$ ./primeregbms 128 1 2 2048
 +</cli>
 +
 +We'd have:
 +
 +  * <nowiki>argv[0]</nowiki>: "./primeregbms" 
 +  * <nowiki>argv[1]</nowiki>: "128" (note, NOT the scalar integer 128, but a string) 
 +  * <nowiki>argv[2]</nowiki>: "1"
 +  * <nowiki>argv[3]</nowiki>: "2" 
 +  * <nowiki>argv[4]</nowiki>: "2048" 
 +
 +and let's not forget:
 +
 +  * argc: 5   (there are 5 things, argv indexes 0, 1, 2, 3, and 4)
 +
 +With the conditionally optional arguments as part of the program spec, for a valid execution of the program, argc could be a value anywhere from 3 to 5.
  
 ====Simple argument checks==== ====Simple argument checks====
Line 392: Line 419:
  
 And with that, we can compute an approximate run-time of our programs. The timing won't necessarily be accurate down to that level of precision, but it will be informative enough for our purposes. And with that, we can compute an approximate run-time of our programs. The timing won't necessarily be accurate down to that level of precision, but it will be informative enough for our purposes.
- 
-=====Loops===== 
-A loop is basically instructing the computer to repeat a section, or block, or code a given amount of times (it can be based on a fixed value-- repeat this 4 times, or be based on a conditional value-- keep repeating as long as (or while) this value is not 4). 
- 
-Loops enable us to simplify our code-- allowing us to write a one-size-fits all algorithm (provided the algorithm itself can appropriately scale!), where the computer merely repeats the instructions we gave. We only have to write them once, but the computer can do that task any number of times. 
- 
-Loops can be initially difficult to comprehend because unlike other programmatic actions, they are not single-state in nature-- loops are multi-state. What this means is that in order to correctly "see" or visualize a loop, you must analyze what is going on with EACH iteration or cycle, watching the values/algorithm/process slowly march from its initial state to its resultant state. Think of it as climbing a set of stairs... yes, we can describe that action succinctly as "climbing a set of stairs", but there are multiple "steps" (heh, heh) involved: we place our foot, adjust our balance-- left foot, right foot, from one step, to the next, to the next, allowing us to progress from the bottom step to the top step... that process of scaling a stairway is the same as iterating through a loop-- but what is important as we implement is what needs to happen each step along the way. 
- 
-With that said, it is important to be able to focus on the process of the individual steps being taken. What is involved in taking a step? What constitutes a basic unit of stairway traversal? If that unit can be easily repeated for the next and the next (and in fact, the rest of the) steps, we've described the core process of the loop, or what will be iterated a given number of times. 
- 
-In C and C-syntax influenced languages (C++, Java, PHP, among others), we typically have 3 types of loops: 
- 
-  * **for** loop (automatic counter loop, stepping loop; top-driven) - when we know exactly how many times we wish something to run; we know where we want to start, where we want to end, and exactly how to progress from start to end (step value) 
-  * **while** loop (top-driven conditional loop) - when we want to repeat a process, but the exact number of iterations is either not known, not important, not known, or variable in nature. While loops can run 0 or more times. 
-  * **do-while** loop (bottom-driven conditional loop) - similar to the while loop, only we do the check for loop termination at the bottom of the loop, meaning it runs 1 or more times (a do-while loop is guaranteed to run at least once). 
- 
-====for() loops==== 
-A **for()** loop is the most syntactically unique of the loops, so care must be taken to use the proper syntax. 
- 
-With any loop, we need (at least one) looping variable, which the loop will use to analyze whether or not we've met our looping destination, or to perform another iteration. 
- 
-A for loop typically also has a defined starting point, a "keep-looping-while" condition, and a stepping equation. 
- 
-Here's a sample for() loop, in C, which will display the squares of each number, starting at 0, and stepping one at a time, for 8 total iterations: 
- 
-<code c> 
-int i = 0; 
- 
-for (i = 0; i < 8; i++) 
-{ 
-    fprintf(stdout, "loop #%d ... %d\n", (i+1), (i*i)); 
-} 
-</code> 
- 
-The output of this code, with the help of our loop should be: 
- 
-<cli> 
-loop #1 ... 0 
-loop #2 ... 1 
-loop #3 ... 4 
-loop #4 ... 9 
-loop #5 ... 16 
-loop #6 ... 25 
-loop #7 ... 36 
-loop #8 ... 49 
-</cli> 
- 
-Note how we can use our looping variable (**i**) within mathematical expressions to drive a process along... loops can be of enormous help in this way. 
- 
-And again, we shouldn't look at this as one step-- we need to see there are 8 discrete, distinct steps happening here (when i is 0, when i is 1, when i is 2, ... up until (and including) when i is 7). 
- 
-The loop exits once **i** reaches a value of 8, because our loop determinant condition states as long as **i** is **less than** **8**, continue to loop. Once **i** becomes **8**, our looping condition has been satisfied, and the loop will no longer iterate. 
- 
-The stepping (that third) field is a mathematical expression indicating how we wish for **i** to progress from its starting state (of being equal to 0) to satisfying the loop's iterating condition (no longer being less than 8). 
- 
-**i++** is a shortcut we can use in C; the longhand (and likely more familiar) equivalent is: **i = i + 1** 
- 
-====while() loops==== 
-A **while()** loop isn't as specific about starting and stepping values, really only caring about what condition needs to be met in order to exit the loop (keep looping while this condition is true). 
- 
-In actuality, anything we use a for loop for can be expressed as a while loop-- we merely have to ensure we provide the necessary loop variables and progressions within the loop. 
- 
-That same loop above, expressed as a while loop, could look like: 
- 
-<code c> 
-int i = 0; 
- 
-while (i < 8) 
-{ 
-    fprintf(stdout, "loop #%d ... %d\n", (i+1), (i*i)); 
-    i = i + 1;   // I could have used "i++;" here 
-} 
-</code> 
- 
-The output of this code should be identical, even though we used a different loop to accomplish the task (try them both out and confirm!) 
- 
-**while()** loops, like **for()** loops, will run 0 or more times; if the conditions enabling the loop to occur are not initially met, they will not run... if met, they will continue to iterate until their looping conditions are met. 
- 
-It is possible to introduce a certain kind of **logical error** into your programs using loops-- what is known as an "infinite loop"; this is basically where you erroneously provide incorrect conditions to the particular loop used, allowing it to start running, but never arriving at its conclusion, thereby iterating forever. 
- 
-Another common **logical error** that loops will allow us to encounter will be the "off by one" error-- where the conditions we pose to the loop are incorrect, and the loop runs one magnitude more or less than we had intended. Again, proper debugging of our code will resolve this situation. 
- 
-====do-while loops==== 
-The third commonly recognized looping structure in C, the do-while loop is identical to the while() (and therefore also the for()) loop, only it differs in where it checks the looping condition: where **for()** and **while()** are "top-driven" loops (ie the test for loop continuance occurs at the top of the loop, **before** running the code in the loop body), the **do-while** is a "bottom-driven" loop (ie the test for loop continuance occurs at the bottom of the loop). 
- 
-The placement of this test determines the minimal number of times a loop can run. 
- 
-In the case of the for()/while() loops, because the test is at the top- if the looping conditions are not met, the loop may not run at all. It is for this reason why these loops can run "0 or more times" 
- 
-For the do-while loop, because the test occurs at the bottom, the body of the loop (one full iteration) is run before the test is encountered. So even if the conditions for looping are not met, a do-while will run "1 or more times". 
- 
-That may seem like a minor, and possibly annoying, difference, but in nuanced algorithm design, such distinctions can drastically change the layout of your code, potentially being the difference between beautifully elegant-looking solutions and those which appear slightly more hackish. They can BOTH be used to solve the same problems, it is merely the nature of how we choose express the solution that should make one more preferable over the other in any given moment. 
- 
-I encourage you to intentionally try your hand at taking your completed programs and implementing other versions that utilize the other types of loops you haven't utilized. This way, you can get more familiar with how to structure your solutions and express them. You will find you tend to think in a certain way (from experience, we seem to get in the habit of thinking "top-driven", and as we're unsure, we tend to exert far more of a need to control the situation, so we tend to want to use **for** loops for everything-- but practicing the others will free your mind to craft more elegant and efficient solutions; but only if you take the time to play and explore these possibilities). 
- 
-So, expressing that same program in the form of a do-while loop (note the changes from the while): 
- 
-<code c> 
-int i = 0; 
- 
-do 
-{ 
-    fprintf(stdout, "loop #%d ... %d\n", (i+1), (i*i)); 
-    i = i + 1;  // again, we could just as easily use "i++;" here 
-} while(i < 8); 
-</code> 
- 
-In this case, the 0 or more vs. 1 or more minimal iterations wasn't important; the difference is purely syntactical. 
- 
-With the do-while loop, we start the loop with a **do** statement. 
- 
-Also, the do-while is the only one of our loops which NEEDS a terminating semi-colon (**;**).. please take note of this. 
  
 =====Execution===== =====Execution=====
Line 511: Line 426:
  
 <cli> <cli>
-lab46:~/src/DESIG/pnc0$ ./primereg 24 1+lab46:~/src/discrete/pnc1$ ./primeregoa 24 1
 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89  2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 
   0.0001   0.0001
-lab46:~/src/DESIG/pnc0+lab46:~/src/discrete/pnc1
 </cli> </cli>
  
Line 523: Line 438:
  
 <cli> <cli>
-lab46:~/src/DESIG/pnc0$ ./primerego 32 1 0 +lab46:~/src/discrete/pnc1$ ./primeregbmo 32 1 0 
-./primebrute: invalid lower bound +./primeregbmo: invalid lower bound 
-lab46:~/src/DESIG/pnc0+lab46:~/src/discrete/pnc1
 </cli> </cli>
  
Line 534: Line 449:
  
 <cli> <cli>
-lab46:~/src/cprog/pnc0$ ./primeregs 128 1 7 23+lab46:~/src/discrete/pnc1$ ./primeregos 128 1 7 23
 7 11 13 17 19 23 7 11 13 17 19 23
   0.0001   0.0001
-lab46:~/src/cprog/pnc0+lab46:~/src/discrete/pnc1
 </cli> </cli>
  
Line 543: Line 458:
  
 =====Check Results===== =====Check Results=====
-If you'd like to compare your implementations, I rigged up a Makefile checking rule called "**make check**" which you can run to get a nice side-by-side comparison of your implementations.+If you'd like to compare your implementations, I rigged up a Makefile checking rule called "**make checkqty**" and "**make checkrange**" which you can run to get a nice side-by-side runtime comparisons of your implementations.
  
 In order to work, you **MUST** be in the directory where your pnc0 binaries reside, and must be named as such (which occurs if you ran **make** to compile them). In order to work, you **MUST** be in the directory where your pnc0 binaries reside, and must be named as such (which occurs if you ran **make** to compile them).
  
-For instance (running on my implementation of the pnc0 programs, some output omitted to keep the surprise alive):+====check qty==== 
 +For instance (running on my implementation of the pnc1 programs, some output omitted to keep the surprise alive)
 + 
 +<cli> 
 +lab46:~/src/discrete/pnc1$ make checkqty 
 +========================================================================================================================= 
 +      qty   regmo  regbmo   regms   regma   regos   regoa  regmos  regmoa  regbms  regbma  regbos regbmos  regboa regbmoa 
 +========================================================================================================================= 
 +       32  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
 +       64  0.0002  0.0002  0.0001  0.0002  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
 +      128  0.0005  0.0003  0.0002  0.0001  0.0002  0.0002  0.0002  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
 +      256  0.0022  0.0011  0.0003  0.0003  0.0003  0.0004  0.0003  0.0003  0.0003  0.0003  0.0003  0.0002  0.0002  0.0002 
 +      512  0.0096  0.0039  0.0009  0.0008  0.0009  0.0008  0.0006  0.0006  0.0006  0.0006  0.0005  0.0004  0.0004  0.0004 
 +     1024  0.0444  0.0159  0.0025  0.0025  0.0023  0.0021  0.0016  0.0015  0.0015  0.0014  0.0011  0.0010  0.0010  0.0009 
 +     2048  0.2061  0.0676  0.0076  0.0075  0.0065  0.0062  0.0044  0.0042  0.0040  0.0038  0.0028  0.0025  0.0023  0.0022 
 +     4096  0.9626  0.2905  0.0236  0.0231  0.0194  0.0188  0.0129  0.0125  0.0108  0.0104  0.0069  0.0063  0.0061  0.0059 
 +     8192  5.4731  1.5194  0.0812  0.0805  0.0646  0.0633  0.0431  0.0424  0.0334  0.0321  0.0197  0.0185  0.0182  0.0175 
 +... 
 +   262144  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------ 
 +========================================================================================================================= 
 + verify:     OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK 
 +========================================================================================================================= 
 +lab46:~/src/discrete/pnc1$  
 +</cli> 
 + 
 +====check range==== 
 +Or check range runtimes:
  
 <cli> <cli>
-lab46:~/src/discrete/pnc0$ make check +lab46:~/src/discrete/pnc1$ make checkrange 
-========================================================================================= +========================================================================================================================= 
-      qty     reg    regm    rego    regb   regbm   regbo    regs    rega   regbs   regba +    range   regmo  regbmo   regms   regma   regos   regoa  regmos  regmoa  regbms  regbma  regbos regbmos  regboa regbmoa 
-========================================================================================= +========================================================================================================================= 
-       32  0.0002  0.0001  0.0001  0.0002  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 +       32  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
-       64  0.0006  0.0003  0.0002  0.0002  0.0002  0.0001  0.0001  0.0002  0.0002  0.0001 +       64  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
-      128  0.0028  0.0010  0.0008  0.0006  0.0006  0.0003  0.0004  0.0003  0.0002  0.0002 +      128  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
-      256  0.0123  0.0041  0.0031  0.0020  0.0019  0.0010  0.0009  0.0008  0.0004  0.0003 +      256  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001  0.0001 
-      512  0.0574  0.0188  0.0144  0.0077  0.0077  0.0040  0.0025  0.0026  0.0008  0.0007 +      512  0.0003  0.0002  0.0002  0.0001  0.0002  0.0001  0.0001  0.0001  0.0001  0.0001  0.0002  0.0001  0.0001  0.0001 
-     1024  0.2690  0.0880  0.0665  0.0320  0.0312  0.0161  0.0077  0.0080  0.0019  0.0016+     1024  0.0010  0.0005  0.0002  0.0002  0.0002  0.0002  0.0002  0.0002  0.0002  0.0002  0.0002  0.0002  0.0001  0.0002 
 +     2048  0.0033  0.0015  0.0004  0.0004  0.0004  0.0004  0.0003  0.0003  0.0003  0.0003  0.0003  0.0003  0.0003  0.0003 
 +     4096  0.0118  0.0047  0.0010  0.0010  0.0009  0.0009  0.0007  0.0007  0.0006  0.0006  0.0006  0.0005  0.0005  0.0005 
 +     8192  0.0448  0.0161  0.0026  0.0025  0.0023  0.0022  0.0016  0.0015  0.0015  0.0015  0.0011  0.0011  0.0010  0.0009 
 +    16384  0.1742  0.0576  0.0067  0.0067  0.0058  0.0055  0.0038  0.0046  0.0036  0.0034  0.0024  0.0022  0.0021  0.0020 
 +    32768  0.6861  0.2096  0.0186  0.0181  0.0152  0.0147  0.0101  0.0099  0.0086  0.0083  0.0055  0.0051  0.0049  0.0048 
 +    65536  2.7211  0.7758  0.0503  0.0500  0.0410  0.0397  0.0270  0.0268  0.0215  0.0208  0.0132  0.0123  0.0119  0.0117
 ... ...
-   262144  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------ +  4194304  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------  ------ 
-========================================================================================= +========================================================================================================================= 
- verify:     OK      OK      OK      OK      OK      OK      OK      OK      OK      OK + verify:     OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK 
-========================================================================================= +========================================================================================================================= 
-lab46:~/src/discrete/pnc0+lab46:~/src/discrete/pnc1
 </cli> </cli>
  
Line 572: Line 519:
 If you don't feel like waiting, simply hit **CTRL-c** (maybe a couple of times) and the script will terminate. If you don't feel like waiting, simply hit **CTRL-c** (maybe a couple of times) and the script will terminate.
  
 +====Verification====
 I also include a validation check- to ensure your prime programs are actually producing the correct list of prime numbers. If the check is successful, you will see "OK" displayed beneath in the appropriate column; if unsuccessful, you will see "MISMATCH". I also include a validation check- to ensure your prime programs are actually producing the correct list of prime numbers. If the check is successful, you will see "OK" displayed beneath in the appropriate column; if unsuccessful, you will see "MISMATCH".
  
 +====Full Verification Compliance====
 +There's also a more rigorous verification step you can take, which runs your programs through a series to tests to see if they conform to project specifications:
 +
 +<cli>
 +lab46:~/src/discrete/pnc1$ make verifyall
 +=========================================================================================================================
 +            regmo  regbmo   regms   regma   regos   regoa  regmos  regmoa  regbms  regbma  regbos regbmos  regboa regbmoa
 +=========================================================================================================================
 + qtynorm:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + qtypart:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + rngnorm:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + rngpart:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +    coop:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +   coop2:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +   coop3:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +  noargs:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + invargs:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +  invqty:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + invnary:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +  invlow:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 + invhigh:    OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK      OK
 +=========================================================================================================================
 +lab46:~/src/discrete/pnc1$ 
 +</cli>
 +
 +===verifyall tests===
 +The "**verifyall**" is an industrial grade verification; there are 13 specific tests performed, they are:
 +  * **qtynorm**: a normal quantity run (2-max)
 +    * **./primealg 2048 1 2 0**
 +  * **qtypart**: an offset quantity run (24-max)
 +    * **./primealg 2048 1 24 0**
 +  * **rngnorm**: a normal range run (2-max)
 +    * **./primealg 0 1 2 2048**
 +  * **rngpart**: an offset range run (24-max)
 +    * **./primealg 0 1 24 2048**
 +  * **coop**: both qty and upper bounds set (q: 2048, ub: 8192)
 +    * **./primealg 2048 1 2 8192**
 +  * **coop2**: both qty and upper bounds set (q: 512, ub: 8192)
 +    * **./primealg 512 1 2 8192**
 +  * **coop3**: both qty and upper bounds set, offset start (24-max, q: 2048, ub: 8192)
 +    * **./primealg 2048 1 24 8192**
 +  * **noargs**:  no arguments provided on command line (invokes error message)
 +    * **./primealg**
 +  * **invargs**: insufficient number of arguments provided (invokes error)
 +    * **./primealg 128**
 +  * **invqty**: invalid value for quantity argument given (invokes error)
 +    * **./primealg -2 1**
 +  * **invnary**: invalid value given for n-ary (invokes error)
 +    * **./primealg 128 2**
 +  * **invlow**: invalid value given for lower bound (invokes error)
 +    * **./primealg 128 1 1**
 +  * **invhigh**: invalid value given for upper bound (invokes error)
 +    * **./primealg 128 1 32 24**
 +
 +If you'd actually to see the output your program's output is being tested against, that can be found in the **/usr/local/etc** directory in the file **primeTEST**, where "TEST" is the name of the verify test mentioned above.
 +
 +For example, if you wanted to see the intended output of the **invnary** test, that would be found in:
 +
 +  * **/usr/local/etc/primeinvnary**
 +
 +You could easily run your program with the stated arguments for the test, then use **cat** to display the test results and do a visual comparison.
 +
 +====In general====
 Analyze the times you see... do they make sense, especially when comparing the algorithm used and the quantity being processed? These are related to some very important core Computer Science considerations we need to be increasingly mindful of as we design our programs and implement our solutions. Algorithmic complexity and algorithmic efficiency will be common themes in all we do. Analyze the times you see... do they make sense, especially when comparing the algorithm used and the quantity being processed? These are related to some very important core Computer Science considerations we need to be increasingly mindful of as we design our programs and implement our solutions. Algorithmic complexity and algorithmic efficiency will be common themes in all we do.
  
Line 583: Line 594:
   * Code must be nicely and consistently indented (you may use the **indent** tool)   * Code must be nicely and consistently indented (you may use the **indent** tool)
   * Code must utilize the algorithm(s) presented above:   * Code must utilize the algorithm(s) presented above:
-    * **primereg.c** must do the raw, unoptimized brute force method +    * **primeregmo.c**: map + odd traversal optimizations 
-    * **primeregb.c** adds in the break on composite optimization +    * **primeregms.c**: map traversal + sqrt() trick 
-    * **primeregm.c** implements the map traversal +    * **primeregma.c**map treversal + approximated square root trick 
-    * **primerego.c** implements odds-only checking +    * **primeregos.c**: odd traversal + sqrt() trick 
-    * **primeregs.c** implements the sqrt() trick +    * **primeregoa.c**: odd traversal + approximated square root trick 
-    * **primerega.c** implements square root trick by approximating square root +    * **primeregbmo.c**: break + map + odd traversal 
-    * **primeregbm.c** implements "break on composite" AND "map" optimizations +    * **primeregbms.c**: break + map + sqrt() trick 
-    * **primeregbo.c** implements "break on composite" AND "odds-only checking" optimizations +    * **primeregbma.c**: break + map + approximated square root trick 
-    * **primeregbs.c** implements "break on composite" AND "sqrt()" optimizations +    * **primeregbos.c**: break + odd + sqrt() trick 
-    * **primeregba.c** implements "break on composite" AND "approximated square root" optimizations+    * **primeregboa.c**: break + odd + approximated square root trick 
 +    * **primeregmos.c**map + odd traversal + sqrt() trick 
 +    * **primeregmoa.c**: map + odd traversal + approximated square root trick 
 +    * **primeregbmos.c**break + map + odd + sqrt() trick 
 +    * **primeregbmoa.c**break + map + odd + approximated square root trick
   * Code must be commented   * Code must be commented
     * have a properly filled-out comment banner at the top     * have a properly filled-out comment banner at the top
Line 604: Line 619:
  
 <cli> <cli>
-lab46:~/src/discrete/pnc0$ make submit +lab46:~/src/discrete/pnc1$ make submit 
-removed ‘primerega’ +Delinking ... 
-removed ‘primeregba’ +removed ‘primerega.c’ 
-removed ‘primeregb’ +removed ‘primeregba.c’ 
-removed ‘primeregbm’ +removed ‘primeregb.c’ 
-removed ‘primeregbo’ +removed ‘primeregbm.c’ 
-removed ‘primeregbs’ +removed ‘primeregbo.c’ 
-removed ‘primereg’ +removed ‘primeregbs.c’ 
-removed ‘primeregm’ +removed ‘primereg.c’ 
-removed ‘primerego’ +removed ‘primeregm.c’ 
-removed ‘primeregs’+removed ‘primerego.c’ 
 +removed ‘primeregs.c’ 
 +removed ‘primeregbma’ 
 +removed ‘primeregbmoa’ 
 +removed ‘primeregbmo’ 
 +removed ‘primeregbmos’ 
 +removed ‘primeregbms’ 
 +removed ‘primeregboa’ 
 +removed ‘primeregbos’ 
 +removed ‘primeregma’ 
 +removed ‘primeregmoa’ 
 +removed ‘primeregmo’ 
 +removed ‘primeregmos’ 
 +removed ‘primeregms’ 
 +removed ‘primeregoa’ 
 +removed ‘primeregos
 removed ‘errors’ removed ‘errors’
  
 Project backup process commencing Project backup process commencing
  
-Taking snapshot of current project (pnc0)      ... OK +Taking snapshot of current project (pnc1)      ... OK 
-Compressing snapshot of pnc0 project archive   ... OK +Compressing snapshot of pnc1 project archive   ... OK 
-Setting secure permissions on pnc0 archive     ... OK+Setting secure permissions on pnc1 archive     ... OK
  
 Project backup process complete Project backup process complete
  
-Submitting discrete project "pnc0": +Submitting discrete project "pnc1": 
-    -> ../pnc0-20170712-16.tar.gz(OK)+    -> ../pnc1-20170907-16.tar.gz(OK)
  
 SUCCESSFULLY SUBMITTED SUCCESSFULLY SUBMITTED
Line 633: Line 663:
 You should get that final "SUCCESSFULLY SUBMITTED" with no error messages occurring. If not, check for typos and or locational mismatches. You should get that final "SUCCESSFULLY SUBMITTED" with no error messages occurring. If not, check for typos and or locational mismatches.
  
-What I will be looking for:+====Evaluation Criteria==== 
 +Grand total points:
  
 <code> <code>
-260:pnc0:final tally of results (260/260) +546:pnc1:final tally of results (546/546)
-*:pnc0:primereg.c performs proper argument checking [2/2] +
-*:pnc0:primereg.c no negative compiler messages [2/2] +
-*:pnc0:primereg.c implements only specified algorithm [6/6] +
-*:pnc0:primereg.c consistent indentation and comments [4/4] +
-*:pnc0:primereg.c data and output conform to specifications [6/6] +
-*:pnc0:primereg.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregb.c performs proper argument checking [2/2] +
-*:pnc0:primeregb.c no negative compiler messages [2/2] +
-*:pnc0:primeregb.c implements only specified algorithm [6/6] +
-*:pnc0:primeregb.c consistent indentation and comments [4/4] +
-*:pnc0:primeregb.c data and output conform to specifications [6/6] +
-*:pnc0:primeregb.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregm.c performs proper argument checking [2/2] +
-*:pnc0:primeregm.c no negative compiler messages [2/2] +
-*:pnc0:primeregm.c implements only specified algorithm [6/6] +
-*:pnc0:primeregm.c consistent indentation and comments [4/4] +
-*:pnc0:primeregm.c data and output conform to specifications [6/6] +
-*:pnc0:primeregm.c make check runtime tests succeed [6/6] +
-*:pnc0:primerego.c performs proper argument checking [2/2] +
-*:pnc0:primerego.c no negative compiler messages [2/2] +
-*:pnc0:primerego.c implements only specified algorithm [6/6] +
-*:pnc0:primerego.c consistent indentation and comments [4/4] +
-*:pnc0:primerego.c data and output conform to specifications [6/6] +
-*:pnc0:primerego.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregs.c performs proper argument checking [2/2] +
-*:pnc0:primeregs.c no negative compiler messages [2/2] +
-*:pnc0:primeregs.c implements only specified algorithm [6/6] +
-*:pnc0:primeregs.c consistent indentation and comments [4/4] +
-*:pnc0:primeregs.c data and output conform to specifications [6/6] +
-*:pnc0:primeregs.c make check runtime tests succeed [6/6] +
-*:pnc0:primerega.c performs proper argument checking [2/2] +
-*:pnc0:primerega.c no negative compiler messages [2/2] +
-*:pnc0:primerega.c implements only specified algorithm [6/6] +
-*:pnc0:primerega.c consistent indentation and comments [4/4] +
-*:pnc0:primerega.c data and output conform to specifications [6/6] +
-*:pnc0:primerega.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregbm.c performs proper argument checking [2/2] +
-*:pnc0:primeregbm.c no negative compiler messages [2/2] +
-*:pnc0:primeregbm.c implements only specified algorithm [6/6] +
-*:pnc0:primeregbm.c consistent indentation and comments [4/4] +
-*:pnc0:primeregbm.c data and output conform to specifications [6/6] +
-*:pnc0:primeregbm.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregbo.c performs proper argument checking [2/2] +
-*:pnc0:primeregbo.c no negative compiler messages [2/2] +
-*:pnc0:primeregbo.c implements only specified algorithm [6/6] +
-*:pnc0:primeregbo.c consistent indentation and comments [4/4] +
-*:pnc0:primeregbo.c data and output conform to specifications [6/6] +
-*:pnc0:primeregbo.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregbs.c performs proper argument checking [2/2] +
-*:pnc0:primeregbs.c no negative compiler messages [2/2] +
-*:pnc0:primeregbs.c implements only specified algorithm [6/6] +
-*:pnc0:primeregbs.c consistent indentation and comments [4/4] +
-*:pnc0:primeregbs.c data and output conform to specifications [6/6] +
-*:pnc0:primeregbs.c make check runtime tests succeed [6/6] +
-*:pnc0:primeregba.c performs proper argument checking [2/2] +
-*:pnc0:primeregba.c no negative compiler messages [2/2] +
-*:pnc0:primeregba.c implements only specified algorithm [6/6] +
-*:pnc0:primeregba.c consistent indentation and comments [4/4] +
-*:pnc0:primeregba.c data and output conform to specifications [6/6] +
-*:pnc0:primeregba.c make check runtime tests succeed [6/6]+
 </code> </code>
 +
 +What I will be looking for (for each file):
 +
 +<code>
 +*:pnc1:primeALGO.c compiles cleanly, no compiler messages [3/3]
 +*:pnc1:primeALGO.c implements only specified algorithm [6/6]
 +*:pnc1:primeALGO.c consistent indentation throughout code [3/3]
 +*:pnc1:primeALGO.c relevant comments throughout code [3/3]
 +*:pnc1:primeALGO.c code conforms to project specifications [3/3]
 +*:pnc1:primeALGO.c runtime output conforms to specifications [4/4]
 +*:pnc1:primeALGO.c make checkqty test times within reason [2/2]
 +*:pnc1:primeALGO.c make checkrange test times within reason [2/2]
 +*:pnc1:primeALGO.c make verifyall tests succeed [13/13]
 +</code>
 +
 +As the optimizations improve upon others, some evaluations will be based upon differences between a baseline (in some cases, primereg) and the optimization.
haas/fall2017/discrete/projects/pnc1.1499955976.txt.gz · Last modified: 2017/07/13 14:26 by wedge