Examlex

Solved

Consider the Following Code That Adds Two Matrices a and B

question 10

Essay

Consider the following code that adds two matrices A and B and stores the result in a matrix C:
for (i= 0 to 15) {
for (j= 0 to 63) {
C[i][j] = A[i][j] + B[i][j];
}
}
If we had a quad-core multiprocessor, where the elements of the matrices A, B, C are stored in row major order, which one of the following two parallelizations is better and why ? What about when they are stored in column major order ?
(a) For each Pk in {0, 1, 2, 3}:
for (i= 0 to 15) {
for (j= Pk*15 + Pk to (Pk+1)*15 + Pk)
{
// Inner Loop Parallelization C[i][j] = A[i][j] + B[i][j];
}
}
(b) For each Pk in {0, 1, 2, 3}:
for (i= Pk*3 + Pk to (Pk+1)*3 + Pk) {
// Outer Loop Parallelization for (j= 0 to 63) {
C[i][j] = A[i][j] + B[i][j];
}
}


Definitions:

Pulmonary Embolism

A sudden blockage in one of the pulmonary arteries in the lungs, often due to blood clots that travel from the legs or other parts of the body.

Early Ambulation

The practice of encouraging patients to walk and move around soon after surgery to promote faster recovery.

Deep Breathing

A relaxation technique that involves inhaling slowly and deeply through the nose, filling the lungs, and then exhaling gradually to reduce stress and increase oxygen levels in the blood.

Chronic Obstructive Pulmonary Disease (COPD)

A group of lung diseases that block airflow and make it difficult to breathe, including conditions like emphysema and chronic bronchitis.

Related Questions