Act11_Disjoint_Parallel

Act11_Disjoint_Parallel - Illinois Institute of Technology...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Illinois Institute of Technology Activities for Lecture 11 Disjoint Parallel Programs; Evaluation Graphs CS 536, Mon Nov 15, 2010 Activity 11.1: Disjoint Parallel Programs A. Why? •Disjoint Parallel Programs are simple to understand, so their operational semantics is easier to present. B. Outcomes At the end of this activity you should: •Be able to recognize a Disjoint Parallel Program (DPP) if you see one. C. Questions 1. 2. 3. 4. 5. 6. Is [x:= v || y:= v+2 || z:= v∗2] a DPP? Yes! Is [x:= v || y:= v+2; z:= v∗2 || v:= 3] a DPP? No! Is [x:= v || v:= y-2] a DPP? No! Can a thread of a DPP include an if-else statement? Yes! Can a thread of a DPP include a while loop? Yes! Can a while loop have a body that includes a parallel program? Yes! E.g., is [x:= 0 || y:= 1]; while x ≤ n do [x:= x+1 || y:= y*2] od include only DPPs? Activity 11.2: Evaluation Graphs A. Why? •Evaluation graphs are a natural way to express the possible ways a program might execute. B. Outcomes At the end of this activity you should: •Be able to write an evaluation graph for a parallel program (DPP or not). C. Questions Draw evaluation graphs for the following programs starting in the given state. 1. [x:= v || y:= v+2 || z:= v∗2] in state σ ⇒ v = a. Let b be the constant for a+2 and c be the constant for a*2, and define the following states: σ₁ ⇔ σ[x ↦ a] CS 536: Science of Programming - 1 of 6 © James Sasaki, 2010 Illinois Institute of Technology Activities for Lecture 11 σ₂ ⇔ σ[y ↦ b] σ₃ ⇔ σ[z ↦ c] σ₄ ⇔ σ[x ↦ a][y ↦ b] ⇔ σ[y ↦ b][x ↦ a] σ₅ ⇔ σ[y ↦ b][z ↦ c] ⇔ σ[z ↦ c][y ↦ b] σ₆ ⇔ σ[x ↦ a][z ↦ c] ⇔ σ[z ↦ c][x ↦ a] σ₇ ⇔ σ[x ↦ a][y ↦ b][z ↦ c] ⇔ σ[x ↦ a][z ↦ c][y ↦ b] ⇔ σ[y ↦ b][x ↦ a][z ↦ c] ⇔ σ[y ↦ b][z ↦ c][x ↦ a] ⇔ σ[z ↦ c][x ↦ a][y ↦ b] ⇔ σ[z ↦ c][y ↦ b][x ↦ a] Here’s the evaluation graph. 〈 [x:= v || y:= v+2 || z:= v∗2] , σ〉 〈 [E || y:= v+2 || z:= v∗2] , σ₁〉 〈[x:= v || E || z:= v∗2] , σ₂〉 〈 [x:= v || y:= v+2 || E] , σ₃〉 〈 [x:= v || E || E] , σ₅〉 〈 [E || E || z:= v∗2] , σ₄〉 〈 [E || y:= v+2 || E] , σ₆〉 〈 [E || E || E] , σ₇〉 CS 536: Science of Programming - 2 of 6 - © James Sasaki, 2010 Illinois Institute of Technology Activities for Lecture 11 -----------------------------------------------------------Stopped here 2. [x:= v || y:= v+2 || z:= v∗2] in state σ ⇒ v = 0. This is the same as the previous problem but it has a specific value for v. 3. [x:= v || y:= v+2; z:= v∗2] in state σ ⇒ v = 6. Note: I changed the problem by dropping the third thread (it made the problem way too long). Also note that because threads are executed sequentially, we must evaluate y:= v+2 before z:= v∗2. We may have other statements interleaved between them, however. The evaluation graph is 〈 [x:= v || y:= v+2; z:= v∗2], σ 〉 〈 [E || y:= v+2; z:= v∗2], σ[x ↦ 6] 〉 〈 [x:= v || z:= v∗2], σ[y ↦ 8] 〉 〈 [E || z:= v∗2], σ[x ↦ 6][y ↦ 8] 〉 〈 [x:= v || E], σ[y ↦ 8][z ↦ 12] 〉 〈 [E || E], σ[x ↦ 6][y ↦ 8][z ↦ 12] 〉 4. [x:= T || x:= F]; while x do [x:= T || x:= F] od in state σ ⇒ x = T. It may help to define τ = σ[x ↦  F]. CS 536: Science of Programming - 3 of 6 - © James Sasaki, 2010 Illinois Institute of Technology Activities for Lecture 11 Let W be while x do [x:= T || x:= F] od. The evaluation graph is given below. Note that if the parallel statement always evaluates x:= F before x:= T, the program diverges. 〈 [x:= T || x:= F]; W , σ〉 〈 [E || x:= F]; W , σ〉 〈 [x:= T || E ]; W , τ〉 〈 [E || E ]; W , τ〉 〈 [E || E ]; W , σ〉 5. while x ≤ n do [x:= x+1 || y:= y*2] in state σ ⇔ x = 0 ∧ y = 1 ∧ n = 3. Let W be while x ≤ n do [x:= x+1 || y:= y*2] od and define the following states. σ ⇔ x = 0 ∧ y = 1 ∧ n = 3 σ₁ ⇔ σ[x ↦ 1] ⇔ x = 1 ∧ y = 1 ∧ n = 3 σ₂ ⇔ σ[y ↦ 2] ⇔ x = 0 ∧ y = 2 ∧ n = 3 τ₁ ⇔ σ[x ↦ 1][y ↦ 2] ⇔ σ[y ↦ 2][x ↦ 1] ⇔ x = 1 ∧ y = 2 ∧ n = 3 σ₃ ⇔ τ₁[x ↦ 2] ⇔ x = 2 ∧ y = 2 ∧ n = 3 σ₄ ⇔ τ₁[y ↦ 4] ⇔ x = 1 ∧ y = 4 ∧ n = 3 τ₂ ⇔ τ₁[x ↦ 2][y ↦ 4] ⇔ τ₁[y ↦ 4][x ↦ 2] ⇔ x = 2 ∧ y = 4 ∧ n = 3 σ₅ ⇔ τ₂[x ↦ 3]  ⇔ x = 3 ∧ y = 4 ∧ n = 3 σ₆ ⇔ τ₂[y ↦ 8]  ⇔ x = 2 ∧ y = 8 ∧ n = 3 τ₃ ⇔ τ₂[x ↦ 3][y ↦ 8] ⇔ τ₂[y ↦ 8][x ↦ 3] ⇔ x = 3 ∧ y = 8 ∧ n = 3 σ₇ ⇔ τ₃[x ↦ 4]  ⇔ x = 4 ∧ y = 4 ∧ n = 3 σ₈ ⇔ τ₃[y ↦ 16]  ⇔ x = 3 ∧ y = 16 ∧ n = 3 τ₄ ⇔ τ₃[x ↦ 4][y ↦ 16] ⇔ τ₃[y ↦ 16][x ↦ 4] ⇔ x = 4 ∧ y = 16 ∧ n = 3 CS 536: Science of Programming - 4 of 6 - © James Sasaki, 2010 Illinois Institute of Technology Activities for Lecture 11 The evaluation graph is: 〈W, σ〉 〈 [x:= x+1 || y:= y*2]; W , σ〉 〈 [x:= x+1 || y:= y*2]; W , σ₁〉 〈W, τ₁〉 〈 [x:= x+1 || y:= y*2]; W , τ₁〉 〈 [x:= x+1 || y:= y*2]; W , σ₃〉 〈W, τ₂〉 〈 [x:= x+1 || y:= y*2]; W , τ₂〉 〈 [x:= x+1 || y:= y*2]; W , σ₅〉 〈W, τ₃〉 〈 [x:= x+1 || y:= y*2]; W , τ₃〉 〈 [x:= x+1 || y:= y*2]; W , σ₇〉 〈W, τ₄〉 〈 [x:= x+1 || y:= y*2]; W , σ₈〉 〈 [x:= x+1 || y:= y*2]; W , σ₆〉 〈 [x:= x+1 || y:= y*2]; W , σ₄〉 〈 [x:= x+1 || y:= y*2]; W , σ₂〉 CS 536: Science of Programming - 5 of 6 - © James Sasaki, 2010 Illinois Institute of Technology Activities for Lecture 11 6. Here’s one more problem (wasn’t in the original version of the activity: Draw the evaluation graph for [v:= 8 || v:= v+2; v:= v∗2], starting in state σ where σ(v) = 4. This is similar to problem 3 but here the program isn’t disjoint parallel. 〈 [v:= 8 || v:= v+2; v:= v∗2], σ 〉 〈 [E || v:= v+2; v:= v∗2], σ[v ↦ 8] 〉 〈 [v:= 8 || v:= v∗2], σ[v ↦ 6] 〉 〈 [E || v:= v∗2], σ[v ↦ 10] 〉 〈 [E || v:= v∗2], σ[v ↦ 8] 〉 〈 [v:= 8 || E ], σ[v ↦ 12] 〉 〈 [E || E ], σ[v ↦ 20] 〉 〈 [E || E], σ[v ↦ 16] 〉 〈 [E || E ], σ[v ↦ 8] 〉 Any program with an evaluation graph that has more than one sink must be not disjoint parallel. The converse isn’t true, however — there exist non-DPPs whose evaluation happens to end in a unique final state. CS 536: Science of Programming - 6 of 6 - © James Sasaki, 2010 ...
View Full Document

Ask a homework question - tutors are online