This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
haas:spring2016:cprog:projects:pnc0 [2016/02/24 14:30] – [Check Results] wedge | haas:spring2016:cprog:projects:pnc0 [2016/02/27 13:13] (current) – [Program] wedge | ||
---|---|---|---|
Line 123: | Line 123: | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | Of particular note: the sieve algorithms take advantage of a increased storage space, where others (like brute force) are predominantly time-based. The sieve is also more detailed... even if you don't decide to implement a sieve, take a look and compare the algorithm to what you've done to see the differences in approaches. | ||
=====Program===== | =====Program===== | ||
It is your task to write 3 separate prime number calculating programs: | It is your task to write 3 separate prime number calculating programs: | ||
- | - primebrute.c: | + | - **primebrute.c**: for your brute force implementation |
- | - primesqrt.c: | + | - **primesqrt.c**: for your square root-optimization of the brute force |
- | - primeopt.c: for your optimized solution, be it basing off the existing ones, or taking a different approach | + | - **primeopt.c**: for your optimized solution, be it basing off the existing ones, or taking a different approach |
Your program should: | Your program should: | ||
Line 136: | Line 139: | ||
* these values should be positive integer values; you can make the assumption that the user will always do the right thing. | * these values should be positive integer values; you can make the assumption that the user will always do the right thing. | ||
* start your stopwatch (see **timing** section below): | * start your stopwatch (see **timing** section below): | ||
- | * perform the correct | + | * perform the algorithm against the value |
* if enabled, display the prime numbers found in the range | * if enabled, display the prime numbers found in the range | ||
* output the processing run-time to STDERR (do this always). | * output the processing run-time to STDERR (do this always). | ||
Line 143: | Line 146: | ||
* the timing information will be displayed in accordance to code I will provide (in the **timing** section). | * the timing information will be displayed in accordance to code I will provide (in the **timing** section). | ||
+ | ====Other considerations==== | ||
+ | All your programs MUST perform the calculations to determine primality- you may not always be printing it out (depending on argv[2]), but work must be done to ensure the value is identified as a prime/ | ||
+ | |||
+ | For example: | ||
+ | |||
+ | < | ||
+ | if (show == 1) | ||
+ | { | ||
+ | work to determine if it is prime | ||
+ | if prime | ||
+ | print number | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | will actually skip the core processing, and you’ll see some amazing runtimes as a result. They may be amazing, but they’re not real, because you’re not actually doing anything. | ||
+ | |||
+ | What you want instead: | ||
+ | |||
+ | < | ||
+ | work to determine if it is prime | ||
+ | if (show == 1) | ||
+ | { | ||
+ | if prime | ||
+ | print number | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | there are many ways to express the above, through compound if statements and other arrangements, | ||
+ | |||
+ | That also isn’t to say you can’t avoid doing a work run if you’re able to determine its non-primality with a simple pretest (even value, factor of 3, etc.), but that’s actually considered more of the core “work”, so it is more than okay (and encouraged in the primeopt). | ||
=====Command-Line Arguments===== | =====Command-Line Arguments===== | ||
To automate our comparisons, | To automate our comparisons, | ||
Line 308: | Line 341: | ||
| | ||
============================================ | ============================================ | ||
- | | + | |
- | 16 0.000002 | + | 16 0.000002 |
32 0.000003 | 32 0.000003 | ||
- | 64 0.000005 | + | 64 0.000005 |
- | | + | |
- | | + | |
- | | + | |
- | 1024 0.000539 | + | 1024 0.000540 |
- | 2048 0.001761 | + | 2048 0.001761 |
- | 4096 0.006110 | + | 4096 0.006115 |
- | 8192 0.021278 | + | 8192 0.021259 |
- | | + | |
- | | + | |
- | | + | |
- | 131072 | + | 131072 |
- | 262144 | + | 262144 |
- | 524288 | + | 524288 |
- | | + | |
- | | + | |
- | | + | |
| | ||
+ | ============================================ | ||
+ | | ||
============================================ | ============================================ | ||
lab46: | lab46: | ||
Line 339: | Line 374: | ||
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 you'd like to experiment with other variations, | + | In the example output above, my **primeopt** is playing with an implementation |
- | * primesrto (I was playing with optimizations | + | I also include a validation check- |
+ | |||
+ | If you'd like to experiment with other variations, the script also recognizes prime variants of the following names: | ||
+ | * primeopt0 (for an additional optimization) | ||
+ | * primeopt1 (and another) | ||
* primeopt2 (if you'd like another entry for another optimization) | * primeopt2 (if you'd like another entry for another optimization) | ||
* primeopt3 (for yet another optimization) | * primeopt3 (for yet another optimization) | ||
* primeopt4 (and one more; hey, I want you to have nice things) | * primeopt4 (and one more; hey, I want you to have nice things) | ||
- | * primemap | ||
=====Bonus Points===== | =====Bonus Points===== | ||
There will be an additional bonus point opportunity with this project, based on processing run-time of your optimized solution. | There will be an additional bonus point opportunity with this project, based on processing run-time of your optimized solution. |