1 / 18

CS242

CS242. Optimizing the Raster Program. Optimization Priority. Algorithmic Organizational/architectural Low-level. Algorithmic Optimization. Can your improve on the method use to solve the problem? Example: sorting O(n nog n) – Heap, Merge, quicksort

Download Presentation

CS242

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS242 Optimizing the Raster Program

  2. Optimization Priority • Algorithmic • Organizational/architectural • Low-level

  3. Algorithmic Optimization • Can your improve on the method use to solve the problem? Example: sorting • O(n nog n) – Heap, Merge, quicksort • O(n^2) – Bubble, Insertion, Selection, Shell

  4. Organizational/architectural(Is this algorithmic?) • Concentrate on optimizing the inner loops • Why? • How? • Reduce unnecessary operations

  5. Low-level • Requires understanding compiler output • Knowing which combination of instructions will execute faster than others • Outside scope of this course

  6. Check Timing • Where to put the checks • Why put them there? • See: http://rabbit.eng.miami.edu/info/functions/time.html

  7. Timing the Raster Scanner • Place your START of timing right before you start actually scanning the raster and after your input phase • Place your END right after you have completed scanning but before you do your output • Why?

  8. Some Words About Style • Your main() • Initialization (read in input) • Important work (scan the raster) • Output (output the results) • Cleanup (whatever housekeeping you need) • Write for clarity first • Avoid code that takes some thinking to understand

  9. Clarity Objects in mirror appear farther than they actually are

  10. Clarity Objects in mirror are closer than they appear

  11. Objects in Mirror… • Why is the first choice preferred? • Closer • Farther

  12. Some Optimizations • Create special cases to majority of cases run without checks • 9 special cases • Exploit the symmetry of equality • ½ the number of checks • Further reduces special cases • No longer check if left column

  13. Special Cases9 Zones • Rows • Top row • Middle rows • Bottom row • Columns • Leftmost • Middle • Rightmost

  14. Check 8 Neighbors Check boundary conditions

  15. Symmetry of Equality • Reduces number of checks and element accesses by ½ • Reduces number of special case zones to 6

  16. Exploit Symmetry

  17. Assignment • Organize your main • Write for clarity • Optimize • Time your main work before optimization (last week’s code) • Time your new work • Be prepared for a data file that I give you

  18. Handling binary data in C • Allocate memory for data • Load data into memory • Define “struct” matching header • Use pointers to point at the correct location • Cast pointers when necessary

More Related