2018-02-14

Feb 14 In-Class Exercise Thread.

Post your solutions to the Feb 14 In-Class Exercise to this Thread.
Best, Chris
Post your solutions to the Feb 14 In-Class Exercise to this Thread. Best, Chris

-- Feb 14 In-Class Exercise Thread
example latex of matrices
`[[a,b],[c,d]]`
example latex of matrices @BT@[[a,b],[c,d]]@BT@

-- Feb 14 In-Class Exercise Thread
Matrix, vector, and situation with race condition: `[[2,2],[3,3]][[4],[4]]` When i == 0, if the j=0 strand and j=1 strand both read the value before either writes, there will be a race condition.
Matrix, vector, without race condition: `[[0,0],[0,0]][[0],[0]]` The operations will always have zeroes in the result vector no matter what order the operations occur in.
(Edited: 2018-02-14)
Matrix, vector, and situation with race condition: @BT@[[2,2],[3,3]][[4],[4]]@BT@ When i == 0, if the j=0 strand and j=1 strand both read the value before either writes, there will be a race condition. Matrix, vector, without race condition: @BT@[[0,0],[0,0]][[0],[0]]@BT@ The operations will always have zeroes in the result vector no matter what order the operations occur in.

-- Feb 14 In-Class Exercise Thread
If we have a matrix `[[a,b],[c,d]]`, if any of the values are different to each other, there may be a race condition.

In the example below, we will face a race condition:
`[[1,2],[3,3]] * [1,1]`

If we have a matrix `[[a,b],[c,d]]`, `a`, `b`, `c` and `d` should all be the same value. In this case, there would not be a race condition
(Edited: 2018-02-14)
If we have a matrix @BT@[[a,b],[c,d]]@BT@, if any of the values are different to each other, there may be a race condition. ---- In the example below, we will face a race condition: @BT@[[1,2],[3,3]] * [1,1]@BT@ ---- If we have a matrix @BT@[[a,b],[c,d]]@BT@, @BT@a@BT@, @BT@b@BT@, @BT@c@BT@ and @BT@d@BT@ should all be the same value. In this case, there would not be a race condition

-- Feb 14 In-Class Exercise Thread
(1) has race condition.
a = `[[1,3],[4,6]]`
x = `[[4],[6]]`
a * x would have race condition,
case: when 2 strands read the y[i] together and then calc y[i] independently and write to y[i] with code y[i] = y[i] + a[i][j] * x[j] then y[i] would get corrupted due to race condition. e.g. j= 1 and j=2 strands start together
  
  
  
(2) does not have race condition
a = `[[0,0],[0,0]]`
x = `[[0],[0]]`
as all values are zeros so product and sum does not matter and race condition wont affect.
(Edited: 2018-02-14)
(1) has race condition. a = @BT@[[1,3],[4,6]]@BT@ x = @BT@[[4],[6]]@BT@ a * x would have race condition, case: when 2 strands read the y[i] together and then calc y[i] independently and write to y[i] with code y[i] = y[i] + a[i][j] * x[j] then y[i] would get corrupted due to race condition. e.g. j= 1 and j=2 strands start together (2) does not have race condition a = @BT@[[0,0],[0,0]]@BT@ x = @BT@[[0],[0]]@BT@ as all values are zeros so product and sum does not matter and race condition wont affect.

-- Feb 14 In-Class Exercise Thread
1. a = `[``[`1 2 3`]` `[`1 2 3`]` `[`1 2 3`]``]` x = `[`1 2 3`]`
2. a = `[``[`1 0 0`]``[`0 2 0`]``[`0 0 3`]``]` x = `[`1 2 3`]` Since all elements are 0 except for one, the parallel sum would not create a race condition.
(Edited: 2018-02-14)
1. a = @BT@[@BT@@BT@[@BT@1 2 3@BT@]@BT@ @BT@[@BT@1 2 3@BT@]@BT@ @BT@[@BT@1 2 3@BT@]@BT@@BT@]@BT@ x = @BT@[@BT@1 2 3@BT@]@BT@ 2. a = @BT@[@BT@@BT@[@BT@1 0 0@BT@]@BT@@BT@[@BT@0 2 0@BT@]@BT@@BT@[@BT@0 0 3@BT@]@BT@@BT@]@BT@ x = @BT@[@BT@1 2 3@BT@]@BT@ Since all elements are 0 except for one, the parallel sum would not create a race condition.

-- Feb 14 In-Class Exercise Thread
Suppose we have a matrix like this:
`A=[[a, b],[c, d]]`
In the first parallel loop, suppose that i=1 comes first. then it is possible that the 2nd loop will attempt to read A[i][j] at same time when j=0 and j=1 before writing to y[i], hence race condition is possible.
There are cases where race conditions are not possible, only if all a[i][j] values are same for all i and j.
(Edited: 2018-02-14)
Suppose we have a matrix like this: @BT@A=[[a, b],[c, d]]@BT@ In the first parallel loop, suppose that i=1 comes first. then it is possible that the 2nd loop will attempt to read A[i][j] at same time when j=0 and j=1 before writing to y[i], hence race condition is possible. There are cases where race conditions are not possible, only if all a[i][j] values are same for all i and j.

-- Feb 14 In-Class Exercise Thread
Name: Kunal Deshmukh Below matrix will result in race condition: `[[1,3],[4,2]]`,`[[2],[9]]` since inner loop is also paralalized, y[i] = y[i] + a[i][j] * x[j] will be calculated by by multiple processes and since it involves updateion in the value of y[i], and processes many not run sequentialy, race condition can occur. condition to avoid race condition: Same element in a matrix. eg. `[[1,1],[1,1]]` , `[[0],[0]]`
(Edited: 2018-02-14)
<nowiki> Name: Kunal Deshmukh Below matrix will result in race condition:</nowiki> @BT@[[1,3],[4,2]]@BT@,@BT@[[2],[9]]@BT@<nowiki> since inner loop is also paralalized, y[i] = y[i] + a[i][j] * x[j] will be calculated by by multiple processes and since it involves updateion in the value of y[i], and processes many not run sequentialy, race condition can occur. condition to avoid race condition: Same element in a matrix. eg. </nowiki>@BT@[[1,1],[1,1]]@BT@ , @BT@[[0],[0]]@BT@

-- Feb 14 In-Class Exercise Thread
`[[1,3],[3,4]]` * `[[2],[5]]` , this can give race condition, if each thread i reads the value of y[i] at the same time.
The situation where no race condition will occur: `[[0,0],[0,0]]` * `[[1],[1]]`
(Edited: 2018-02-14)
@BT@[[1,3],[3,4]]@BT@ * @BT@[[2],[5]]@BT@ , this can give race condition, if each thread i reads the value of y[i] at the same time. The situation where no race condition will occur: @BT@[[0,0],[0,0]]@BT@ * @BT@[[1],[1]]@BT@

-- Feb 14 In-Class Exercise Thread
For,
`[[1,2,3],[4,5,6],[7,8,9]]``[[4],[5],[6]]`
the race condition would occur when both j=0 and j=1 occur at the same time.
The fix for this would be to have the vector with all 0s.
(Edited: 2018-02-14)
For, @BT@[[1,2,3],[4,5,6],[7,8,9]]@BT@@BT@[[4],[5],[6]]@BT@ the race condition would occur when both j=0 and j=1 occur at the same time. The fix for this would be to have the vector with all 0s.
[ Next ]
X