What is the likely result?

Given:
<code>
class Fibonacci extends RecursiveTask<Integer> {
final int n;
Fibonacci (int n) { this.n = n }
Integer compute () {
if (n <= 1)
return n;
Fibonacci f1 = new Fibonacci (n 1);
f1.fork; // Line X
Fibonacci f2 = new Fibonacci (n 2); // Line Y
return f2.compute() + f1.join;
}
}
</code>
Suppose that lines X and Y are transposed:
<code>
Fibonacci f2 = new Fibonacci (n 2); // Line Y
f1.fork; // Line X
</code>

What is the likely result?

Given:
<code>
class Fibonacci extends RecursiveTask<Integer> {
final int n;
Fibonacci (int n) { this.n = n }
Integer compute () {
if (n <= 1)
return n;
Fibonacci f1 = new Fibonacci (n 1);
f1.fork; // Line X
Fibonacci f2 = new Fibonacci (n 2); // Line Y
return f2.compute() + f1.join;
}
}
</code>
Suppose that lines X and Y are transposed:
<code>
Fibonacci f2 = new Fibonacci (n 2); // Line Y
f1.fork; // Line X
</code>

What is the likely result?

A.
The program produces the correct result, with similar performance to the original

B.
The program produces the correct result, with performance degraded to the equivalent of being single-threaded.

C.
The program produces an incorrect result

D.
The program goes into an infinite loop

E.
An exception is thrown at runtime

F.
The program produces the correct result, the better performance than the original.

Explanation:
The degree of parallelism is not changed. Functionality is the same.



Leave a Reply 0

Your email address will not be published. Required fields are marked *