Csc 750 More Midterm Review Questions

CSc 750 More Midterm Review Questions

Chapter 1

-  Multiple choice
Q) Which is not the locking-mechanism for parallel processing?
a) mutex
b) spinlock
c) deadlock
d) livelock

-  true/false
Q) The default thread attributes include “Detached Thread” property.
A) false
< ppt page >

-  short answer or code
Q) What’s the difference “heavyweight” with “lightweight(thread)”?
A) Process – completely separate program with vars, stack, memory allocation.
Thread – Shares the same memory space & global data, thread-private-structure : stack & IP.
< ppt page >

-  fill in the blank
The routine ( pthread_join() ) waits for one specific thread to terminate.
< ppt page >

Short answer:

What is the motivation for parallel computing?

Answer (slide 9):

Faster computation, fault tolerance, larger available memory

T/F:

The maximum speedup possible from p processors is p.

Answer (slides 20-24)

False, superlinear speedup is possible in some cases.

Fill in the blank:

The two principle types of parallel computers are ______memory and ______distributed memory.

Answer (slide 27):

shared, distributed (in either order)

Multiple Choice:

Which of the following is not an advantage of cluster computing?

a)  able to use commodity hardware

b)  shared memory access

c)  new processors can be integrated when available

d)  existing or modified software may be used

Answer (slide 51)

b

Chapter 8

-  Multiple choice
Q) Which problems are adequate to use Parallel computing?
a) whether forecasting
b) Matrices multiplication
c) Modeling DNA structures
d) Modeling astronomical bodies
A) a,b,c,d
< ppt page 3 >

-  true/false
Q) Parallel program with n-processors is always n-times faster than serial program with 1-processor.
A) False
< ppt page 9 >

-  short answer or code
Q) What’s the main advantage and disadvantage of using Cluster Computing?
adv – We can get high performance using available PCs at low cost
disadv – Somebody can shutdown one PC and this can mess up the whole computation.
< ppt page 52 >

-  fill in the blank
Two principla types are ( shared memory ) multiprocessor and
( Distributed memory ) multicomputer.
< ppt page27 >

1.  In concurrent programming a _____ is a piece of code that accesses a shared resource (data structure or device) that must not be concurrently accessed by more than one thread of execution.

A critical section (p 240) (with help from Wikipedia)

2.  Deadlock can be eliminated between two processes accessing more than one shaed resource if both processes make requests first for one resource and then for the other.

A T (slide 40)

3.  Describe Bernstein's Conditions for dependency analysis.

A

For two processes P1 and P2 to be executed simultaneously, inputs to process P1 must not be part of outputs of P2 , and inputs of P2 must not be part of outputs of P1 ; i.e.,

I 1 Ç O 2 = f

I 2 Ç O 1 = f

where f is an empty set. The set of outputs of each process must also be different; i.e.,

O 1 Ç O 2 = f

If the three conditions are all satisfied, the two processes can be executed concurrently.

(p 250)

4. Which of the following is true for semaphores.

a) A semaphore, is a positive integer, including zero, operated upon by two operations named P and V.

b) A P operation, P(s), waits until s is greater than zero and then decrements s by one and allows process to continue.

c) A V operation, V(s), increments s by one to release one of the waiting processes (if any).

d)  All of the above

A. d (slide 42)

Short Answer:

Explain the difference between concurrency and parallelism.

Answer (slides 4-5):

Concurrent: several processes are executing at the same time (may be actually the same time or a simulation)

Parallel: simultaneous execution of the same task on multiple processors

Parallelism is always concurrency, but concurrency may not always be parallelism.

T/F:

Forked child processes (using the UNIX fork system command) each have a shared copy of the parent process’s variables.

Answer (slide 13):

False, each child process has its own copy of the parent’s variables.

Multiple Choice:

Which of the following is not shared among threads?

a)  global variables

b)  stack

c)  heap

d)  code

Answer (slide 17):

b – each thread has its own stack

Fill in the blank:

System calls or library routines are called ______if they can be called from multiple threads simultaneously and always produce correct results.

Answer (slide 27):

thread safe

More on Pthreads

-  Multiple choice
Q) Property of Programming in Shared Address space.
a) All memory is accessible to all processors
b) threads assum all memory is global
c) Hard to programming than using PVM
d) Use message-passing method usually.
< ppt page 2 >

-  true/false
Q) Threads support faster memory manipulation.
A) true
< ppt page 2>

-  short answer or code
Q) Why use Threads?
A) We can improve the performance using scheduling and Load Balancing.
SW Portability + Latency Hiding.
Easier to use than in MPI & PVM
Furthermore POSIX threads is standard.
< ppt page 8-10>

-  fill in the blank
Thread creation can ( preempt ) its creator on a single processor system.
< ppt page 13 >

Multiple Choice:

Which of the following is not a reason to use threads?

a)  latency hiding

b)  load balancing

c)  improved reliability

d)  portability to serial machines

Answer (slides 8-10—More on Threads):

c – threads generally reduce reliability

T/F:

Threads free the programmer from explicit scheduling and load balancing.

Answer (slide 8—More on Threads):

true – scheduling and load balancing are performed by the OS when using threads

Short Answer:

Explain when it would make sense to use PThreads instead of a message-based programming model.

Answer (slides 2,10):

PThreads are designed for shared-memory multi-computers. Using PThreads in these scenarios is usually more efficient than message-based programming models like MPI, since data can be accessed by all processors without needing to copy it across slow interconnects.

Fill in the blank:

Threads are known as ______.

Answer (slide 2):

lightweight processes

Still More on Pthreads

-  Multiple choices
Q) Which is true for Condition-variable?
a) A condition variable always has a mutex with it.
b) A single condition variable may be associated with more than one predicate.
c) If predicate becomes true, condition variable can signal only one thread.
d) condition wait function is pthread_cond_wait()
< ppt page 14 >

-  true/false
Q) Locking mechanism is used only for thread programming.
A)false (e.g. file locking)
< >

-  short answer or code
Q) Why use “Read-Write” locks ?
A) Usually data-structure is read frequently but written infrequently.
< ppt page 24 >

-  fill in the blank
Locks represent ( serialization points ) since critical sections must be executed by threads one after the other.
< ppt page 11 >

Short Answer:

Why might we be forced to use mutual exclusion when dealing with threads? Give an example with pseudo-code.

Answer (slide 2—Still More on Threads):

When multiple threads attempt to manipulate the same data item, the results can often be incoherent if proper care is not taken to synchronize them.

Example:

if (my_cost < best_cost)

best_cost = my_cost;

Assume that there are two threads, the initial value of best_cost is 100, and the values of my_cost are 50 and 75 at threads t1 and t2.

Depending on the schedule of the threads, the value of best_cost could be 50 or 75!

Fill in the blank:

In many applications, a data structure is ______frequently but ______infrequently. For such applications, we should use ______.

Answer (slide 24—Still More on Threads):

read, written, read-write locks

Multiple Choice:

Which of the following should be relied on when designing asynchronous programs.

a)  scheduling assumptions when exchanging data

b)  liveness of data based on scheduling

c)  the ability of a mutex to provide mutual exclusion

d)  scheduling as a means of synchronizations

Answer (slide 38):

c

T/F:

Barriers are directly supported by PThreads.

Answer (slide 34-35):

false—PThreads does not support barriers directly, however it is possible to build your own using PThreads

1. Critical segments in Pthreads are implemented using ____ locks.

A. mutex (slide 3)

2. A normal mutex deadlocks if a thread that already has a lock tries a second lock on it.

A. True (slide 10)

3. (?? too much memorization??) Write the code to implement the consumer routine of a producer-consumer solution using mutexes and condition variables.

A. void *consumer(void *consumer_thread_data) {

while (!done()) {

pthread_mutex_lock(&task_queue_cond_lock);

while (task_available == 0)

pthread_cond_wait(&cond_queue_full,

&task_queue_cond_lock);

my_task = extract_from_queue();

task_available = 0;

pthread_cond_signal(&cond_queue_empty);

pthread_mutex_unlock(&task_queue_cond_lock);

process_task(my_task);

}

}

(slide 18)

4. Which of the following is true:

a) A condition variable allows a thread to block itself until specified data reaches a predefined state.

b) A single condition variable may be associated with more than one predicate.

c) A condition variable always has a mutex associated with it.

d) all of the above.

A. d (slide 14)