Fork/Join - Divide & Conquer Flashcards

1
Q

What is the concept of divide and conquer?

A

Split a porblem into smaller subproblems, solve the task recursively for each of these and combine the results to get the final result.

1st step is always to divide the problem into smaller subproblems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is used to visualize the performance of a divide & conquer algorithm?

A

Task Graphs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the best framework for divide & conquer algorithms and what is the java library?

A

Fork/Join Framework and the library is java.util.concurrent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do we use the library?
what do we extend?
what do we override?
What do we call?

A
  • Instead of extending Thread, we extend RecursiveTask (with return value) or RecursiveAction (without return value)
  • Instead of overriding run, we override compute
  • Instead of calling start, we call fork
  • Instead of a topmost call to run, we create a ForkJoinPool and call invoke
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

We want to return a result what do we need to extend in the Fork / Join Framework?

A

We need to extend RecursiveTask<>

<> in these we put the datatype to be returned

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Implement the following example in code. See picture

A

See picture

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When we need to return something we extend RecursiveTask<>

What data Type can be put into the < > symbols?

A

Only wrapped data types of primitives. For example Integer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you find the minimum number of processors that are necessary to execute the task graph is the picture. And how many are there.

A

1) Critical path uses 1 processors
2) Go through the time intervals and figure out how many tasks are not being worked on at any given time
3) Use additional processors to do this but make sure you reuse the ones already added

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the maximum overall speedup that can be achieved by parallelism on a task graph how do you calculate it?

A

Sp = T1 / Tp

Tp here is the minimum number of processors in this case. Find out what the minimum number is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

See the picture below. How do we fill the blanks when awaiting a number to be returned

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What aren’t we allowed to forget before applying the forking to code?

A

The Base Case see picture

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does .fork() do?

A

In practice, this means that the framework first “forks”, recursively breaking the task into smaller independent subtasks until they are simple enough to be executed asynchronously.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does .join() do?

A

After that, the “join” part begins, in which results of all subtasks are recursively joined into a single result, or in the case of a task which returns void, the program simply waits until every subtask is executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the basic structure of the fork/join problem? Use words

A

if (my portion of the work is small enough)
do the work directly
else
split my work into two pieces
invoke the two pieces and wait for the results

How well did you know this?
1
Not at all
2
3
4
5
Perfectly