Analyze the work and span of your code


Problem

Another matrix operation is matrix-vector multiplication, in which a matrix is multiplied by an array to produce another array. Consider the following serial implementation of this operations (M is a two-dimensional input array, x is a one-dimensional input array, and y is a one-dimensional output array):

for(int i=0; i < n; i++) {
y[i] = 0;
for(int j=0; j < n; j++)
y[i] = y[i] + M[i][j] * x[j];
}

Note the doubly-nested loop.

1. Use either a parallel for loop or spawn and sync to parallelize the iterations of the outer loop (controlled by i). The inner loop should be unchanged. Be sure that you do not introduce any race conditions. Analyze the work and span of your code.

2. Use either a parallel for loop or spawn and sync to parallelize the iterations of the inner loop (controlled by j). The outer loop should be unchanged. Be sure that you do not introduce any race conditions. Analyze the work and span of your code.

For each part, give the modified code (using spawn and sync) and explain how you calculated the work and span.

Request for Solution File

Ask an Expert for Answer!!
Data Structure & Algorithms: Analyze the work and span of your code
Reference No:- TGS03256171

Expected delivery within 24 Hours