Parallel and Distributed lec 8
Parallel and Distributed lec 8
Computing
COMP3139
Contents
• Parallelism algorithms
• Synchronization
• Synchronization mechanisms
• Challenges
• Best practices
• Data and work partitioning
PARALLELIZATION ALGORITHMS
LOOP PARALLELISM
3
PARALLELIZATION ALGORITHMS
LOOP PARALLELISM
4
PARALLELIZATION ALGORITHMS
PIPELINE PARALLELISM
5
PIPELINE PARALLELISM
• Example code
PARALLELIZATION ALGORITHMS
SPECULATIVE PARALLELISM
7
SPECUL ATIVE PARALLELISM
• EXAMPLE CODE
SYNCHRONIZATION
1. Mutex (Mutual Exclusion): A lock that ensures only one thread at a time
can access a shared resource or critical section of code.
• Example:
10
SYNCHRONIZATION MECHANISMS
2. Semaphores: A counter-based
synchronization mechanism that
controls access to a pool of resources.
• Useful when multiple threads need to
access limited resources (e.g.,
multiple readers/writers).
• Example: A semaphore with a count
of 3 would allow three threads to
access the resource simultaneously
before blocking others.
11
SYNCHRONIZATION MECHANISMS
12
• SYNCHRONIZATION MECHANISMS
Types:
Spinlocks: Threads continuously
check if a lock is available, useful in
situations where waiting times are
very short.
spinlock is a synchronization
mechanism used in operating
systems to protect shared resources
from single access by multiple
13
threads or processes.
• SYNCHRONIZATION MECHANISMS
Types:
• Read-Write Locks: Allows multiple
readers but only one writer at a
time.
• Read-write locks allow simultaneous
read access by many threads while
restricting write access to only one
thread at a time.
14
CHALLENGES ADDRESSED BY
SYNCHRONIZATION
15
CHALLENGES ADDRESSED BY
SYNCHRONIZATION
16
BEST PRACTICES FOR
SYNCHRONIZATION
17
DATA AND WORK PARTITIONING
1. Data Partitioning: Dividing the input data into chunks that can be
processed independently.
• This is simple but may not balance the load efficiently if some data
chunks are more compute-intensive than others.
19
DATA AND WORK PARTITIONING
20
DATA AND WORK PARTITIONING
2. Work Partitioning:
21
DATA AND WORK PARTITIONING
22
CHALLENGES IN PARTITIONING
23
THANK YOU