Week 4: Parallel Programming Flashcards
How does memory work in multicore processors?
Each core has L1 cache.
In some processors, each core has L2, in others, L2 is shared.
All cores share L3 cache and DDR3 DRAM (main memory - via comm bus).
What is data coherence?
Quality of being logical and consistent.
Data must remain coherent.
Name a coherence mechanism?
A write to a memory location must cause all other copies of this location to be invalidated or deleted from the caches they are in.
Describe MSI Protocol?
Each cache line is labelled with a state.
M: Cache block has been modified.
S: Caches may be sharing block.
I: Cache block is invalid.
How should you program multicore platforms?
1: Program directly targets processor cores (error-prone)
2: Concurrency platform: Abstracts cores, handles synchronization and communication protocols, performs load balancing
What are the 3 ways in which a server may deal with a client?
Sequential: Process one client at a time, other clients may have to wait a while
Concurrent: Process multiple clients at the same time
Parallel: Process multiple tasks at the same time
Parallel tasks are always concurrent, but concurrent tasks may not be parallel.
What is a thread?
The smallest sequence of instructions that can be managed independently by the scheduler.
Execute concurrently in a stack region, each with it’s own copy of stack related info.
Share heap, global data and other resources (opened files etc.)
What is a possible solution for multiple parameters for a function on a pthread?
Pack parameters into a compound object, with wrapper function.
Pass compound into function.
What is a race condition?
When two+ threads need to perform operations on same data, but result of computation depends on order of operations.
Mutual exclusion prevents this.
What are 3 synchronization methods in pthreads?
Join: Blocking function, waits for thread to finish.
Mutual Exclusion: Objects that lock and unlock, section between lock and unlock is the critical section. Can result in deadlock (trylock).
Condition variables: Synchronize based on value of data, thread waits until data is a certain value.
Why is a mutex needed with a condition variable?
Signal (only checked in waiting state) may arrive before Thread 1 enters the waiting state - deadlock.
What are read-write locks?
Lock functions for read and read-write.
Multiple threads can read (if no thread is writing) but only one thread can write.