PVW SKRIPT Flashcards

1
Q

1) Define Parallel Programming.

2) Use example of summing up an array

A

1) Parallel programming is about using additional computational resources to solve a problem faster.

2) There is no sequential algorithm that can do better than O(n)
Suppose we had 4 processors, we could produce the result 4 times faster by partitioning the array into 4 segments, having each processor sum one segment and combining the results with an extra 3 additions.

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

Define concurrent programming.

A

Concurrent Programming is about correctly and efficiently controlling access by multiple threads to shared resources.

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

Define the programming model used in this lecture with key points use the following:

  • threads

- shared memory

A

We assume:

  • explicit threads with shared memory
  • two or more threads can communicate by writing and reading fields of the same object
  • a thread is like a running sequential programm that can create other threads
  • threads can see the same object because we assume memory is shared
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is scheduling?

A

There may be more threads than processors, than its up to the Java implementation, with help from the underlying operating system, to find a way to let the threads take turns, this is called scheduling.

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

Why are multithreaded programs harder to test and debug?

A

Because the are nondeterministic. Rerunning the same multithreaded programm, can give different results.

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

What are the different thread states in Java?

A
Non-Existing
New
Runnable
Blocked
Waiting
Terminated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define the Non-Existing state.

A

Non-Existing: Thread hasn’t been created yet

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

Define the New state.

A

New: Once a Thread object is created, it enters new state

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

Define the Runnable state.

A

Runnable: Once we call start() on the new thread object, it becomes eligible for execution and the system can start scheduling the thread as it wishes.

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

Define the Blocked state.

A

Blocked: When a thread attempts to acquire a lock it goes into a blocked state until it has obtained the lock, upon which it returns to a runnable state. In addition, calling the join() method will also transfer a thread into a blocked state.

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

Define the Waiting state.

A

Waiting: The thread can call wait() to go into a wating state. It will return to a runnable state once another thread calls notify() or notifyAll() and the thread is removed from the waiting queue.

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

Define the Terminated state.

A

Treminated: We can use interrupt() to signal the thread to stop its execution, it will then transfer to a terminated state. Also exiting the run() method is equicvalent to entering a terminated state.

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

What is a race condition?

A

A racecondition is a mistake in your program such that whether the program behaves correctly or not depends on the order in which the threads execute.

Race conditions are very common bugs in concurrent programming that, by definition, do not exist in sequential programming.

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

What are the two types of race conditions?

A

Bad Interleaving

Data Race

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

Define the race condition bad interleaving.

A

(High Level Race Condition) Erroneous programm behavior caused by an unfavorable execution order of a multithreaded algorithm

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

Define the race condition data race.

A

Also described as “simultaneous access error”
There are two kinds of data races:

1) When one threads reads an object field at the same moment another thread writes the same field
2) When on thread might write an object field at the same moment that another thread also writes the same field

17
Q

What are 3 alternatives to the programm model with share memory?

A

1) Message-passing
2) Dataflow
3) Data parallelism

18
Q

How does the distributed memory alternative programm model Message-Passing work?

A

Message-passing is the natural alternative to shared memory. In this model, explicit threads do not share
objects. For them to communicate, copies of data are exchanged as messages between processes. As
objects are not shared between individual threads, the issue of threads wrongly updating fields does not
occur. One does, however, have to keep track of the different data copies being passed around through
messages.

19
Q

What is the speedup of a program?

Use picture definition

A

The ratio of the sequential execution time to the time given P processors.

20
Q

What is the intuitive meaning to Amdaahl’s Law?

A

Speedup of a parallel programm can be greatly decreased due to overhead of caused by several issues intoduced by parallelizing a program.

Especially a sequential part of a program can drastically impact the maximum achievable speedup.

21
Q

What is the formula to Amdahl’s Law?

A
22
Q

What is the formula for Gustafson’s law?

A
23
Q

Define a thread

A
  • A set of instructions to be executed one at a time, in a specified order
24
Q

How to create Java Threads using java.lang.Runnable.

A
24
Q

How to create Java Threads using java.lang.Runnable.

A