CSCE 411 Lecture 38

From Notes
Jump to navigation Jump to search
Lecture Slides

« 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+1

What is the value of 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

Lecture Slides

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 T2n2. Then the total number of instructions is given by

T1(n+1)+k+1nT2k2

Where T1 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

k=abg(k)

can be regarded as discrete analogs of integrals

abg(x)dx

We can evaluate the integral by finding a function f(x) such that ddxf(x)=g(x), since FTC gives

abg(x)dx=f(b)f(a)


Difference Operator

Represented as symbol Δ:

Δg(n)=g(n+1)g(n)

Let E denote the shift operator Eg(n)=g(n+1), and I the identity operator, then

Δ=EI

Examples:

  1. f(n)=n: Δf(n)=n+1n=1
  2. f(n)=n2: Δf(n)=(n+1)2n2=2n+1
  3. f(n)=n3: Δf(n)=(n+1)3n3=3n2+3n+1

Falling Power

The m-th falling power of n is defined as

nm_=n(n1)(nm+1)

For m0

Δnm_=mnm1_

Proof. By definition

Δnm_=(n+1)n(nm+2)n(nm+2)(nm+1)=mn(nm+2)


What about negative numbers?

n0_n1_=n+1, so n1_=1n+1

Continue recursively to define

nm_=1(n+1)(n+2)(n+m)

So for m0,

Δnm_=mnm1_


Exponentials

Δcn=(c1)cn

In particular, Δ2n=2n... Hey!