Search for question
Question

Assignment 2 Parallelize the following sequential code by parallelizing the two for-loops indicated. Input: n and matrix[n][n], where the matrix [n] [n] is an n x n matrix with non-negative elements and on the diagonal. Output: array output[n]. void HW2(int n, int **matrix, int *output) { int i, j, count, tmp, leastVal, leastPos, *done; } done = (int *) calloc( n, sizeof(int)); for(i=0; i<n; i++) { done[i] = 0; output[i] = matrix[0][i]; } done [0] = 1; count = 1; while( count < n ) { leastVal 987654321; for(i=0; i<n; i++) { // <-- parallelize this loop tmp = output[i]; if (!done[i]) && (tmp < leastVal) ) { leastVal= tmp; leastPosi; } } done [leastPos] = 1; count++; for(i=0; i<n; i++) { // <-- parallelize this loop if(!(done[i])) output[i] = min (output[i], leastVal + matrix [leastPos] [i]); End of while ***/ } }.... free (done);

Fig: 1