This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:fall2017:discrete:projects:pnc2 [2017/07/13 20:43] – wedge | haas:fall2017:discrete:projects:pnc2 [2017/09/18 15:58] (current) – [Evaluation Criteria] wedge | ||
---|---|---|---|
Line 6: | Line 6: | ||
~~TOC~~ | ~~TOC~~ | ||
- | ======Project: | + | ======Project: |
=====Errata===== | =====Errata===== | ||
Line 14: | Line 14: | ||
====Revision List==== | ====Revision List==== | ||
- | * revision 0: initial release (20170713) | ||
* revision #: < | * revision #: < | ||
Line 29: | Line 28: | ||
* if optimizing for (or trying to take up less) space, the program runtime can grow. | * if optimizing for (or trying to take up less) space, the program runtime can grow. | ||
- | Let it be clear: using modern computers bound by fourth dimensional constraints, | + | Let it be clear: using modern computers bound by these so-called |
In the previous projects, we focused on algorithms that were more constrained by time- taking progressively more time the larger the data set to be processed became. These time-constrained algorithms also happen to be the type of algorithm you're most familiar with (or at least, were indoctrinated into thinking with...). Your third grade self, on the other hand, potentially would have found more familiarity with the space-constrained methods this project will explore. | In the previous projects, we focused on algorithms that were more constrained by time- taking progressively more time the larger the data set to be processed became. These time-constrained algorithms also happen to be the type of algorithm you're most familiar with (or at least, were indoctrinated into thinking with...). Your third grade self, on the other hand, potentially would have found more familiarity with the space-constrained methods this project will explore. | ||
Line 47: | Line 46: | ||
* unless otherwise specified, you are doing all values (odds AND evens). | * unless otherwise specified, you are doing all values (odds AND evens). | ||
- | * if you exceed some threshold of values get " | + | * if you exceed some threshold of values |
- | * as the space-based approach to solving our prime number computation problem is fundamentally different from those we took in previous projects, you will want to look to start from scratch. Trying to reuse old code and shoehorn it into what effectively amounts to an entirely different paradigm will create a lot of problems. | + | * as the storage-based approach to solving our prime number computation problem is fundamentally different from those we took in previous projects, you will want to look to start from scratch. Trying to reuse old code and shoehorn it into what effectively amounts to an entirely different paradigm will create a lot of problems. |
- | But, the conceptual level, at least for the baseline implementation, | + | But, the conceptual level, at least for the baseline implementation, |
You may find some of the previous optimizations aren't even applicable based on how this algorithm works (break on composite, for instance). | You may find some of the previous optimizations aren't even applicable based on how this algorithm works (break on composite, for instance). | ||
Line 112: | Line 111: | ||
For this project, you'll be implementing various combinations of optimizations, | For this project, you'll be implementing various combinations of optimizations, | ||
+ | |||
+ | =====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, I will be looking for pertinent comments specifically covering the how or why of the particular change unique to the variant in question. | ||
+ | |||
+ | And notice I said the " | ||
+ | |||
+ | * WHY is that important to the process? | ||
+ | * HOW does it impact the efficiency of the algorithm? | ||
+ | |||
+ | 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 to code it- if you cannot adequately explain the WHY and HOW, you similarly will have trouble. | ||
=====Programs===== | =====Programs===== | ||
Line 157: | Line 174: | ||
* 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. | * 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 below (see the **timing** section). | * the timing information will be displayed in accordance to code I will provide below (see the **timing** section). | ||
+ | |||
+ | =====Implementation Restrictions===== | ||
+ | |||
+ | As our goal is not only to explore the more subtle concepts of computing but to promote different methods of thinking (and arriving at solutions seemingly in different ways), one of the themes I have been harping on is the stricter adherence to the structured programming philosophy/ | ||
+ | |||
+ | As such, the following implementation restrictions are also in place: | ||
+ | |||
+ | * focus on **if()**, **ternary**, | ||
+ | * keep your use of **continue** and **break** statements (especially **break** statements) to a necessary minimum). | ||
+ | * absolutely **NO** other non-structured program flow alteration (jumps, gotos, etc.) | ||
+ | * absolutely **NO** infinite loops (**while(1)**, | ||
+ | * no forced redirection of the flow of the process (no seeking to the end of the file to grab a max size only to zip back somewhere else: deal with the data in as you are naturally encountering it). | ||
+ | * All " | ||
+ | * **NO** logic shunts (ie having an if statement nested inside a loop to bypass an undesirable iteration)- this should be handled by the loop condition! | ||
+ | * At most, **ONE** return statement per function (in the case of **void**, 0 return statements). | ||
+ | * No redundant duplication of code to address different top-level conditions or operational constraints (think quantity vs. range- these can successfully co-exist in the same block of code). | ||
+ | * Never leave an initialized or allocated resource unverified- always do proper error checking (was the file successfully opened? Was the memory successfully allocated? | ||
+ | |||
+ | A common resistance or complaint I get with imposing these is that it may make your solutions more cumbersome or less optimal; that actually may not be an incorrect assertion, but remember: we are interested in the longer-term pursuit of structured thinking and effective problem solving. To foster your ability to think flexibly and differently. We tend to be naturally more averse to going against the grain, but to be an effective programmer/ | ||
+ | |||
+ | I am seeking to make you all better thinkers and programmers, | ||
=====Grabit Integration===== | =====Grabit Integration===== | ||
Line 162: | Line 200: | ||
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 pnc2 directory tree ... OK | -> Creating project pnc2 directory tree ... OK | ||
-> Copying pnc2 project files ... OK | -> Copying pnc2 project files ... OK | ||
Line 176: | Line 212: | ||
*** 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: | lab46: | ||
Line 194: | Line 229: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
- | ******************[ Discrete Structures | + | ******************[ Discrete Structures |
** make - build everything | ** make - build everything | ||
** make showerrors | ** make showerrors | ||
- | ** ** | ||
** make debug - build everything with debug symbols | ** make debug - build everything with debug symbols | ||
- | ** make check | + | ** make checkqty |
+ | ** make checkrange | ||
+ | ** ** | ||
+ | ** make verifyqty | ||
+ | ** make verifyrange | ||
+ | ** make verifyall | ||
** ** | ** ** | ||
** make link - link in previous prime programs | ** make link - link in previous prime programs | ||
Line 215: | Line 254: | ||
** make help - this information | ** make help - this information | ||
************************************************************************ | ************************************************************************ | ||
- | lab46: | + | lab46: |
</ | </ | ||
Line 221: | Line 260: | ||
* **make**: compile everything | * **make**: compile everything | ||
- | * any **warnings** or **errors** generated by the compiler will go into a file in the base directory of the project | + | * 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 | * **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. | * any **warnings** or **errors** generated by the compiler will be displayed to the screen as the programs compile. | ||
Line 227: | Line 266: | ||
* **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 " | ||
+ | |||
+ | The various " | ||
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 249: | Line 292: | ||
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: | ||
- | | + | * argv[0]: program invocation (path + program name) |
- | | + | * 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 **primeregbms** program: | ||
+ | |||
+ | < | ||
+ | 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 274: | Line 350: | ||
<code c> | <code c> | ||
- | max = atoi(argv[1]); | + | max = atoi (argv[1]); |
</ | </ | ||
Line 532: | Line 608: | ||
And of course the same for the 3 variants, and the same error message reporting if invalid values are given. | And of course the same for the 3 variants, and the same error message reporting if invalid values are given. | ||
+ | |||
====Performance changes==== | ====Performance changes==== | ||
You may notice a change with the sieves as compared to the other algorithms you've implemented with respect to performance- there will likely be a lower bound of performance, | You may notice a change with the sieves as compared to the other algorithms you've implemented with respect to performance- there will likely be a lower bound of performance, | ||
=====Check Results===== | =====Check Results===== | ||
- | To verify your program's correctness and view your implementation' | + | If you'd like to compare |
+ | In order to work, you **MUST** be in the directory where your pnc2 binaries reside, and must be named as such (which occurs if you ran **make** to compile them). | ||
+ | |||
+ | ====check qty==== | ||
<cli> | <cli> | ||
+ | lab46: | ||
========================================================= | ========================================================= | ||
qty | qty | ||
Line 557: | Line 638: | ||
| | ||
========================================================= | ========================================================= | ||
+ | lab46: | ||
</ | </ | ||
- | If/ | + | 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. | If you don't feel like waiting, simply hit **CTRL-c** and the script will terminate. | ||
- | If the check is successful, you will see " | + | ====check range==== |
+ | < | ||
+ | lab46: | ||
+ | coming soon | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | ====Verification==== | ||
+ | I also include a validation check- to ensure your prime programs are actually producing the correct list of prime numbers. | ||
+ | |||
+ | ====Full Verification Compliance==== | ||
+ | There' | ||
+ | |||
+ | < | ||
+ | lab46: | ||
+ | coming soon | ||
+ | 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===== | ||
Line 572: | Line 711: | ||
* 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: | ||
- | | + | * soe |
- | * **primeregms.c**: | + | * **primesoe.c**: baseline sieve of eratosthenes |
- | * **primeregma.c**: | + | * **primesoeo.c**: odd traversal |
- | * **primeregos.c**: | + | * **primesoes.c**: sqrt() trick |
- | * **primeregoa.c**: odd traversal + approximated square root trick | + | * **primesoea.c**: approximated square root |
- | * **primeregbmo.c**: break + map + odd traversal | + | * **primesoeos.c**: odd traversal + sqrt() trick |
- | * **primeregbms.c**: break + map + sqrt() trick | + | * **primesoeoa.c**: odd traversal + approximated square root |
- | * **primeregbma.c**: break + map + approximated square root trick | + | * Code must be commented, and comments must focus on the how and why of the process. |
- | * **primeregbos.c**: break + odd + sqrt() trick | + | |
- | * **primeregboa.c**: | + | |
- | * **primeregmos.c**: | + | |
- | * **primeregmoa.c**: map + odd traversal + approximated square root trick | + | |
- | * **primeregbmos.c**: | + | |
- | * **primeregbmoa.c**: | + | |
- | * Code must be commented | + | |
- | * have a properly filled-out comment banner at the top | + | |
- | * be sure to include any compiling instructions | + | |
- | * have at least 20% of your program consist of **< | + | |
* Output Formatting (including spacing) of program must conform to the provided output (see above). | * Output Formatting (including spacing) of program must conform to the provided output (see above). | ||
* Track/ | * Track/ | ||
Line 597: | Line 726: | ||
<cli> | <cli> | ||
- | lab46: | + | lab46: |
Delinking ... | Delinking ... | ||
- | removed ‘primerega.c’ | ||
- | removed ‘primeregba.c’ | ||
- | removed ‘primeregb.c’ | ||
- | removed ‘primeregbm.c’ | ||
- | removed ‘primeregbo.c’ | ||
- | removed ‘primeregbs.c’ | ||
- | removed ‘primereg.c’ | ||
- | removed ‘primeregm.c’ | ||
- | 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 (pnc1) ... OK | + | Taking snapshot of current project (pnc2) ... OK |
- | Compressing snapshot of pnc1 project archive | + | Compressing snapshot of pnc2 project archive |
- | Setting secure permissions on pnc1 archive | + | Setting secure permissions on pnc2 archive |
Project backup process complete | Project backup process complete | ||
- | Submitting discrete project "pnc1": | + | Submitting discrete project "pnc2": |
- | -> ../pnc1-20170713-11.tar.gz(OK) | + | -> ../pnc2-DATESTRING-HR.tar.gz(OK) |
SUCCESSFULLY SUBMITTED | SUCCESSFULLY SUBMITTED | ||
Line 641: | Line 746: | ||
You should get that final " | You should get that final " | ||
- | What I will be looking for: | + | ====Evaluation Criteria==== |
+ | Grand total points: | ||
< | < | ||
- | 364:pnc1:final tally of results (364/364) | + | 390:pnc2:final tally of results (390/390) |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
- | *: | + | |
</ | </ | ||
+ | What I will be looking for (for each file): | ||
+ | |||
+ | < | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | *: | ||
+ | </ |