Oracle® Solaris Studio 12.4: OpenMP API User's Guide

Exit Print View

Updated: December 2014
 
 

8.2.2 Reducing False Sharing

False sharing can typically be detected when accesses to certain variables seem particularly expensive. Careful analysis of parallel loops that play a major part in the execution of an application can reveal performance scalability problems caused by false sharing.

In general, false sharing can be reduced using the following techniques:

  • Make use of private or threadprivate data as much as possible.

  • Use the compiler’s optimization features to eliminate memory loads and stores.

  • Pad data structures so that each thread's data resides on a different cache line. The size of the padding is system-dependent, and is the size needed to push a thread's data onto a separate cache line.

  • Modify data structures so there is less sharing of data among the threads.

Techniques for tackling false sharing are very much dependent on the particular application. In some cases, a change in the way the data is allocated can reduce false sharing. In other cases, changing the mapping of iterations to threads by giving each thread more work per chunk (by changing the chunk_size value) can also lead to a reduction in false sharing.