Name (print clearly): _________________________________________________
Student ID (print clearly; 1 digit per underline): _____ _____ _____ _____ _____ _____
CSE 231s Quiz 05: Parallel For Loop
For the code below, write equivalent code with async, finish, and a Java sequential for loop.
forall(0, n, (i) -> {
doSomething(i);
});
|
|
How many asyncs and finishes will execute for the code below:
forall(0, n, (i) -> {
forall(0, m, (j) -> {
doSomething(i, j);
});
});
|
async count: ________
finish count: ________
|
How many asyncs and finishes will execute for the code below:
forall2d(0, n, 0, m, (i, j) -> {
doSomething(i, j);
});
|
async count: ________
finish count: ________
|
Imagine square matrices a, b, and result of size 1000.
It follows that
n, m, and p below will each be 1000.
Imagine further that you are targetting creating 10 times as many tasks as
available processors.
int n = a.length;
int m = b[0].length;
int p = a[0].length;
The code below uses a single forall loop.
2a) Is this appropriate if you had 8 available processors? Yes / No
2b) What if you had 100 available processors? Yes / No
forall(0, n, (i) -> {
for (int j = 0; j < m; j++) {
for (int k = 0; k < p; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
});
The code below uses two (2) forall loops.
3a) Is this appropriate if you had 8 available processors? Yes / No
3b) What if you had 100,000 available processors? Yes / No
forall(0, n, (i) -> {
forall(0, m, (j) -> {
for (int k = 0; k < p; k++) {
result[i][j] += a[i][k] * b[k][j];
}
});
});
The code below uses three (3) forall loops.
4a) Is this appropriate if you had 8 available processors? Yes / No
4b) What if you had 100,000,000 available processors? Yes / No
forall(0, n, (i) -> {
forall(0, m, (j) -> {
forall(0, p, (k) -> {
result[i][j] += a[i][k] * b[k][j];
});
});
});