Previous | Next --- Slide 27 of 48
Back to Lecture Thumbnails
kayvonf

Question: Can someone write some C-like code that processes the grid in parallel, in accordance with the dependencies illustrated above?

bojianh

Here is some code in python for access pattern, hopefully, it is correct. In order to the make the below code parallel, have to make some foreach for the inner while loop

 for t in range(rows+cols-1):
   if t < cols:
     i = 0
     j = t - i 
   else:
     j = cols - 1
     i = t - j

   while (i < rows and j >= 0):
     do stuff    
     i += 1
     j -= 1
bojianh

Here is a much better version

for iteration in range(rows+cols-1):

n = min(min(iteration+1, rows+cols-1-iteration),min(rows,cols))

if iteration < cols:

start_row = 0

start_col = iteration - start_row 

else:

start_col = cols - 1

start_row = iteration - start_col

# Convert this to foreach

for program_index in range(n):

i = start_row + program_index

j = start_col - program_index 

A[i][j] += 1
cyl

void **process_2darray(double **input_array, int N) { for (int i=0; i<N; i++) { for (int j=0; j<=i, j++) { input_array[i][j-i] = do_some(); } }