False Sharing
Bad data or work distribution can lead to false sharing
- example:
- processor P0 does only even iterations
- processor P1 does only odd iterations
- both processors read and write same cache lines
- each write invalidates the cache line of the pear processor
-
- each processor runs cache coherency protocol on the cache lines, thus the cache lines will ping-pong from one cache to another
for(i=myid; i<n; i+= nthr) {