Prev Up Next
Go backward to Simple Divide-and-Conquer Functions
Go up to Introducing Parallelism
Go forward to Dynamic Behaviour

Data-Oriented Parallelism

Quicksort and pfib are examples of (divide-and-conquer) control-oriented parallelism where subexpressions of a function are identified for parallel evaluation. Data-oriented parallelism is an alternative approach where elements of a data structure are evaluated in parallel. A parallel map is a useful example of data-oriented parallelism; for example the parMap function defined below applies its function argument to every element of a list in parallel.
parMap :: (a -> b) -> [a] -> [b]
parMap f [] = []
parMap f (x:xs) = fx `par` fxs `seq` (fx:fxs)
                    where
                      fx = f x
                      fxs = parMap f xs

The definition above works as follows: fx is sparked, before recursing down the list (fxs), only returning the first constructor of the result list after every element has been sparked. The process diagram for parMap is given in the figure below. If the function argument supplied to parMap constructs a data structure, it must be composed with a forcing function in order to ensure that the data structure is constructed in parallel.

Process Diagram
parMap Process Diagram


{trinder,hwloidl,simonpj}@dcs.gla.ac.uk, kh@dcs.st-and.ac.uk

Prev Up Next