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 ?

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

Where 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 such that , since FTC gives


Difference Operator

Represented as symbol :

Let denote the shift operator , and the identity operator, then

Examples:

  1. :
  2. :
  3. :

Falling Power

The -th falling power of is defined as

For

Proof. By definition


What about negative numbers?

, so

Continue recursively to define

So for ,


Exponentials

In particular, ... Hey!