# Lecture 24: Critical Thinking. Code Optimization Aspects.

## Lecture Summary

* Last time
  * Parallel computing, multi-core: how caches come into play
  * Critical thinking, and similar tricks for speeding up your code
* Today
  * Critical thinking, and other similar tricks for speeding up your code

## Know your hardware

![Know your bandwidth/latency](/files/-MXzDYa0tV1dJtz9aCO7)

## Choose the right algorithm

* When working on a problem, there's more to performance than asymptotic complexity
  * Because asymptotic complexity is most often defined by the number of operations
  * Memory transactions are rarely considered: they are specific to the hardware
* Assess the arithmetic intensity associated with your problem

![](/files/-MXzESdkvKR6BfxCfv61)

* Simple optimization: Fusing transformations and do not bring data into the cache twice

## Compiler

* Aggressive optimizations done by the compiler might change the behavior of your code
* To help the compiler:
  * Allow it to see as much code as possible
  * Provide flags to convey information (e.g., the target architecture)
* There are a lot of amazing things covered in this lecture. The takeaways are:
  * Compilers are fantastic
  * Know them better to use them wisely
* A quick example is down below. Refer to the [slides](https://uwmadison.app.box.com/s/kapdp4qt18c6869dnaenlo35iytnlp2r) for a lot more fun facts

![](/files/-MXzI3IUdr6jxw-hCJ01)

![](/files/-MXzI64jS_qzpu4BFr0-)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.ruipan.xyz/earlier-readings-and-notes/cs759-hpc-course-notes/lecture-24-critical-thinking.-code-optimizatino-aspects..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
