Avoid Excessive Synchronization

Submit New Article

March 1, 2009 8:00 PM PST



Challenge

Identify and eliminate excessive synchronization in a threaded application. The overhead associated with excessive synchronization can be a significant detriment to the scaling performance of threaded applications. If global data accesses are found throughout the profile of a thread, each has to be protected by synchronization constructs.


Solution

Merge local data accesses that occur close to each other, make local copies of global data, and remove synchronization constructs associated with read-only global data accesses. The following figure shows a profile of a thread with many global data accesses in red and all the parallel work in green:



All global data access must be protected by synchronization constructs to prevent data races from occurring in the application.

As shown in the figure, many global data accesses that occur close to each other can be merged into one larger synchronization point, thereby eliminating many synchronization points. If two global data accesses exist, and if the data that is accessed second is not updated between the two accesses, then the second access can be made immediately after the first. By protecting these two data accesses with synchronization, two synchronization points can be reduced to one small synchronization point.

Further, large critical sections that occur in the code may be potential candidates for a local copy for each thread, if the data dependencies allow for such an optimization.


Source

Threading Methodology: Principles and Practice