0% found this document useful (0 votes)
25 views

Comp 372 Assignment 3

The document provides an example of multiplying 2x2 matrices using a recursive algorithm. It constructs a computation DAG showing the dependencies between multiplying submatrices. The DAG has a work of 8, span of 3, and

Uploaded by

Hussam Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Comp 372 Assignment 3

The document provides an example of multiplying 2x2 matrices using a recursive algorithm. It constructs a computation DAG showing the dependencies between multiplying submatrices. The DAG has a work of 8, span of 3, and

Uploaded by

Hussam Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Assignment 3:

1. Exercise 27.1-1 from the textbook (10 marks)

• Asymptotic Work: The asymptotic work, which is the total amount of computation
performed, is determined by the total number of recursive calls made. In both versions
of the code, the number of recursive calls remains the same. Therefore, the asymptotic
work remains unchanged.
• Span: The span, which is the length of the longest chain of dependent tasks, is affected
by the change. In the original code, line 5 (calling P-FIB(n - 2)) creates a dependency
between the computation of x and y, leading to a longer span. In the modified code, by
spawning P-FIB(n - 2) in line 4, the tasks x and P-FIB(n - 2) are spawned simultaneously.
This reduces the span and improves parallelism.
• Parallelism: The potential speedup gained by running tasks concurrently is affected by
the change. In the modified code, the parallelism is increased because x and P-FIB(n - 2)
are spawned in parallel. This allows better utilization of available processing resources,
leading to improved parallel performance.
In summary, by spawning P-FIB(n - 2) in line 4 of the code instead of calling it directly, you
reduce the span and increase parallelism, which could lead to better parallel performance in
practice. However, the asymptotic work remains unchanged.

2. Exercise 27.1-7 from the textbook (10 marks)

Analysis:
• Work: Work refers to the total amount of computation performed by an algorithm. In
this case, the work can be calculated by counting the number of iterations in both
parallel loops. The outer loop (j) runs from 2 to n, and the inner loop (i) runs from 1 to j -
1. So, the total number of iterations is the sum of the arithmetic progression from 1 to n
- 1, which can be calculated as (n - 1) * n / 2. However, the actual work is doubled due to
the exchange operation for each iteration. Therefore, the total work is approximately n *
(n - 1) * n.
• Span: Span is the longest chain of dependencies in the execution of the algorithm. In
other words, it represents the critical path that limits the degree of parallelism. In this
case, the span is determined by the longest chain of dependencies, which occurs when j
= n. For each iteration of the outer loop (j), there are j - 1 iterations of the inner loop (i)
that need to be completed before the exchange operation can take place. So, the span
for a single iteration of the outer loop is j - 1. Since the outer loop runs from 2 to n, the
overall span is the sum of these spans for each iteration. The sum can be calculated as (2
- 1) + (3 - 1) + ... + (n - 1), which simplifies to (n - 2) * (n - 1) / 2. Therefore, the span is
approximately (n^2 - 3n + 2) / 2.
• Parallelism: Parallelism is defined as the ratio of work to span, representing the
potential for parallel execution. In this case, the parallelism can be calculated as the ratio
of the total work to the span: Parallelism: (n - 1) / 2
3. Exercise 27.2-1 from the textbook (10 marks)

Let's assume you have two matrices, A and B, both of size 2x2:

1. A = | a11 a12 |
2. | a21 a22 |
3.
4. B = | b11 b12 |
5. | b21 b22 |
6.
The P-SQUARE-MATRIX-MULTIPLY algorithm works by dividing the matrices into submatrices and
recursively multiplying them. Here's how the computation dag might look:

1. Multiply A11 and B11


2. / \
3. Multiply A12 and B21 Multiply A11 and B12
4. / \ / \
5. Multiply A21 and B11 Multiply A22 and B21 Multiply A21 and B12
6. / \ / \ / \
7. Multiply A21 and B12 Multiply A22 and B22 Multiply A21 and B12 Multiply A22 and B22
8.

In this computation dag, each vertex represents a multiplication of two submatrices, and the
edges represent the dependencies between them. The strands in the execution of the algorithm
correspond to the paths from the top to the bottom of the dag.
Now, let's analyze the work, span, and parallelism of this computation:
1. Work: The total number of multiplications required is 8, as there are 8 leaf nodes in the
dag.
2. Span: The span is determined by the length of the critical path in the dag. In this case,
the critical path would be the longest path from the root to a leaf. Since the depth of the
dag is 3 (from the root to the leaf nodes), the span is 3.
3. Parallelism: The parallelism of the computation is given by the formula Work / Span. In
this case, it's 8 / 3, which is approximately 2.67. This means that at most 2.67 strands
can be executed in parallel at any given time.
4. Exercise 31.1-7 from the textbook (10 marks)
5. Exercise 31.2-3 from the textbook (10 marks)
6. Exercise 31.3-1 from the textbook (10 marks)
7. Exercise 31.4-1 from the textbook (10 marks)
8. Exercise 31.5-1 from the textbook (10 marks)
9. Exercise 31.6-1 from the textbook (10 marks)

1. +-------+-------+
2. | a | Order |
3. +-------+-------+
4. | 0 | 1 |
5. | 1 | 11 |
6. | 2 | 10 |
7. | 3 | 5 |
8. | 4 | 5 |
9. | 5 | 2 |
10. | 6 | 5 |
11. | 7 | 10 |
12. | 8 | 10 |
13. | 9 | 5 |
14. | 10 | 2 |
15. +-------+-------+
16.

1. +-------+---------------+
2. | x | ind_{11;2}(x) |
3. +-------+---------------+
4. | 1 | 0 |
5. | 2 | 1 |
6. | 3 | 9 |
7. | 4 | 4 |
8. | 5 | 3 |
9. | 6 | 8 |
10. | 7 | 2 |
11. | 8 | 7 |
12. | 9 | 5 |
13. | 10 | 10 |
14. +-------+---------------+
15.
10. Exercise 31.7-1 from the textbook (10 marks)

You might also like