Parallel Programming in Java Quiz

Parallel Programming in JavaQuiz Answer. In this post you will get Quiz & Assignment Answer Of Parallel Programming in Java

 

Parallel Programming in Java Quiz

Offered By ”Rice University”

Enroll Now

Week- 1

Programming Assignment: Mini Project 1 Submission

Download

 

 

Module 1 Quiz

1.
Question 1
Consider the following parallel pseudo-code that uses the async-finish notation for task creation and termination introduced in Lecture 1.1:

Which of the following statements are true? Check all that apply

1 point

  • A. S2 can potentially execute in parallel with S3
  • B. S2 can potentially execute in parallel with S4
  • C. S1 can potentially execute in parallel with S4
  • D. S1 can potentially execute in parallel with S5

2.
Question 2
Consider the following parallel pseudo-code that uses the async-finish notation for task creation and termination introduced in Lecture 1.1::

Check all that apply

1 point

  • A. async S2;
  • B. async finish S2;
  • C. S2;
  • D. finish S2;

3.
Question 3
Consider the computation graph in Figure 1 below (where black, green and red arrows represent continue, fork, and join edges respectively, as explained in Lecture 1.3).

Figure 1.

What is the total WORK for the computation graph in Figure 1? Please enter an integer.

1 point
Enter answer here

22

4.
Question 4
What is the SPAN or CPL (critical path length) for the computation graph in Figure 1? Please enter an integer.

1 point
Enter answer here

8

5.
Question 5
Consider the computation graph in Figure 2 below (where black, green and red arrows represent continue, fork, and join edges respectively, as explained in Lecture 1.3).

Figure 2.

For the computation graph in Figure 2, identify which of the following paths are critical paths?

Check all that apply

1 point

  • A. S1 \rightarrow→ S2 \rightarrow→ S3 \rightarrow→ S4
  • B. S1 \rightarrow→ S5 \rightarrow→ S8
  • C. S1 \rightarrow→ S5 \rightarrow→ S6 \rightarrow→ S8
  • D. S1 \rightarrow→ S5 \rightarrow→ S7 \rightarrow→ S8
  • E. S1 \rightarrow→ S9

6.
Question 6
Recall that the concepts of WORK and SPAN were introduced in Lecture 1.3. Consider the pseudo-code in Figure 3 below for adding two lower triangular matrices (square matrices in which all the elements above and including the (0,0) to (n,n) diagonal are zero), in which each execution of the statement A[i][j] = B[i][j] + C[i][j]; represents one unit of work in the computation graph, WORK(S5) = 1:

Figure 3.

The total WORK performed by the program in Figure 3 (after it completes execution), in terms of nn equals __________.

1 point

  • A. 1
  • B. n-1n−1
  • C. \frac{n(n-1)}{2}2n(n−1)
  • D. None of the above

7.
Question 7
The Critical Path Length (CPL) of the program in Figure 3 in terms of nn equals __________.

1 point

  • A. 1
  • B. n-1n−1
  • C. \frac{n(n-1)}{2}2n(n−1)
  • D. None of the above

8.
Question 8
Recall that Ideal Parallelism was also defined in Lecture 1.3. The Ideal Parallelism of the program in Figure 3, as a function of nn equals _________.

Figure 3

 

  • A. 1
  • B. \frac{n}{2}2n
  • C. n-1n−1
  • D. None of the above

9.
Question 9
Recall that multiprocessor schedules were introduced in Lecture 1.4. Though, by default, we focus on schedules with no unforced idleness in this course, this question will allow for all possible legal schedules, including those that may have unforced idleness, i.e., schedules in which a process may be idle even if there is work that is available to be executed.

Consider the computation graph shown below in Figure 4. Select the statement below that is true about legal schedules for this graph on 3 processors.

Figure 4.

1 point

  • A. There exists a legal schedule in which node C can start execution before node B starts.
  • B. There exists a legal schedule in which node P can complete execution before node C starts.
  • C. There exists a legal schedule in which nodes J, L, O, Q can all be scheduled at the same time.

10.
Question 10
For an arbitrary computation graph and its schedule on P processors, which of the following relationships must always hold between Speedup(P) and Ideal Parallelism?

1 point

  • A. Speedup(P) < Ideal Parallelism
  • B. Speedup(P) ≤ Ideal Parallelism
  • C. Speedup(P) = Ideal Parallelism
  • D. Speedup(P) ≥ Ideal Parallelism
  • E. Speedup(P) > Ideal Parallelism

 

 

Week- 2

Programming Assignment: Mini Project 2 Submission

Download

 

 

Module 2 Quiz

1.
Question 1
Consider the following parallel
pseudo-code that use future tasks, as introduced in Lecture 2.1. Select the statement below which must be true for this code snippet.

1 point

A. S1
can run in parallel with S3.

B. S2 can run in parallel with S5.

C. S1, S2, and S4 can all run in parallel with each other

D. S2 can run in parallel with S4.

E. S4 can run in parallel with S5.

2.
Question 2
Which
of the following dependencies result from the following pseudo-code using futures (as introduced in Lecture 2.1)?

 

}
1 point

A. S3
depends on S2 having executed

B. S4 depends on S2 having executed

C. S2 depends on S4 having executed

D. S1 depends on S3 having executed

3.
Question 3
You can use futures in the Java Fork-Join framework (as discussed in Lecture 2.2) by
implementing which class?

1 point

A. RecursiveAction

B. RecursiveTask

C. FutureTask

D. Future

4.
Question 4
How do you retrieve the value from a future in the Java Fork-Join
framework (as discussed in Lecture 2.2) ?

1 point

A. Through the return value provided by explicitly calling a task’s compute() method.

B. By the return value of the fork() method of ForkJoinTask.

C. By the return value of the join() method of ForkJoinTask.

D. By the return value of the quietlyJoin() method of ForkJoinTask.

5.
Question 5
Consider the Pascal’s triangle implementation below, with a triangle containing R rows, with row i
containing i entries. A triangle with R rows would therefore have \frac{R(R + 1)}{2}
2
R(R+1)

total entries. Assuming a memoized parallelization strategy like the one below (and discussed in Lecture 2.3), how many futures would be created when computing Pascal’s triangle with R rows ?

 

1point

A. RR

B. 2 \times R2×R

C. R(R + 1)R(R+1)

D. \frac{R(R + 1)}{2}2R(R+1)

6.
Question 6
Based on the same Pascal’s triangle implementation above, if memoization and futures are used to compute a Pascal’s triangle of R rows, how many future get() calls must be made to compute the values for the R rows? Keep in mind the special cases of elements on the left and right edges of the triangle. You should ignore the get() calls on the second to last line (line 31) in the code example above; only consider the get()s necessary to compute the actual contents of the triangle.

1 point

A. R^2 – RR2−R

B. \frac{R(R + 1)}{2}
2
R(R+1)

C. R(R + 1)R(R+1)

D. 2 \times R2×R

7.
Question 7
Supposed you had a List of Integers in Java: [3, 6, 8, 2, 1,
0]. Which of the stream-based programs below would be equivalent to the provided
loop-based Java code? (Recall that Java streams were introduced in Lecture 2.4.)

1 point

A. input.filter(v -> v >= 3);

B. input.stream().filter(v -> v >= 3);

C. input.stream().filter(v -> v < 3);

D. input.stream().average();

8.
Question 8
Consider
a search algorithm that uses many tasks to examine the search space in
parallel. Every task that discovers a target value in the search space will set a global boolean flag to true (it is initialized to false). However, no task will ever read this global flag during execution, hence there will be no early exit of tasks. The flag will only be read after all tasks have terminated.

Such a program will exhibit
which of the following? (Recall that data races, functional determinism, and structural determinism were introduced in Lecture 2.5.)

1 point

A. Functional and structural determinism, and no data race

B. Functional and structural determinism, with a data race

C. Functional but not structural determinism, with a data race

D. Structural but not functional determinism, with a data race

9.
Question 9
Now consider another search algorithm that uses many tasks to examine the search space in
parallel. Each task increments a shared integer counter (e.g., count = count +1) when the search is
successful.

Such a program will exhibit
which of the following?

1 point

A. Functional and structural determinism, and no data race

B. Functional and structural determinism, with a data race

C. Functional but not structural determinism, with a data race

D. Structural but not functional determinism, with a data race

10.
Question 10
Finally, consider a variation of Question 8 in which every task that discovers a target value in the search space will set a shared global int variable to the location of the target value that was found (the variable is initialized to -1). However, no task will ever read the int variable during execution, hence there will be no early exit of tasks. The variable will only be read after all tasks have terminated. Note that, in general, there can be multiple possible locations for the target value, and we assume that any target location is acceptable in the final value of the int variable.

Such a program will exhibit which of the following?

1 point

A. Functional and structural determinism, with a data race

B. Functional and structural determinism, and no data race

C. Benign non-determinism, with a data race.

 

 

Week- 3

Programming Assignment: Mini Project 3 Submission

Download

 

 

Module 3 Quiz

1.
Question 1
Given
the following sequential code fragment and assuming N > 2, which of the possible
approaches using forall loops (pseudocode introduced in Lecture 3.1) will produce functionally equivalent values in the arrays x and y? Note that a range like “i : [0 : N]” in the forall pseudocode is assumed to be an inclusive range that includes both the lower bound (0) and the upper bound (N).

1234
for (i=0; i <= N; i = i + 1) {
x[i] = x[i] + y[i];
y[i+1] = w[i] + z[i];
}
1 point

A.

 

B.

 

C.

 

2.
Question 2
Given
the following sequential code fragment:

12345
c = 0;
for (i = 0; i <= N; i++) {
c = c + a[i];
}
println(“c = ” + c);
and the following attempt to parallelize the fragment using a forall loop (introduced in Lecture 3.1):

12345
c = 0;
forall (i : [0 : N]) {
c = c + a[i];
}
println(“c = ” + c);
Which of the following statements is true, related to the determinism properties introduced in Lecture 2.5?

1 point

A. The
parallel code exhibits data races and structural determinism, but not
functional determinism.

B. The
parallel code exhibits data races and functional determinism, but not
structural determinism.

C. The
parallel code exhibits functional and structural determinism, and no data
races.

D. The
parallel code exhibits data races, but not functional or structural
determinism.

3.
Question 3
Assume that forall is implemented using a finish scope containing a sequential for loop in which each iteration is implemented as a parallel async task.

Given the following two versions of code that attempt to
parallelize a matrix multiplication computation (introduced in Lecture 3.2). We now use a slightly different notation for forall loops that corresponds to actual code (in the PCDP library) rather than pseudocode. The lower and upper bound parameters for the forall constructs still represent inclusive ranges.

Which of the following statements are true for Versions 1 and 2?

1 point

A. Version 2 will create fewer finish scopes than
version 1

B. Version
2 will create fewer async tasks than version 1

C. Version
1 and Version 2 will perform the same total number of multiply operations (from line 5 in version 1, and line 6 in version 2)

D. Version
2 will have a longer critical path than Version 1, if we assume that each multiply operation corresponds to 1 unit of work

4.
Question 4
Recall that barriers were introduced in Lecture 3.3. True or false, the following code snippet that uses barriers can exhibit a data race?

 

1 point

True

False

5.
Question 5
Recall that barriers were introduced in Lecture 3.3. Which of the choices is a legal ordering of the
print statements in the code snippet below?

1234567
forall (0, 1, (i) -> {
println(“Hello from iteration “ + i);
barrier;
println(“Continuing iteration “ + i);
barrier;
println(“Finishing iteration “ + i);
});
1 point

A.

Hello from iteration 0

Continuing iteration 0

Finishing iteration 0

Hello from iteration 1

Continuing iteration 1

Finishing iteration 1

B.

Hello from iteration 0

Hello from iteration 1

Continuing iteration 0

Finishing iteration 0

Continuing iteration 1

Finishing iteration 1

C.

Hello from iteration 1

Hello from iteration 0

Continuing iteration 1

Continuing iteration 0

Finishing iteration 0

Finishing iteration 1

6.
Question 6
Consider
the code below, and recall that barriers were introduced in Lecture 3.3. Which of the choices is a functionally equivalent barrier-based
parallel program?

1 point

A.

12345
forall (0, 3, (i) -> {
sum[i] = i;
barrier;
sum[i] += sum[i + 1];
});

B.

123
forall (0, 3, (i) -> {
sum[i] = i + sum[i + 1];
});

C.

12345
forall (0, 3, (i) -> {
sum[i] = sum[i + 1];
barrier;
sum[i] += i;
});

 

7.
Question 7
What was the primary benefit of using barriers
in the one-dimensional iterative averaging example studied in Lecture 3.4?

1 point

A. Barriers were necessary for the correct implementation
of one-dimensional iterative averaging. It could not be implemented without
them.

B. Fewer tasks had to be created when we made use of
barriers, leading to lower overhead

C. Barriers reduced the amount of non-determinism caused
by data races in the version of the code that did not use barriers.

D. Barriers led to the creation of more tasks, allowing
the parallel runtime more flexibility in scheduling tasks.

8.
Question 8
Which of the following is true about iteration grouping/chunking for parallel loops (as introduced in Lecture 3.5)?

1 point

A. Loop chunking increases the amount of work performed by the parallel loop and reduces the number of tasks created.

B. Loop chunking reduces the amount of work performed by the parallel loop and reduces the number of tasks created.

C. Loop chunking does not affect the amount of work
performed by the parallel loop and increases the number of tasks created.

D. Loop chunking does not affect the amount of work
performed by the parallel loop and reduces the number of tasks created.

9.
Question 9
Given the sequential code snippet below:

123
for (i = 1; i <= 100; i++) {
a[i] = b[i] + c[i + 10];
}
And four parallel versions of the above code snippet, which of the provided parallel versions is correct?

A.

1234
// No chunking/grouping is performed in this version
forall (1, 100, (i) -> {
a[i] = b[i] + c[i + 10];
});
B.

1234
// Chunking is performed, but the chunk size is unknown
forallChunked (1, 100, (i) -> {
a[i] = b[i] + c[i + 10];
});
C.

12345
chunkSizeDivides100 = 10;
// Chunk size is provided in the third parameter below
forallChunked (1, 100, chunkSizeDivides100, (i) -> {
a[i] = b[i] + c[i + 10];
});
D.

12345
chunkSizeDoesNotDivide100 = 23;
// Chunk size is provided in the third parameter below
forallChunked (1, 100, chunkSizeDoesNotDivide100, (i) -> {
a[i] = b[i] + c[i + 10];
});
1 point

A. Snippets
A, B, and C are correct but not D.

B. Snippets
A and C are correct but not B and D.

C. Only
snippet C is correct.

D. All
of the parallel snippets are correct.

10.
Question 10
In general, recalling the contents of Lecture 3.5, what is a good heuristic for setting
the number of chunks in a forall parallel loop?

1 point

A. The number of chunks should be similar to the number of
hardware cores in the platform.

B. The number of chunks should group together as many
iterations in to a single chunk as there are hardware cores in the platform.

C. The number of chunks should be an order of magnitude
smaller than the number of loop iterations.

D. The number of chunks should always be between 10 and 20.

 

 

Week- 4

Download

Download

 

 

 

1.
Question 1
Based on the simple code example in the Topic 4.2 lecture video, which of the following are true of phasers?

1 point

A. Using phasers can help to reduce both the critical path
and work of this parallel program.

B. Using phasers can help to reduce the critical path but
does not affect the work of this parallel program.

C. Using phasers increases the work of this parallel
program but does not affect the critical path.

D. Using phasers increases both the critical path and work
of this parallel program.

2.
Question 2
True or False, if a given thread has hit a next and is now in wait mode, then we can state that at least some other threads have also hit a next and have done a signal of the phaser.

1 point

True

False

3.
Question 3
Given three tasks and three phasers (ph0, ph1, and ph2), which
of the following code snippets uses phasers to implement what is semantically a
barrier?

1 point

A.

1234567891011
// Task 0
ph0.signal();
ph0.wait();

// Task 1
ph1.signal();
ph1.wait();

// Task 2
ph2.signal();

B.

1234567891011
// Task 0
ph0.signal();
ph0.wait();

// Task 1
ph1.signal();
ph0.wait();

// Task 2
ph2.signal();

C.

1234567891011
// Task 0
ph0.signal();
ph1.wait();

// Task 1
ph1.signal();
ph2.wait();

// Task 2
ph2.signal();

D.

1234567891011121314
// Task 0
ph0.signal();
ph1.wait();
ph2.wait();

// Task 1
ph1.signal();
ph0.wait();
ph2.wait();

4.
Question 4
What is the primary benefit of using a phaser
over a barrier?

1 point

A. Using a phaser rather than a barrier always reduces the
critical path of a program.

B. Phasers allow for a more precise definition of the
dependencies in a parallel program, potentially exposing more parallelism.

C. The use of phasers guarantees data race freedom in multi-threaded Java programs.

D. The use of phasers guarantees deadlock freedom in multi-threaded Java programs.

5.
Question 5
True or False, a child task waiting on a phaser registered with the parent task will cause a deadlock if the parent task reaches the end of the scope in which the phaser is declared without issuing a signal.

1 point

True

False

6.
Question 6
Consider the example pipeline in the Topic 4.4 lecture video. If instead of using phasers we used barriers to implement synchronization between the pipeline stages, would you expect performance to improve, worsen, or remain the same?

1 point

Improve

Stay the same

Worsen

7.
Question 7
Given a hardware platform with C cores, assuming
an infinite supply of equally sized and immediately available inputs, assuming
that each pipeline stage can only process one input at a time, and assuming
that each pipeline stage takes the same amount of time, how would the speedup
of a parallel pipeline scale with the number of pipeline stages P? Ignore any
effects from warming up the pipeline.

1 point

A. The speedup achieved by a parallel pipeline would scale
linearly with P up until P == C, and then be limited to Cx speedup.

B. The speedup would always equal C, regardless of number
of stages.

C. The speedup achieved by a parallel pipeline would scale
linearly for all P.

D. Because each stage can only process one input at a
time, speedup would never go beyond 1x.

8.
Question 8
True or False, the order in which dataflow
asyncAwait tasks are launched affects the logical ordering of their execution.

1 point

True

False

9.
Question 9
Below are three code snippets, each containing the definition of a task from the same program. These tasks use three phasers (ph0, ph1, and ph2) to synchronize among themselves. Which of the code snippet options below using asyncAwait and data-driven futures f0, f1 and f2 is semantically equivalent to these three phaser-synchronized tasks?

12345
async {
A();
ph0.signal();
}

123456
async {
ph0.wait();
B();
ph1.signal();
}

123456
async {
ph1.wait();
C();
ph2.signal();
}

1 point

A.

123
asyncAwait(f1) { C(); f2.put(); }
asyncAwait(f0) { B(); f1.put(); }
async { A(); f0.put(); }

B.

123
asyncAwait(f0) { A(); f0.put(); }
asyncAwait(f1) { B(); f1.put(); }
asyncAwait(f2) { C(); f2.put(); }

C.

123
async { f0.put(); A(); }
asyncAwait(f0) { f1.put(); B(); }
asyncAwait(f1) { f2.put(); C(); }

D.

123
async { f0.put(); A(); }
asyncAwait(f0) { B(); f0.put(); }
asyncAwait(f0) { C(); f0.put(); }

 

10.
Question 10
True or False, there are computation graphs that
can be expressed using explicit waits on futures (e.g. A.get()) that cannot be
expressed using dataflow programming (i.e. asyncAwait(A)).

1 point

True

False