Below you will find two sequential codes. Augment the code snippets with OpenMP pragmas if applicable. You have to make
Posted: Sun May 15, 2022 12:56 pm
Below you will find two sequential codes. Augment the code
snippets with OpenMP pragmas if
applicable. You have to make sure that no dependencies are broken
and thus the algorithm still
computes correct result. Please include all the necessary clauses
in the programs, including
the variable scope clauses. If the algorithm is parallelizable,
briefly discuss your parallelization
strategy. Otherwise, explain why it cannot be parallelized. Justify
your claims.
a)
// computes the product of an M x L matrix A
// with an L x N matrix B
double sum = 0;
for (i = 0; i < M; i++){
for (j = 0; j < N; j++){
sum = 0;
for (k = 0; k < L; k++){
sum += A[i*L + k] * B[k*N + j];
}
C[i*N + j] = sum;
}
}
b)
Repetitive Smoothing of a Vector
// v is a pre-initialized array of length N
// s is the smoothed version of v, pre-initialized with v
// M is the number of iterations
for(i = 0; i < M; i++){
for (j = 2; j < N-2; j++){
s[j] = 0;
for (k = -2; k < 3; k++){
s[j] += 0.2 * v[j+k];
}
}
for (j = 0; j < N; j++){
v[j] = s[j];
}
}
snippets with OpenMP pragmas if
applicable. You have to make sure that no dependencies are broken
and thus the algorithm still
computes correct result. Please include all the necessary clauses
in the programs, including
the variable scope clauses. If the algorithm is parallelizable,
briefly discuss your parallelization
strategy. Otherwise, explain why it cannot be parallelized. Justify
your claims.
a)
// computes the product of an M x L matrix A
// with an L x N matrix B
double sum = 0;
for (i = 0; i < M; i++){
for (j = 0; j < N; j++){
sum = 0;
for (k = 0; k < L; k++){
sum += A[i*L + k] * B[k*N + j];
}
C[i*N + j] = sum;
}
}
b)
Repetitive Smoothing of a Vector
// v is a pre-initialized array of length N
// s is the smoothed version of v, pre-initialized with v
// M is the number of iterations
for(i = 0; i < M; i++){
for (j = 2; j < N-2; j++){
s[j] = 0;
for (k = -2; k < 3; k++){
s[j] += 0.2 * v[j+k];
}
}
for (j = 0; j < N; j++){
v[j] = s[j];
}
}