This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2017:discrete:projects:pnc1 [2017/07/14 21:15] – wedge | haas:fall2017:discrete:projects:pnc1 [2017/10/15 21:09] (current) – wedge | ||
---|---|---|---|
Line 4: | Line 4: | ||
</ | </ | ||
- | ~~TOC~~ | + | ======Project: |
- | + | ||
- | ======Project: | + | |
=====Errata===== | =====Errata===== | ||
Line 14: | Line 12: | ||
====Revision List==== | ====Revision List==== | ||
- | * revision 0: initial release (20170713) | + | |
* revision #: < | * revision #: < | ||
Line 20: | Line 18: | ||
=====Objective===== | =====Objective===== | ||
- | To continue | + | To continue |
=====Background===== | =====Background===== | ||
Line 36: | Line 34: | ||
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, | ||
- | =====Review of main algorithm: brute force (primereg)===== | + | =====Main algorithm: brute force (primereg)===== |
- | The brute force approach is the simplest to implement, although | + | The brute force approach is the simplest to implement |
+ | |||
+ | As we will be looking to do some time/ | ||
- | To review | + | To perform |
- | Checking the **remainder** of an integer | + | Checking the **remainder** of a division indicates whether or not a division was clean (having 0 remainder indicates such a state). |
- | For example, | + | For example, the number 11: |
< | < | ||
Line 78: | Line 78: | ||
Because, during our range of testing every value from 2-118, we find that 7 evenly divides into 119, it failed the test: 119 is **not** prime, but is instead a composite number. | Because, during our range of testing every value from 2-118, we find that 7 evenly divides into 119, it failed the test: 119 is **not** prime, but is instead a composite number. | ||
+ | |||
+ | Please NOTE: Even once a number is identified as composite, your **primereg** MUST **CONTINUE** evaluating the remainder of the values (up to 119-1, or 118). It might seem pointless (and it is for a production program), but I want you to see the performance implications this creates. | ||
====algorithm==== | ====algorithm==== | ||
Line 100: | Line 102: | ||
* 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. | * 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/ | ||
- | | + | |
- | * your timing should start before the loop (just AFTER argument processing), | + | * your timing should start before the loop (just AFTER argument processing), |
+ | * 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 124: | Line 127: | ||
That is, if your program to implement is **primerego**, | That is, if your program to implement is **primerego**, | ||
- | |||
- | On the other hand, if your program to implement is **primeregbms**, | ||
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. | 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. | ||
- | 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: | ||
+ | |||
+ | Comments should be describing what is going on in your code. | ||
+ | |||
+ | With projects like this, often relying on a common base, comments become even more important, as they allow me to see specifically what is changed or unique about one variant over the other. | ||
+ | |||
+ | As such, when evaluating the project, | ||
+ | |||
+ | And notice I said the " | ||
+ | |||
+ | * WHY is that important to the process? | ||
+ | * HOW does it impact the efficiency | ||
+ | |||
+ | 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 any) on the requirements for that variant. | ||
+ | |||
+ | Just like if you can't do it by hand you have no business trying | ||
=====Programs===== | =====Programs===== | ||
+ | It is your task to write the following prime number variants: | ||
- | Those variants to implement are: | ||
* the remainder of the viable double optimization combinations: | * the remainder of the viable double optimization combinations: | ||
* **primeregmo.c**: | * **primeregmo.c**: | ||
Line 151: | Line 168: | ||
* **primeregbmos.c**: | * **primeregbmos.c**: | ||
* **primeregbmoa.c**: | * **primeregbmoa.c**: | ||
- | |||
- | You should, if you haven' | ||
====Program Specifications==== | ====Program Specifications==== | ||
Line 183: | Line 198: | ||
* each program is to have no fewer and no more than 2 loops in this prime processing section. | * each program is to have no fewer and no more than 2 loops in this prime processing section. | ||
* in each program, you are not allowed to use a given loop type (for(), while(), do-while()) more than once! | * in each program, you are not allowed to use a given loop type (for(), while(), do-while()) more than once! | ||
- | * utilize meaningful variable names (I do not want to see things like **a**, **i**, **n**, **x** being used which have no meaningful bearing on the role they serve). | ||
* display identified primes (space-separated) to a file pointer called **primelist** | * display identified primes (space-separated) to a file pointer called **primelist** | ||
* stop your stopwatch immediately following your prime processing loops (and terminating newline display to **primelist**). Calculate the time that has transpired (ending time minus starting time). | * stop your stopwatch immediately following your prime processing loops (and terminating newline display to **primelist**). Calculate the time that has transpired (ending time minus starting time). | ||
Line 195: | Line 209: | ||
To " | To " | ||
- | |||
- | NOTE: You will **NEED** to specify the semester as indicated as the semester in question has not yet started. | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | make: Entering directory '/ | + | make: Entering directory '/ |
- | Commencing copy process for fall2017 | + | Commencing copy process for SEMESTER |
-> Creating project pnc1 directory tree ... OK | -> Creating project pnc1 directory tree ... OK | ||
-> Copying pnc1 project files ... OK | -> Copying pnc1 project files ... OK | ||
Line 209: | Line 221: | ||
*** Copy COMPLETE! You may now go to the '/ | *** Copy COMPLETE! You may now go to the '/ | ||
- | make: Leaving directory '/ | + | make: Leaving directory '/ |
lab46: | lab46: | ||
lab46: | lab46: | ||
Line 268: | Line 280: | ||
The various " | The various " | ||
- | |||
- | The " | ||
- | * 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: | ||
- | * ./primealg 512 1 2 8192 | ||
- | * coop3: | ||
- | * ./primealg 2048 1 24 8192 | ||
- | * noargs: | ||
- | * ./primealg | ||
- | * invargs: insufficient number of arguments provided (invokes error) | ||
- | * ./primealg 128 | ||
- | * invqty: | ||
- | * ./primealg -2 1 | ||
- | * invnary: invalid value given for n-ary (invokes error) | ||
- | * ./primealg 128 2 | ||
- | * invlow: | ||
- | * ./primealg 128 1 1 | ||
- | * invhigh: invalid value given for upper bound (invokes error) | ||
- | * ./primealg 128 1 32 24 | ||
Just another "nice thing" we deserve. | 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 317: | Line 302: | ||
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 325: | 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, | ||
+ | |||
+ | ===example=== | ||
+ | For example, if we were to execute the **primeregbms** 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==== | ||
Line 413: | Line 426: | ||
<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.0001 | 0.0001 | ||
Line 425: | Line 438: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | ./primeregos: invalid lower bound | + | ./primeregbmo: invalid lower bound |
lab46: | lab46: | ||
</ | </ | ||
Line 436: | Line 449: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
7 11 13 17 19 23 | 7 11 13 17 19 23 | ||
0.0001 | 0.0001 | ||
- | lab46: | + | lab46: |
</ | </ | ||
Line 450: | Line 463: | ||
====check qty==== | ====check qty==== | ||
+ | For instance (running on my implementation of the pnc1 programs, some output omitted to keep the surprise alive): | ||
+ | |||
<cli> | <cli> | ||
+ | lab46: | ||
========================================================================================================================= | ========================================================================================================================= | ||
qty | qty | ||
========================================================================================================================= | ========================================================================================================================= | ||
| | ||
- | | + | |
- | 128 0.0005 | + | 128 0.0005 |
- | 256 0.0021 | + | 256 0.0022 |
- | 512 0.0096 | + | 512 0.0096 |
- | | + | |
+ | | ||
+ | | ||
+ | | ||
... | ... | ||
| | ||
Line 465: | Line 484: | ||
| | ||
========================================================================================================================= | ========================================================================================================================= | ||
+ | lab46: | ||
</ | </ | ||
- | |||
- | When the runtime of a particular prime variant exceeds an upper threshold (1 second), it will be omitted from further tests, and a series of dashes will instead appear in the output. | ||
- | |||
- | If you don't feel like waiting, simply hit **CTRL-c** and the script will terminate. | ||
====check range==== | ====check range==== | ||
- | <cli> | + | Or check range runtimes: |
+ | <cli> | ||
+ | lab46: | ||
+ | ========================================================================================================================= | ||
+ | range | ||
+ | ========================================================================================================================= | ||
+ | | ||
+ | | ||
+ | 128 0.0001 | ||
+ | 256 0.0001 | ||
+ | 512 0.0003 | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | 16384 0.1742 | ||
+ | 32768 0.6861 | ||
+ | 65536 2.7211 | ||
+ | ... | ||
+ | 4194304 | ||
+ | ========================================================================================================================= | ||
+ | | ||
+ | ========================================================================================================================= | ||
+ | lab46: | ||
</ | </ | ||
+ | |||
+ | 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 will instead appear in the output. | ||
+ | |||
+ | If you don't feel like waiting, simply hit **CTRL-c** (maybe a couple of times) and the script will terminate. | ||
====Verification==== | ====Verification==== | ||
Line 484: | Line 527: | ||
<cli> | <cli> | ||
lab46: | lab46: | ||
- | ========================================================================================= | + | ========================================================================================================================= |
- | | + | |
- | ========================================================================================= | + | ========================================================================================================================= |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | coop: OK OK OK OK OK OK OK OK OK OK | + | coop: |
- | | + | |
- | | + | |
- | noargs: | + | noargs: |
- | | + | |
- | invqty: | + | invqty: |
- | | + | |
- | invlow: | + | invlow: |
- | | + | |
- | ========================================================================================= | + | ========================================================================================================================= |
lab46: | 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==== | ====In general==== | ||
Line 576: | Line 656: | ||
Submitting discrete project " | Submitting discrete project " | ||
- | -> ../pnc1-20170713-11.tar.gz(OK) | + | -> ../pnc1-20170907-16.tar.gz(OK) |
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
Line 584: | Line 664: | ||
====Evaluation Criteria==== | ====Evaluation Criteria==== | ||
- | What I will be looking for: | + | Grand total points: |
< | < | ||
546: | 546: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
- | *: | ||
</ | </ | ||
+ | |||
+ | 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. |