Memory & CPU Caches

This week and last weekend I was primarily focusing on memory pools, allocators, CPU caches. I now probably know how allocators work, simply separating memory allocation & objects initialization, for example, reserve() function in std::vector, it doesn’t initialize the allocated data segment, thus permitting better performance when we don’t need initialize the data immediately.

CPU cache is another very interesting & important aspect that can (hugely) influence the performance of our programs, as it’s way faster than main memory (RAM). Smaller is faster. A great resource I found on Tuesday evening was a YouTube video – Scott Meyers’s presentation on code::drive conference 2014, a very humorous & high-quality speech!! Really awesome!

Here are a few slides screenshots, the complete presentation pdf version can be downloaded from here.

There are some interesting tops contained within it: cache lines, false sharing, data-oriented design, etc. Very practical and constructive.

From Wednesday and later, I reviewed my qsort vs std::sort problem in terms of cpu cache and cache lines. I found a hug bug (typo) in my qsort function call (embarrassed). Then I further developed that, added a few more tests (for instance, indirect sort), and drew some charts. The details can be found here.


Supplemented on Nov 24, 2020

About cache associativity: see https://www.youtube.com/watch?v=UCK-0fCchmY, a very detailed & intuitive demonstration.

Additional resource: Gallery of Processor Cache Effects by Igor Ostrovsky.

Completing in Communication

This week I had a discussion about error estimates for FEM with Miss White on Wednesday evening. While in communication about our ideas, I found a few things that I had deemed almost perfect, but it turned out that it was never meant to be perfect if you don’t have an in-depth discussion with someone of your profession yet. As well as subsequent interchange of ideas, we inspired and completed each other in the process of communication in an unconscious way.

Reviewing FEM

This week did actually only one thing, reviewing FEM. I found a lot of C++ numerical libraries, as well as some with FEM, like deal.II, MFEM, FreeFEM. FEM is soooo important in engineering, geophysics, CAD, etc. FEM is fun & powerful.

Thanks to Miss White, I could go over the knowledge in respect to numerical analysis and FEM again. Meanwhile, I want to apologize to Miss White that I didn’t prepare at all for how to teach her programming. Plus I don’t actually use MATLAB much. I’m working on C++, Linux stuff, etc. Truly sorry about that.

Next week, I’m planning to work on some string algorithms (trie, data compression), as well as Computer Vision (which is gonna take a few coming weeks).