Master the fundamental concepts of cache optimization through this focused micro-challenge.
When each thread increments its own counter in a shared array, placing counters 8 bytes apart packs eight of them into one 64-byte line. Padding or aligning each counter to 64 bytes gives each thread a private line.
Use alignas(64) on struct fields or insert explicit char padding arrays. Verify sizeof and offsets with offsetof before trusting layout.
cLoading…
std::hardware_destructive_interference_size documents line size when availableperf c2c validationKeep the relevant documentation open while you implement. When your output disagrees with the reference, trace one failing case by hand before changing random lines.
You will pad a struct array so threads no longer false-share, then benchmark before and after. This exercise requires measuring contention drops, not just showing the layout change.
Pad structures to cache line size to prevent false sharing.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github