Open main menu

CDOT Wiki β

Changes

GPU621/Group 1

86 bytes added, 18:45, 9 April 2023
Solution
When two threads update different variables that share the same cache line, this is known as false sharing. A performance hit results as a result of each thread invalidating the cache line for the other thread. In order to ensure that each variable is aligned to its own cache line, we can fix this issue by adding padding to the Counter struct. By ensuring that each thread updates a different cache line, false sharing is prevented.
We can further optimise optimize the code by switching to atomic variables from volatile variables, which solves the issue of false sharing as well. In order to ensure that the variables are updated atomically, atomic variables offer a higher level of synchronisationsynchronizationThe updated code, which addresses false sharing and optimization, is provided below:
== Sources ==
25
edits