Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]

Similar presentations


Presentation on theme: "Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]"— Presentation transcript:

1 Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]

2 Divide and Conquer Divide and Conquer? Split the entire range into smaller manageable parts. Solve each part separately. Combine the results to get result for the original larger problem. Merge

3 Divide and Conquer Recursive Divide and Conquer? Doing Divide and Conquer recursively. i.e., First divide into two parts, then divide each of those two parts into two more smaller parts and so on until reach a small enough size. cilk_for is also implemented as a recursive divide and conquer. Splits the loop range in a divide and conquer way ………

4 Homework: Implement it and show the performance.

5 Merge Sort: Sort n numbers recursively using divide and conquer. Picture: Wikipedia

6 Divide and Conquer Fibonacci number: In mathematics, the Fibonacci numbers or Fibonacci sequence are the numbers in the following integer sequence 1 1 2 3 5 8 13 21 …. F(n) = F(n - 1) + F (n - 2) int fib(int n) { if (n < 2) return n; int x = fib(n-1); int y = fib(n-2); return x + y; } int fib(int n) { if (n < 2) return n; int x = cilk_spawn fib(n-1); int y = fib(n-2); cilk_sync; return x + y; }

7 Matrix-multiplication Iterative-MM ( Z, X, Y ) // X, Y, Z are n × n matrices, // where n is a positive integer 1. for i ← 1 to n do 3. Z[ i ][ j ] ← 0 4. for k ← 1 to n do 2. for j ← 1 to n do 5. Z[ i ][ j ] ← Z[ i ][ j ] + (X[ i ][ k ] * Y[ k ][ j ]) Par-Iterative-MM ( Z, X, Y ) // X, Y, Z are n × n matrices, // where n is a positive integer 1. parallel for i ← 1 to n do 3. Z[ i ][ j ] ← 0 4. for k ← 1 to n do 2. parallel for j ← 1 to n do 5. Z[ i ][ j ] ← Z[ i ][ j ] + X[ i ][ k ] ⋅ Y[ k ][ j ] Source: http://www.mathsisfun.com/algebra/matrix-multiplying.htmlhttp://www.mathsisfun.com/algebra/matrix-multiplying.html http://algebra.nipissingu.ca/tutorials/matrices.html

8 Links for c/c++ tutorial https://www.youtube.com/watch?v=rk2fK2IIiiQ https://www.youtube.com/watch?v=Rub-JsjMhWY https://www.youtube.com/watch?v=S3t-5UtvDN0 https://www.youtube.com/watch?v=KNFv4DZ4Mp4 https://www.youtube.com/watch?v=c5gg9F8h8Fw&list=PLfVsf4Bjg79 CZ5kHTiQHcm-l2q8j06ofd (probably by this time you know all) https://www.youtube.com/watch?v=c5gg9F8h8Fw&list=PLfVsf4Bjg79 CZ5kHTiQHcm-l2q8j06ofd Source: google!

9 Group Homework1 [1]. Teach yourself c/c++ Watch these online videos and other resources freely available in Google and write a 10 page group report on c/c++ basic data types, for loops, input, output, arrays and metrics with dynamic allocation, and function. https://www.youtube.com/watch?v=rk2fK2IIiiQ https://www.youtube.com/watch?v=Rub-JsjMhWY https://www.youtube.com/watch?v=S3t-5UtvDN0 https://www.youtube.com/watch?v=KNFv4DZ4Mp4 https://www.youtube.com/watch?v=c5gg9F8h8Fw&list=PLfVsf4Bjg79CZ5kHTiQHcm- l2q8j06ofd (probably by this time you know all) [2]. Write all the codes discussed in the class so far. Compile them and generate output. Vary n and take the time using the cilktime function. Report the change in running time with n. Fix n to the largest and vary # of cores and report the running time.


Download ppt "Lecture 3 Tuesday, February 10, 2015 [With the help of free online resources]"

Similar presentations


Ads by Google