CSCE 411 Lecture 38
« previous | Wednesday, November 28, 2012 | next »
Race Conditions
A determinancy race occurs when two logically parallel insturcitions access the same memory location at at least one of the instructions performs a write.
def race_example():
x = 0
parallel for i in [1..2]:
x = x+1What is the value of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle x} ?
Matrix Multiplication
Simple divide and conquer algorithm:
def matrix_add(C, T, n):
# Adds matrices C and T in-place, producing C = C + T
# n is a power of 2 for simplicity
if n == 1:
C[1, 1] = C[1, 1] + T[1, 1]
else:
partition C and T into 4 n/2 x n/2 matrices
spawn matrix_add(C[1,1], T[1,1], n/2)
spawn matrix_add(C[1,2], T[1,2], n/2)
spawn matrix_add(C[2,1], T[2,1], n/2)
spawn matrix_add(C[2,2], T[2,2], n/2)
sync
def matrix_multiply(C, A, B, n):
# Multiplies matrices A and B, storing the result in C. // n is power of 2 (for simplicity).
if n == 1:
C[1, 1] = A[1, 1] · B[1, 1]
else:
allocate a temporary matrix T[1...n, 1...n]
partition A, B, C, and T into (n/2)x(n/2) submatrices
spawn matrix_multiply(C11,A11,B11, n/2)
spawn matrix_multiply(C12,A11,B12, n/2)
spawn matrix_multiply(C21,A21,B11, n/2)
spawn matrix_multiply(C22,A21,B12, n/2)
spawn matrix_multiply(T11,A12,B21, n/2)
spawn matrix_multiply(T12,A12,B22, n/2)
spawn matrix_multiply(T21,A22,B21, n/2)
spawn matrix_multiply(T22,A22,B22, n/2)
sync
matrix_add(C, T, n)
Calculus of Finite Differences
Motivation
Analyze running time of algorithms: count number of operations:
for i in [1..n]:
square(i)where square(n) is a function that has running time Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle T_2n^2} . Then the total number of instructions is given by
Where Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle T_1} is the time for loop increment and comparison. (increment and compare happens an extra time to determine "break" condition.
How do you evaluate that monster‽
- Find closed form representation other than looking it up or guessing the solution.
Discrete sums
can be regarded as discrete analogs of integrals
We can evaluate the integral by finding a function Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(x)} such that Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \tfrac{\mathrm{d}}{\mathrm{d}x} \, f(x) = g(x)} , since FTC gives
Difference Operator
Represented as symbol Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Delta} :
Let Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle E} denote the shift operator Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle Eg(n) = g(n+1)} , and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle I} the identity operator, then
Examples:
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = n} : Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Delta f(n) = n+1 - n = 1}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = n^2} : Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Delta f(n) = (n+1)^2 - n^2 = 2n+1}
- Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = n^3} : Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Delta f(n) = (n+1)^3 - n^3 = 3n^2 + 3n + 1}
Falling Power
The Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m} -th falling power of Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n} is defined as
For Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m \ge 0}
Proof. By definition
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \begin{align} \Delta n^{\underline{m}} &= (n+1) n \dots (n-m+2) - n \dots (n-m+2)(n-m+1) \\ &= mn\dots(n-m+2) \end{align}}
What about negative numbers?
Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \frac{n^{\underline{0}}}{n^{\underline{-1}}} = n+1} , so Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n^{\underline{-1}} = \frac{1}{n+1}}
Continue recursively to define
So for Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle m \ge 0} ,
Exponentials
In particular, Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \Delta 2^n = 2^n} ... Hey!