Practical performance engineering.
WHAT TO DO FIRST
Measure, and establish where time is actually spent.
WHY
Optimisation without measurement is usually wasted.
WHAT DOMINATES MOST SCIENTIFIC CODE
Memory access, not arithmetic.
WHY
Processors are far faster than memory, and waiting dominates.
WHAT IMPROVES MEMORY BEHAVIOUR
Accessing data contiguously Structuring data for the access pattern Blocking computations to fit in cache Reducing unnecessary copying
WHAT VECTORISATION IS
A single instruction operating on several values.
WHAT ENABLES IT
Simple loops over contiguous data, without dependencies between iterations.
WHAT PREVENTS IT
Branching inside loops Indirect access Aliasing the compiler cannot rule out
WHAT TO PARALLELISE
The outermost loop that has enough work.
WHAT TO AVOID
Parallelising loops too small to justify the overhead Synchronisation inside hot loops False sharing, where threads write to the same cache line
WHAT TO USE
Established numerical libraries rather than writing your own.
WHY
They are tuned for specific hardware and are extremely difficult to match.