This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
haas:fall2017:cprog:projects:pnc0 [2017/02/16 21:14] – external edit 127.0.0.1 | haas:fall2017:cprog:projects:pnc0 [2017/10/15 20:51] (current) – [Evaluation Criteria] wedge | ||
---|---|---|---|
Line 3: | Line 3: | ||
< | < | ||
</ | </ | ||
- | |||
- | ~~TOC~~ | ||
======Project: | ======Project: | ||
+ | |||
+ | =====Errata===== | ||
+ | With any increasingly complex piece of code or environment, | ||
+ | |||
+ | Any typos, bugs, or other updates/ | ||
+ | |||
+ | ====Revision List==== | ||
+ | |||
+ | * revision #: < | ||
+ | |||
+ | Some changes may involve updates being made available to the project, in which case you'll be prompted with such notification and can run the available updating commands to synchronize your copy of the project with the changes. | ||
=====Objective===== | =====Objective===== | ||
Line 12: | Line 21: | ||
=====Background===== | =====Background===== | ||
- | In mathematics, | + | In mathematics, |
- | The number **6** is a **composite** | + | The number **6** is a **composite** |
- | The number **17** is a **prime** number, as no numbers other than 1 and 17 can be evenly divided. | + | The number **17**, however, |
=====Calculating the primality of a number===== | =====Calculating the primality of a number===== | ||
Line 23: | Line 32: | ||
This process incurs a considerable amount of processing overhead on the task, so much so that increasingly large values take ever-expanding amounts of time. Often, approaches to prime number calculation involve various algorithms, which offer various benefits (less time) and drawback (more complex code). | This process incurs a considerable amount of processing overhead on the task, so much so that increasingly large values take ever-expanding amounts of time. Often, approaches to prime number calculation involve various algorithms, which offer various benefits (less time) and drawback (more complex code). | ||
- | Your task for this project is to implement a prime number program using the straightforward, | + | Your task for this project is to implement a prime number program using the straightforward, |
+ | |||
+ | =====Main algorithm: brute force (primereg)===== | ||
+ | The brute force approach is the simplest to implement (although at some cost). | ||
- | ====brute force==== | + | As we will be looking |
- | The brute force approach is the simplest | + | |
- | To perform | + | To perform |
- | Checking the remainder of a division indicates whether or not a division was clean (having 0 remainder indicates such a state). | + | Checking the **remainder** of a division indicates whether or not a division was clean (having 0 remainder indicates such a state). |
For example, the number 11: | For example, the number 11: | ||
Line 57: | Line 68: | ||
119 % 6 = 5 (6 is not a factor of 119) | 119 % 6 = 5 (6 is not a factor of 119) | ||
119 % 7 = 0 (7 is a factor of 119) | 119 % 7 = 0 (7 is a factor of 119) | ||
+ | 119 % 8 = 7 | ||
+ | 119 % 9 = 2 | ||
+ | 119 % 10 = 9 | ||
+ | 119 % 11 = 9 | ||
+ | 119 % 12 = 11 | ||
+ | 119 % 13 = 2 | ||
+ | ... | ||
</ | </ | ||
- | Because 7 evenly | + | Because, during our range of testing every value from 2-118, we find that 7 evenly |
- | Even though you have identified the number as a composite, | + | Please NOTE: Even once a number |
- | ===algorithm=== | + | ====algorithm==== |
Some things to keep in mind on your implementation: | Some things to keep in mind on your implementation: | ||
- | * loops, | + | * you will want to use loops (no less than 2, no more than 2) for this program. |
- | * a nested loop makes the most sense. | + | * a nested loop makes the most sense: |
- | * you know the starting value and the terminating condition, so a clear starting and ending point. | + | * an outer loop that drives the progression of each sequential number to be tested |
+ | * an inner loop that tests that current number to see if it has any factors | ||
+ | * you know the starting value and the terminating condition, so you have a clear starting and ending point to work with. | ||
+ | * I do **NOT** want to see ambiguous, one-letter variables used in your implementation(s). Please use // | ||
+ | * Some good examples of variable names would be: | ||
+ | * **number**: | ||
+ | * **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/ | * let the loops drive the overall process. Identify prime/ | ||
- | * and remember, the baseline brute force algorithm may well identify a value as composite, but won't terminate the loop. The optimized brute force will act on the identification of a composite value by terminating the processing of additional values. | + | * and remember, the baseline brute force algorithm |
- | * your timing should start before the loop, 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 |
- | ====brute force optimization==== | + | |
- | The optimized version of brute force will make but one algorithmic change, and that takes place at the moment of identifying a number as composite. So, if we had our 119 example above, and discovered that 7 was a factor: | + | |
- | There is no further need to check the remaining values, as once we have proven | + | =====prime algorithm implementation===== |
+ | For simplicity, I have encoded important implementation information into the file name (and therefore resulting executable/ | ||
- | 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. | + | To break it down, all prime programs will be of the form: |
- | =====Program===== | + | * primeALG[O...] |
- | It is your task to write a brute-force prime number calculating program: | + | * where each and every program starts with " |
+ | | ||
+ | * and then is followed by 0 or more layered attributes describing the particular optimization that is applied (again, if any: **zero** or more). | ||
- | - **primebrute.c**: | + | Unless specified in the encoded name, your algorithm should only implement the algorithm and optimization(s) specified. |
- | - **primebruteopt.c**: for your slightly optimized brute force implementation | + | |
+ | That is, if your program to implement is **primereg**, | ||
+ | |||
+ | =====Programs===== | ||
+ | It is your task to write the following prime number variants: | ||
+ | |||
+ | - **primereg.c**: | ||
+ | |||
+ | ====Program Specifications==== | ||
Your program should: | Your program should: | ||
- | * obtain | + | * obtain |
- | * argv[1]: maximum | + | * check to make sure the user indeed supplied enough parameters, and exit with an error message if not. |
- | * this value should be a positive integer value; you can make the assumption that the user will always do the right thing. | + | * argv[1]: maximum |
- | * do NO algorithmic optimizations | + | * this value should be an integer value, greater than or equal to 0. |
- | * in the case of **primebruteopt**, perform only the short circuit | + | * if argv[1] is 0, disable the quantity check, and rely on provided lower and upper bounds |
- | * please take note in differences in run-time, contemplating the impact the two algorithms | + | * argv[2]: reserved for future compatibility; |
- | * start your stopwatch (see **timing** section below): | + | * argv[3]: **conditionally optional** lower bound (starting |
- | * perform the correct algorithm against the input | + | * if omitted, assume a lower bound of **2**. |
- | * display (to STDOUT) the prime numbers found in the range | + | * if you desired to specify an upper bound (argv[4]), you obviously MUST provide the lower bound argument under this scheme. |
- | * stop your stopwatch. Calculate the time that has transpired. | + | * argv[4]: **conditionally optional** upper bound (ending value). If provided, this is the ending |
- | * output the processing run-time to STDERR | + | * If doing a quantity run (argv[1] is NOT 0), this value isn't necessary. |
- | * your output **MUST** | + | * If doing a quantity run AND you specify an upper bound, whichever condition is achieved first dictates program termination. That is, upper bound could override quantity (if it is achieved before quantity), and quantity |
- | * as primes are being displayed, they are space-separated (first prime hugs the left margin), and when all said and done, a newline is issued. | + | * for each argument: you should |
- | * the timing information will be displayed in accordance to code I will provide (in the **timing** section). | + | * for insufficient quantity |
+ | * for invalid argv[1], display: **PROGRAM_NAME: | ||
+ | * for invalid argv[2], display: **PROGRAM_NAME: | ||
+ | * for invalid argv[3], display: **PROGRAM_NAME: | ||
+ | * if argv[3] is not needed, ignore | ||
+ | * for invalid argv[4], display: **PROGRAM_NAME: | ||
+ | * if argv[4] is not needed, ignore (no error displayed nor forced exit, as it is acceptable defined behavior). | ||
+ | * In these error messages, **PROGRAM_NAME** is the name of the program being run; this can be accessed as a string stored in **argv[0]**. | ||
+ | * implement ONLY the algorithm and optimization(s) specified in the program name. We are producing multiple data points for a broader performance comparison. | ||
+ | * please take note on differences in run-time, contemplating the impact the algorithm and optimization(s) | ||
+ | * immediately after argument processing: | ||
+ | * perform the correct algorithm | ||
+ | * each program is to have no fewer and no more than 2 loops in this prime processing section. | ||
+ | * display | ||
+ | * stop your stopwatch | ||
+ | * output the processing run-time to **STDERR** | ||
+ | * your output **MUST** | ||
+ | * as primes are being displayed, they are space-separated (first prime hugs the left margin), and when all said and done, a newline is issued | ||
+ | * the timing information will be displayed in accordance to code I will provide | ||
+ | |||
+ | =====Grabit Integration===== | ||
+ | I have made some skeleton files and a custom **Makefile** available for this project. Since we've amassed considerable experience manually compiling our files, it is time to start experiencing some of the other development tools that can automate or facilitate various processes. | ||
+ | |||
+ | I have written a tool, known as **grabit**, which will let you obtain the files I have put together for this project. To " | ||
+ | |||
+ | < | ||
+ | lab46: | ||
+ | make: Entering directory '/ | ||
+ | Commencing copy process for SEMESTER cprog project pnc0: | ||
+ | -> Creating project pnc0 directory tree ... OK | ||
+ | -> Copying pnc0 project files ... OK | ||
+ | -> Synchronizing pnc0 project revision level ... OK | ||
+ | -> Establishing sane file permissions for pnc0 ... OK | ||
+ | |||
+ | *** Copy COMPLETE! You may now go to the '/ | ||
+ | |||
+ | make: Leaving directory '/ | ||
+ | lab46: | ||
+ | lab46: | ||
+ | lab46: | ||
+ | Makefile | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | NOTE: You do NOT want to do this on a populated pnc0 project directory-- it will overwrite files. | ||
+ | |||
+ | And, of course, your basic compile and clean-up operations via the Makefile. | ||
+ | |||
+ | =====Makefile operations===== | ||
+ | Makefiles provide a build automation system for our programs, instructing the computer on how to compile files, so we don't have to constantly type compiler command-lines ourselves. I've also integration some other useful, value-added features that will help you with overall administration of the project. | ||
+ | |||
+ | Basic operation of the Makefile is invoked by running the command " | ||
+ | |||
+ | Additional options are available, and they are provided as an argument to the make command. You can see the available options by running " | ||
+ | |||
+ | < | ||
+ | lab46: | ||
+ | *******************[ C/C++ Programming pnc0 Project ]******************* | ||
+ | ** make - build everything | ||
+ | ** make showerrors | ||
+ | ** ** | ||
+ | ** make debug - build everything with debug symbols | ||
+ | ** make checkqty | ||
+ | ** make checkrange | ||
+ | ** ** | ||
+ | ** make verifyqty | ||
+ | ** make verifyrange | ||
+ | ** make verifyall | ||
+ | ** ** | ||
+ | ** make save - create a backup archive | ||
+ | ** make submit | ||
+ | ** ** | ||
+ | ** make update | ||
+ | ** make reupdate | ||
+ | ** make reupdate-all | ||
+ | ** ** | ||
+ | ** make clean - clean; remove all objects/ | ||
+ | ** make help - this information | ||
+ | ************************************************************************ | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | A description of some available commands include: | ||
+ | |||
+ | * **make**: compile everything | ||
+ | * any **warnings** or **errors** generated by the compiler will go into a file in the base directory of pnc0 in a file called **errors**; you can **cat** it to view the information. | ||
+ | * **make debug**: compile everything with debug support | ||
+ | * any **warnings** or **errors** generated by the compiler will be displayed to the screen as the programs compile. | ||
+ | * **make clean**: remove all binaries | ||
+ | * **make save**: make a backup of your current work | ||
+ | * **make submit**: archive and submit your project | ||
+ | |||
+ | The various " | ||
+ | |||
+ | The various " | ||
+ | Just another "nice thing" we deserve. | ||
=====Command-Line Arguments===== | =====Command-Line Arguments===== | ||
- | To automate our comparisons, | + | To automate our comparisons, |
====header files==== | ====header files==== | ||
Line 119: | Line 253: | ||
int main(int argc, char **argv) | int main(int argc, char **argv) | ||
</ | </ | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | * int argc: the count (an integer) of tokens given on the command line (program name + arguments) | ||
+ | * < | ||
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 124: | Line 263: | ||
* argv[0]: program invocation (path + program name) | * argv[0]: program invocation (path + program name) | ||
* argv[1]: our maximum / upper bound | * argv[1]: our maximum / upper bound | ||
+ | * argv[2]: reserved value, should still be provided and be a 1 for this project | ||
+ | * argv[3]: conditionally optional; represents lower bound | ||
+ | * argv[4]: conditionally optional; represents upper bound | ||
+ | |||
+ | Additionally, | ||
+ | |||
+ | ===example=== | ||
+ | For example, if we were to execute the **primereg** program: | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | We'd have: | ||
+ | |||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | * < | ||
+ | |||
+ | and let's not forget: | ||
+ | |||
+ | * argc: 5 | ||
+ | |||
+ | 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==== | ||
- | Although I'm not going to require extensive argument parsing or checking for this project, | + | While there are a number of checks |
<code c> | <code c> | ||
- | if (argc < 2) // if less than 2 arguments have been provided | + | if (argc < 3) // if less than 3 arguments |
{ | { | ||
- | fprintf(stderr, | + | fprintf(stderr, |
exit(1); | exit(1); | ||
} | } | ||
</ | </ | ||
+ | |||
+ | Since argv[3] (lower bound) and argv[4] (upper bound) are conditionally optional, it wouldn' | ||
====Grab and convert max==== | ====Grab and convert max==== | ||
- | Finally, we need to put the argument representing the maximum | + | Finally, we need to put the argument representing the maximum |
I'd recommend declaring a variable of type **int**. | I'd recommend declaring a variable of type **int**. | ||
Line 144: | Line 311: | ||
<code c> | <code c> | ||
- | max = atoi(argv[1]); | + | max = atoi (argv[1]); |
</ | </ | ||
Line 193: | Line 360: | ||
====Displaying the runtime==== | ====Displaying the runtime==== | ||
- | Once we have the starting and ending times, we can display this to STDERR. You'll want this line: | + | Once we have the starting and ending times, we can display this to the **timing** file pointer. You'll want this line: |
<code c> | <code c> | ||
- | fprintf(stderr, | + | fprintf(stderr, |
time_end.tv_sec-time_start.tv_sec+((time_end.tv_usec-time_start.tv_usec)/ | time_end.tv_sec-time_start.tv_sec+((time_end.tv_usec-time_start.tv_usec)/ | ||
</ | </ | ||
- | For clarity sake, that format specifier is "%10.6lf", where the " | + | For clarity sake, that format specifier is "%8.4lf", where the " |
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 " | ||
+ | |||
+ | 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, | ||
+ | |||
+ | A for loop typically also has a defined starting point, a " | ||
+ | |||
+ | 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, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 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 | ||
+ | </ | ||
+ | |||
+ | 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' | ||
+ | |||
+ | 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, | ||
+ | i = i + 1; // I could have used " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | The placement of this test determines the minimal number of times a loop can run. | ||
+ | |||
+ | In the case of the for()/ | ||
+ | |||
+ | 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' | ||
+ | |||
+ | 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, | ||
+ | i = i + 1; // again, we could just as easily use " | ||
+ | } while(i < 8); | ||
+ | </ | ||
+ | |||
+ | 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===== | ||
- | Your program output should be as follows (given the specified | + | |
+ | ====specified quantity==== | ||
+ | Your program output should be as follows (given the specified | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
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.000088 | + | 0.0001 |
lab46: | lab46: | ||
</ | </ | ||
The execution of the programs is short and simple- grab the parameters, do the processing, produce the output, and then terminate. | The execution of the programs is short and simple- grab the parameters, do the processing, produce the output, and then terminate. | ||
+ | |||
+ | ====invalid lower bound==== | ||
+ | Here's an example that should generate an error upon running (based on project specifications): | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | ./primereg: invalid lower bound | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | In this case, the program logic should have detected an invalid condition and bailed out before prime computations even began. No timing data is displayed, because exiting should occur even prior to that. | ||
+ | |||
+ | ====upper bound overriding quantity==== | ||
+ | As indicated above, there is potential interplay with an active quantity and upper bound values. Here is an example where upper bound overrides quantity, resulting in an early termination (ie upper bound is hit before quantity): | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | 7 11 13 17 19 23 | ||
+ | 0.0001 | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | Also for fun, I set the lower bound to 7, so you'll see computation starts at 7 (vs. the usual 2). | ||
=====Check Results===== | =====Check Results===== | ||
- | If you'd like to compare your implementations, | + | If you'd like to compare your implementations, |
- | In order to work, you **MUST** be in the directory where your **primebrute** and **primebruteopt** | + | 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 prime brute and primebruteopt): | + | ====check qty==== |
+ | For instance (running on my implementation of the pnc0 programs, some output omitted to keep the surprise alive): | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | =================================== | + | ================= |
- | | + | |
- | =================================== | + | ================= |
- | | + | 32 |
- | | + | |
- | 512 | + | |
- | | + | 256 |
- | 2048 0.019101 | + | 512 0.0574 |
- | | + | |
- | | + | ... |
- | 16384 | + | |
- | 32768 | + | ================= |
- | 65536 | + | |
- | | + | ================= |
- | | + | |
- | =================================== | + | |
- | | + | |
- | =================================== | + | |
lab46: | lab46: | ||
</ | </ | ||
- | For evaluation, each test is run 4 times, and the resulting time is averaged. During development, | + | ====check range==== |
+ | Or check range runtimes: | ||
- | If the runtime of a particular prime variant exceeds an upper threshold (likely to be set at 2 seconds), it will be omitted from further tests, and a series of dashes will instead appear in the output. | + | < |
+ | lab46: | ||
+ | ================= | ||
+ | range reg | ||
+ | ================= | ||
+ | | ||
+ | | ||
+ | 128 0.0002 | ||
+ | 256 0.0004 | ||
+ | 512 0.0015 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ... | ||
+ | 2097152 | ||
+ | ================= | ||
+ | | ||
+ | ================= | ||
+ | lab46: | ||
+ | </ | ||
- | If you don't feel like waiting, simply hit **CTRL-c** | + | If the runtime of a particular prime variant exceeds an upper runtime threshold (likely to be set at 1 second), it will be omitted from further tests, and a series of dashes |
+ | 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 " | 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 " | ||
+ | |||
+ | ====Full Verification Compliance==== | ||
+ | There' | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | ================= | ||
+ | reg | ||
+ | ================= | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | coop: OK | ||
+ | | ||
+ | | ||
+ | noargs: | ||
+ | | ||
+ | invqty: | ||
+ | | ||
+ | invlow: | ||
+ | | ||
+ | ================= | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | ===verifyall tests=== | ||
+ | The " | ||
+ | * **qtynorm**: | ||
+ | * **./ | ||
+ | * **qtypart**: | ||
+ | * **./ | ||
+ | * **rngnorm**: | ||
+ | * **./ | ||
+ | * **rngpart**: | ||
+ | * **./ | ||
+ | * **coop**: both qty and upper bounds set (q: 2048, ub: 8192) | ||
+ | * **./ | ||
+ | * **coop2**: both qty and upper bounds set (q: 512, ub: 8192) | ||
+ | * **./ | ||
+ | * **coop3**: both qty and upper bounds set, offset start (24-max, q: 2048, ub: 8192) | ||
+ | * **./ | ||
+ | * **noargs**: | ||
+ | * **./ | ||
+ | * **invargs**: | ||
+ | * **./ | ||
+ | * **invqty**: invalid value for quantity argument given (invokes error) | ||
+ | * **./ | ||
+ | * **invnary**: | ||
+ | * **./ | ||
+ | * **invlow**: invalid value given for lower bound (invokes error) | ||
+ | * **./ | ||
+ | * **invhigh**: | ||
+ | * **./ | ||
+ | |||
+ | If you'd actually to see the output your program' | ||
+ | |||
+ | For example, if you wanted to see the intended output of the **invnary** test, that would be found in: | ||
+ | |||
+ | * **/ | ||
+ | |||
+ | 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. | ||
+ | |||
=====Submission===== | =====Submission===== | ||
To successfully complete this project, the following criteria must be met: | To successfully complete this project, the following criteria must be met: | ||
Line 260: | Line 650: | ||
* 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: | ||
- | * **primebrute.c** must do the unoptimized brute force method | + | * **primereg.c** must do the raw, unoptimized brute force method |
- | * **primebruteopt.c** must do the brute force with the composite loop **break** | + | |
* 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 273: | Line 662: | ||
<cli> | <cli> | ||
- | $ submit | + | lab46: |
+ | removed ‘primereg’ | ||
+ | removed ‘errors’ | ||
+ | |||
+ | Project backup process commencing | ||
+ | |||
+ | Taking snapshot of current project (pnc0) ... OK | ||
+ | Compressing snapshot of pnc0 project archive | ||
+ | Setting secure permissions on pnc0 archive | ||
+ | |||
+ | Project backup process complete | ||
Submitting cprog project " | Submitting cprog project " | ||
- | -> primebrute.c(OK) | + | -> ../pnc0-20171018-16.tar.gz(OK) |
- | | + | |
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
</ | </ | ||
- | You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches. | + | You should get that final " |
- | What I will be looking for: | + | ====Evaluation Criteria==== |
+ | Grand total points: | ||
< | < | ||
- | 52:pnc0:final tally of results (52/52) | + | 78:pnc0:final tally of results (78/78) |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
</ | </ | ||
+ | |||
+ | What I will be looking for (for each file): | ||
+ | |||
+ | < | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | </ | ||
+ | |||
+ | As the optimizations improve upon others, some evaluations will be based upon differences between a baseline (in some cases, primereg) and the optimization. |