Parallel Programming: Process and Threads
Parallel Programming: Process and Threads
Parallel Programming: Process and Threads
Concurrency
Processes
Threads
MPI
OpenMP
Concurrency
• A property of computing systems in which several tasks are executing simultaneously
• Tasks are in progress at the same time
• Maybe running on one single processor, maybe on more than one
• Typical examples: web server, multiple programs running in your desktop
Concurrency
Time-sharing or multitasking systems
• Process ID
• Process status
• CPU registers (PC,...)
• Open files, memory management,...
• Stores context to ensure a process can continue its execution properly after
switching by restoring this context.
Thread
• Basic unit of CPU utilization
-Flow of control within a process
• A thread includes
-Thread ID
-Program counter
-Register set
-Stack
• Shares resources with other threads within the same process
-Text section
-Data section
-Other OS resources (open files,...)
Thread
Benefits of multi-threading
• Responsiveness
- An interactive application can keep running even if a part of it is blocked or
performing a compute-intensive operations.
- A server can accept requests while processing existing ones
• Resource sharing: code and data shared among threads
• Speed: cheap creation and context switching
Cost of multi-threading
Performance overhead:
-Synchronization
-Access to shared resources
Hazards
Deadlocks:
-A thread enters a waiting state for a resource held by another one, which in
turns is waiting for a resource by another (possible the first one).
Race conditions:
-Two or more threads read/write shared data and the result depends on the
actual sequence of execution of the threads.
Not deterministic:
-Harder to debug (hard to reproduce errors)
Single program Multiple Data
THANK YOU!!