# HW11_sol - number for i Each processor has local variables...

This preview shows pages 1–2. Sign up to view the full content.

Fall Semester 2008 CS300 Algorithms Solution #11 1. Comment: Each processor carries out the algorithm using its own number for i . Each processor has local variables sum , temp , and incr . Assume that all memory cells in a PRAM that do not contain input contain zero. Now assume that K is d log n e . write M[i] into Sum[i]; incr := 1; for step := 1 to K do read Sum[i] into sum; read Sum[i+incr] into temp; sum := sum+temp; incr := 2*incr; write sum into Sum[i]; end{for}. // Sum[1] will be the sum of M[i]s. if( M[i] < Sum[1]/n ) write 1 into M[i]; else write 0 into M[i]; incr := 1; for step := 1 to K do read M[i] into sum; read M[i+incr] into temp; sum := sum+temp; incr := 2*incr; write sum into M[i]; end{for}.// then M[1] will be the number of students below average. 2. Description: C = A × B Input: A , B , C : n × n boolean matrices M [1] , ··· ,M [ n 2 ] A (store row-wise) M [ n 2 + 1] , ··· ,M [2 n 2 ] B (store column-wise) Output: C M [1] , ··· M [ n 2 ] Comment and Algorithm: Each processor carries out the algorithm using its own

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: number for i . Each processor has local variables a , b , row , col , index and tmp . Assume that all memory cells in a PRAM that do not contain input contain zero. row := d i/n 2 e ; col := d i/n e - b i/n 2 c × n ; index := i- b i/n c × n ; 1 read M[(row-1) × n + index] into a ; read M[ n 2 + (col-1) × n + index] into b ; tmp := a ∧ b ; if tmp == 1 then write 1 in M[(row-1) × n + col] . • the number of processors = n 3 • the number of steps = 2 (reads) 3. Each i th processor reads v i and w i and compare them. If v i ≥ w i , then it writes 1 into i th memory cell. Otherwise, it writes 0. This computation takes O (1) time since it can be done in parallel using n processors. Then, by Binary Fan-in technique, the sum of the values in each memory cell can be computed in O (log n ) time. If the sum is larger than b n/ 2 c , V is stronger than W . 2...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

HW11_sol - number for i Each processor has local variables...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online