Question

In: Computer Science

Given the following code: for (i=2;i<100;i=i+1) { a[i] = b[i] + a[i]; /* S1 */ c[i-1]...

Given the following code:

for (i=2;i<100;i=i+1)

{ a[i] = b[i] + a[i]; /* S1 */

c[i-1] = a[i] + d[i]; /* S2 */

a[i-1] = 2 * b[i]; /* S3 */

b[i+1] = 2 * b[i]; /* S4 */ }

a. List all the dependencies by their types (TD: true-data, AD: anti-data, OD: output-data dependencies).

b. Show how Software Pipelining can exploit parallelism in this code to its fullest potential. How many functional units would be sufficient to achieve the fastest execution time?

c. Is this a parallel loop? If not, can it be parallelized? How?

Solutions

Expert Solution

a. Listing all the dependencies:

There are seven dependences in the C loop given:

1. The true dependence from S1 to S2 on a.

2. The Loop that carried true dependence from S4 to S1 on b.

3. The Loop that carried true dependence from S4 to S3 on b.

4. The Loop that carried true dependence from S4 to S4 on b.

5. The Loop that carried output dependence from S1 to S3 on a.

6. The Loop that carried antidependence from S1 to S3 on a.

7. The Loop that carried antidependence from S2 to S3 on a.

b&c. It is for a loop to be parallel, every iteration must be independent of all others iterations, which will not be the case in the code used for this problem code. Because dependences 1, 2, 3 and 4 are 'true' dependences, however they can not be removed through renaming. Along with these, as dependences 2, 3 and 4 are loop-carried, they will imply that iterations of the loop are not independent. All these factors together imply the loop that it can not be made parallel as the loop is written. Maybe after rewriting the loop it may be possible to find a loop that is functionally equivalent to the original loop that can be made parallel.


Related Solutions

Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that...
Consider the following fragment of C code: for (i=0; i<100; i++) { A[i]=B[i]+C; } Assume that A and B are arrays of 64-bit integers, and C and i are 64-bit integers. Assume that all data values and their addresses are kept in memory (at addresses 1000, 3000, 5000, and 7000 for A, B, C, and i, respectively) except when they are operated on. Assume that values in registers are lost between iterations of the loop. Assume all addresses and words...
2) Given the following C = 25 + 0.8Yd I* = 100 and assuming fixed prices...
2) Given the following C = 25 + 0.8Yd I* = 100 and assuming fixed prices a) What is the equilibrium level of NP ? b) What is the equilibrium level of savings ? c) What is the value of the multiplier ? d) If planned investment falls 10, ceteris paribus, what is the new level of equilibrium NP ? e) If the MPC increases to 0.85 what would equilibrium NP be with I*= 100 ? f) If the MPS...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100;...
C++ Q2.   Given the code as below. Which statement is correct? int myAry[100]; for(int i=0; i<100; i++) myAry = i + 2; for(int i=100; i>0; i--) cout << myAry[i] << '\t'; The first for loop assigns myAry 99 values and the null character. The second for loop prints out myAry elements backwards. The index in the second for loop is out of bounds. Only the first loop needs the null character. Q3. A value returning function that takes one parameter,...
Translate the following C code to MIPS assembly. int a = 1; int b = 2;...
Translate the following C code to MIPS assembly. int a = 1; int b = 2; if (a<b)           a=a+1; b = b + a; printf("The value of b is: %d", b); Translate the following C code to MIPS assembly. int a = 2; int b = 2; if (a<b)           a=a+1; else           a=a-1; b = b + a; printf("The value of b is: %d", b);
a+b+c=(abc)^(1/2) show that (a(b+c))^(1/2)+(b(c+a))^(1/2)+(c(a+b))^(1/2)>36
a+b+c=(abc)^(1/2) show that (a(b+c))^(1/2)+(b(c+a))^(1/2)+(c(a+b))^(1/2)>36
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c...
23. Given a = 5, b = 4, c = 2, evaluate the following: a) a//c b) a % b c) b **c d) b *= c 27. Given the following var_1 = 2.0 var_2 = "apple" var_3 = 'orange' var_4 = 4 Predict the output of the following statements or indicate that there would be an error. a) print (var_1) b) print (var_2) c) print ("var_3") d) print (var_1 / var_4) e) print (var_4 + var_3) f) print (var_2...
1.   What is the output of the following code: string s1 = “X”; string s2 =...
1.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s2; 2.   What is the output of the following code: string s1 = “X”; string s2 = “A” + s1 + “BC” + s1 + “DEF” + s1 + “G”; cout << s[0] + s[3]; 3.   What is the output of the following code: string s1 = “X”; string...
Write MIPS assembly code for the following C code. for (i = 10; i < 30;...
Write MIPS assembly code for the following C code. for (i = 10; i < 30; i ++) { if ((ar[i] > b) || (ar[i] <= c)) ar[i] = 0; else ar[i] = a; }
True or False) The following code will output "I was true". bool isGreater(string s1, string s2)...
True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; }
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the...
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use 3.14159 for pi. #03   If the user enters 2, the program should ask for the length and width of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT