Posts

Showing posts from September, 2019

Parallel summation of a large array without shared data locks

Image
The traditional producer/consumer pattern employs a shared buffer between the producer and the consumer.   Many producer/consumer problems are simply sequential problems with the overhead of multiple tasks and a shared buffer. Parallel operations, on the other hand, are more naturally concurrent without the locking overhead of a shared buffer. Instead non-overlapping data elements of a collection such as an array are assigned to two or more tasks, and identical tasks process their subsets of the collection without need of locking the collection.   If the parallel task is to sum all the elements in the array then task 1 in the diagram above will sum the elements in the first half of the array while task 2 sums the elements in the second half of the array. Task 1 and task 2 then simply report their subtotals to the parent task which adds the two values and returns the final total. The following source code is an Ada package for parallel addition along with a proced...