Optimization

toc
 * Home * Programming * Optimization**


 * Optimization** is about to chose the best element from some set of available alternatives, as referred in [|mathematical optimization] as for instance applied in computer chess to optimize evaluation weights with automated tuning methods, and [|program optimizations], which is the topic covered on this page. Most importantly there is the algorithmic optimization on design level such as using alpha-beta rather than plain minimax, followed by source code optimizations, and finally [|Compiler optimizations].

=Premature Optimization= As a warning on premature optimization a quote by Donald Knuth :

=Program Optimizations= Program Optimization is a necessary part of a decent chess program. It comes in two forms, compiler-end and program-end. Compiler-end optimization involves using specific flags to get a quick program at the cost of speed of compile and memory usage, whereas program-end optimization involves using inline functions and things like that.


 * Avoiding Branches
 * Performance Measurement
 * Profiling
 * SIMD and SWAR Techniques

Compilers
Generally, the Intel C Compiler produces faster compiles, though in recent times, the GNU C Compiler is catching up.

Compiler flags

 * -O3 is the most aggressive optimization flag, though sometimes this can ruin the performance of the chess program.
 * -O2 is the 'safest' optimization flag. It produces a decently fast executable, and won't ruin the performance.
 * -O1/-O produces a faster executable than it would normally
 * -Os is equivent to -O2 but with size of executable and memory usage in mind.

=See also=
 * Automated Tuning
 * Genetic Programming
 * NUMA
 * Simulated Annealing

=Publications=
 * Bruce W. Leverett (**1981**). //Register allocation in optimizing compilers//. Ph.D. thesis, Carnegie Mellon University
 * Bruce W. Leverett (**1982**). //[|Topics in Code Generation and Register Allocation]//. Carnegie Mellon University
 * Bruce W. Leverett (**1983**). //[|Register allocation in optimizing compilers]//. UMI Research Press

=Forum Posts= > [|Re: Beginner's guide to graphical profiling] by Marco Costalba, CCC, September 10, 2016 » Stockfish
 * [|Beginner's guide to graphical profiling] by Matthew Lai, CCC, September 10, 2016 » Profiling, Giraffe
 * [|Reliable speed comparison: some math required] by Marco Costalba, CCC, February 27, 2018 » Nodes per second

=External Links= > [|Global optimization from Wikipedia] > [|Optimization problem from Wikipedia]
 * [|Mathematical optimization from Wikipedia]
 * [|Program optimization from Wikipedia]
 * [|Compiler optimization from Wikipedia]
 * [|Software optimization resources. C++ and assembly. Windows, Linux, BSD, Mac OS X] by [|Agner Fog]
 * [|Programming Optimization] by Paul Hsieh

=References= =What links here?= include page="Optimization" component="backlinks" limit="20"
 * Up one Level**