Compact and split

Previously, we covered how to parallelize the sequential prefix sum algorithm and discussed how it can be used for other applications. Now, let's cover some of those applications: compact and split. The compact operation is an algorithm that can consolidate values that fulfill the given condition from an array. On the other hand, the split operation is an algorithm that distributes the values to the designated place. In general, these algorithms work sequentially. However, we will see how the parallel prefix-sum operation can improve how it functions.

The compact operation is used to collect specific data that meets a certain condition into an array. For example, if we want to use the compact operation for the positive elements in an array, then the operation is as follows:

In parallel programming, we have a different approach that can utilize multiple cores using the parallel prefix-sum operation. First, we mark the data to check whether it meets the condition or not (that is, predicate), and then we do the prefix-sum operation. The output of prefix-sum will be the index of the marked values, so we can obtain the gathered array by copying them. The following diagram shows an example of a compact operation:

Since all of these tasks can be done in parallel, we can obtain the gathered array in four steps.

On the other hand, split means to distribute the data to a number of different places. In general, we distribute the data from where it was initially. The following diagram shows an example of its operation:

This example shows that the gathered array elements are distributed where they were from. We can also do this in parallel using prefix-sum. Firstly, we refer to the predicate array and do the prefix-sum. Since the outputs are each element's address, we can distribute them easily. The following diagram shows how this operation can be done:

`

Now, let's implement this and discuss their performance limiters and their application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.77.114