Work-efficient parallel prefix (up-sweep phase)

This is the pseudocode for the up-sweep. (Notice the parfor over the j variable, which means that this block of code can be parallelized over threads indexed by j):

input: x0, ..., xn-1initialize:    for i = 0 to n - 1:        yi := xibegin:for k=0 to log2(n) - 1:    parfor j=0 to n - 1:         if j is divisible by 2k+1:            yj+2k+1-1 = yj+2k-1  yj +2k+1 -1            else:            continueendoutput: y0, ..., yn-1 

Get Hands-On GPU Programming with Python and CUDA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.