Parallel and Distributed Computing Guide
Parallel and Distributed Computing Guide
rtyuiopasdfghjklzxcvbnmqwertyu
iopasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmqwertyuiopasdfghjkl
PARALLEL AND DISTRIBUTED COMPUTING
zxcvbnmqwertyuiopasdfghjklzxcv
10/9/2025
Laiba Arshad
bnmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqwe
rtyuiopasdfghjklzxcvbnmqwertyu
iopasdfghjklzxcvbnmqwertyuiopa
sdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmqwertyuiopasdfghjkl
zxcvbnmqwertyuiopasdfghjklzxcv
bnmqwertyuiopasdfghjklzxcvbnm
qwertyuiopasdfghjklzxcvbnmqwe
rtyuiopasdfghjklzxcvbnmrtyuiopa
Contents
Parallel and Distributed Computing....................................................................................................1
🔹 Introduction...................................................................................................................................1
⚙️1. Parallel Computing...................................................................................................................1
🌐 2. Distributed Computing.............................................................................................................2
🔸 Parallel vs Distributed Computing (Comparison)......................................................................2
🧾 Conclusion......................................................................................................................................3
⚙️Speedup and Amdahl’s Law.............................................................................................................3
🧠 What is Speedup?..........................................................................................................................3
🧩 Why Speedup is Important:..........................................................................................................4
📊 Types of Speedup:..........................................................................................................................4
⚡ Amdahl’s Law....................................................................................................................................4
🧮 Formula:.........................................................................................................................................5
💡 Example:........................................................................................................................................5
🚫 Amdahl’s Law Tells Us:................................................................................................................5
💻 Hardware Architectures in Parallel and Distributed Computing....................................................6
🧩 1. Multiprocessors (Shared Memory Architecture)........................................................................6
🔹 Definition:......................................................................................................................................6
💡 Simple Example:............................................................................................................................6
⚙️How It Works:...............................................................................................................................6
⚡ Advantages:....................................................................................................................................7
⚠️Disadvantages:...............................................................................................................................7
🧠 Example:........................................................................................................................................7
🌐 2. Networks of Workstations (Distributed Memory Architecture)................................................7
🔹 Definition:......................................................................................................................................7
💡 Simple Example:............................................................................................................................7
⚙️How It Works:...............................................................................................................................8
⚡ Advantages:....................................................................................................................................8
⚠️Disadvantages:...............................................................................................................................8
🧠 Example:........................................................................................................................................8
3. Clusters (Latest Hybrid Variation).................................................................................................8
🔹 Definition:......................................................................................................................................8
💡 Simple Example:............................................................................................................................9
⚙️How It Works:...............................................................................................................................9
⚡ Advantages:....................................................................................................................................9
⚠️Disadvantages:...............................................................................................................................9
🧠 Example:........................................................................................................................................9
🔍 Comparison Table...........................................................................................................................10
🏁 Conclusion........................................................................................................................................10
🧠 Software Architectures in Parallel and Distributed Systems (Detailed Explanation)..................10
🧵 1. Threads and Shared Memory.................................................................................................11
🧮 2. Processes and Message Passing...............................................................................................12
🧠 3. Distributed Shared Memory (DSM).......................................................................................13
🌐 4. Distributed Shared Data (DSD)..............................................................................................14
📊 Comparison Table...........................................................................................................................15
🧭 Relation to Hardware Architectures..........................................................................................15
⚙️Real-Life Analogy.......................................................................................................................15
⚙️Parallel Algorithms (In Detail)...............................................................................................................16
🧠 1. Introduction....................................................................................................................................16
💡 Simple Definition............................................................................................................................16
🧩 2. Need for Parallel Algorithms...........................................................................................................16
✅ Advantages of Using Parallel Algorithms:.......................................................................................16
🔍 3. Comparison: Sequential vs Parallel Algorithm................................................................................16
⚙️4. Structure of a Parallel Algorithm...................................................................................................17
🔹 Step 1: Problem Decomposition.....................................................................................................17
🔹 Step 2: Task Assignment.................................................................................................................17
🔹 Step 3: Communication..................................................................................................................17
🔹 Step 4: Synchronization..................................................................................................................17
🔹 Step 5: Combination.......................................................................................................................18
⚡ 5. Key Concepts in Parallel Algorithms...............................................................................................18
🧮 a) Speedup......................................................................................................................................18
🧩 b) Efficiency....................................................................................................................................18
⚖️c) Scalability..................................................................................................................................19
💬 d) Overhead....................................................................................................................................19
🧮 6. Types of Parallelism........................................................................................................................19
🧩 1. Data Parallelism..........................................................................................................................19
⚙️2. Task Parallelism.........................................................................................................................19
🔄 3. Pipeline Parallelism.....................................................................................................................20
💡 7. Examples of Parallel Algorithms......................................................................................................20
🧩 Example 1: Parallel Sum..................................................................................................................20
🧮 Example 2: Parallel Matrix Multiplication.......................................................................................21
🔄 Example 3: Parallel Merge Sort.......................................................................................................21
🔍 8. Performance Metrics......................................................................................................................21
🧠 9. Challenges in Designing Parallel Algorithms...................................................................................21
⚖️10. Relation to Amdahl’s Law............................................................................................................22
🔧 11. Relation to Hardware and Software Architectures.......................................................................22
🌍 12. Real-Life Applications....................................................................................................................22
🧾 13. Advantages and Disadvantages....................................................................................................23
✅ Advantages.....................................................................................................................................23
❌ Disadvantages.................................................................................................................................23
✨ 14. Conclusion....................................................................................................................................23
⚙️Concurrency and Synchronization (In Detail)........................................................................................23
🧠 1. Introduction....................................................................................................................................23
💡 2. What is Concurrency?.....................................................................................................................24
🔹 Simple Definition:...........................................................................................................................24
🧩 Example 1:......................................................................................................................................24
🧩 Example 2 (Programming Level):....................................................................................................24
⚙️3. Concurrency vs Parallelism............................................................................................................25
🧩 4. Benefits of Concurrency..................................................................................................................25
⚠️5. Problems in Concurrency..............................................................................................................25
💥 a) Race Condition............................................................................................................................25
⚰️b) Deadlock....................................................................................................................................26
🌀 c) Starvation....................................................................................................................................26
🧩 d) Inconsistency..............................................................................................................................26
🧭 6. What is Synchronization?...............................................................................................................26
🔹 Simple Definition:...........................................................................................................................26
🧩 Real-Life Example:..........................................................................................................................27
⚙️7. Types of Synchronization..............................................................................................................27
🧩 A. Process Synchronization.............................................................................................................27
🧩 B. Thread Synchronization..............................................................................................................27
🔧 8. Methods / Mechanisms of Synchronization...................................................................................28
🔹 1. Locks (Mutexes)..........................................................................................................................28
🔹 2. Semaphores................................................................................................................................28
🔹 3. Monitors.....................................................................................................................................28
🔹 4. Condition Variables.....................................................................................................................28
🔹 5. Message Passing.........................................................................................................................29
🧩 9. Critical Section Problem..................................................................................................................29
⚙️10. Synchronization in Parallel and Distributed Systems...................................................................29
🧮 11. Common Synchronization Problems and Solutions......................................................................30
💡 12. Example: Producer–Consumer Problem.......................................................................................30
⚙️Solution using Semaphores:..........................................................................................................30
🧠 13. Relation to Parallel Algorithms.....................................................................................................30
🧾 14. Advantages and Disadvantages....................................................................................................31
✅ Advantages.....................................................................................................................................31
❌ Disadvantages.................................................................................................................................31
✨ 15. Conclusion....................................................................................................................................31
⚙️Data and Work Partitioning...................................................................................................................31
🧠 1. Introduction....................................................................................................................................32
💡 Simple Definition:...........................................................................................................................32
🧩 Why Partitioning is Important........................................................................................................32
🔍 2. Two Main Types of Partitioning......................................................................................................32
🧩 3. Data Partitioning.............................................................................................................................32
📘 Definition:.......................................................................................................................................32
🧠 Example 1:......................................................................................................................................33
🧠 Example 2:......................................................................................................................................33
🔹 Advantages of Data Partitioning.....................................................................................................33
🔸 Disadvantages.................................................................................................................................33
🧮 Types of Data Partitioning..............................................................................................................34
⚙️4. Work (Task) Partitioning................................................................................................................34
📘 Definition:.......................................................................................................................................34
🧠 Example 1:......................................................................................................................................34
🧠 Example 2:......................................................................................................................................34
🔹 Advantages of Work Partitioning....................................................................................................35
🔸 Disadvantages.................................................................................................................................35
🔄 5. Comparison: Data vs Work Partitioning..........................................................................................35
⚙️6. Steps Involved in Partitioning........................................................................................................35
🧮 7. Load Balancing................................................................................................................................36
💬 8. Partitioning in Parallel Algorithms..................................................................................................36
🧩 9. Partitioning in Distributed Systems.................................................................................................36
🧠 10. Challenges in Partitioning.............................................................................................................37
🧾 11. Granularity in Partitioning............................................................................................................37
💡 12. Real-Life Examples........................................................................................................................37
⚖️13. Relation to Concurrency and Synchronization............................................................................38
✨ 14. Conclusion....................................................................................................................................38
🧠 Common Parallelization Strategies..................................................................................................38
🟦 1. Task Parallelism (Functional Parallelism).............................................................................38
🟩 2. Data Parallelism.......................................................................................................................39
🟨 3. Pipeline Parallelism.................................................................................................................39
🟧 4. Hybrid Parallelism..................................................................................................................40
🟥 5. Speculative Parallelism...........................................................................................................40
🟦 6. Loop-Level Parallelism...........................................................................................................41
⚙️Summary Table...............................................................................................................................41
💡 Connection to Previous Topics...................................................................................................42
🧠 Granularity in Parallel Computing..................................................................................................42
📘 Definition:....................................................................................................................................42
⚙️Understanding the Concept........................................................................................................42
🟩 1. Fine-Grained Parallelism............................................................................................................42
🟦 2. Coarse-Grained Parallelism........................................................................................................43
🟨 3. Medium-Grained (Mixed) Parallelism.......................................................................................44
🧩 Comparison Table...........................................................................................................................44
🔁 Relation with Other Topics.............................................................................................................45
💡 Real-Life Example.......................................................................................................................45
⚙️Load Balancing in Parallel and Distributed Computing..............................................................45
📘 Definition:....................................................................................................................................45
💡 Why Load Balancing is Important.............................................................................................45
🟩 Types of Load Balancing.................................................................................................................46
🟦 1. Static Load Balancing..............................................................................................................46
🟩 2. Dynamic Load Balancing........................................................................................................47
🧩 Load Balancing Techniques............................................................................................................47
⚖️Goals of Load Balancing.................................................................................................................48
🧠 Real-Life Example...........................................................................................................................48
🔁 Relation with Other Topics.............................................................................................................48
✅ Summary:.....................................................................................................................................48
⚙️Examples of Parallel Algorithms...................................................................................................49
🟩 1. Parallel Search.........................................................................................................................49
🟦 2. Parallel Sorting........................................................................................................................49
🟨 3. Parallel Matrix Multiplication................................................................................................50
🟧 4. Parallel Prefix Sum (Scan)......................................................................................................51
🟥 5. Parallel Graph Algorithms.....................................................................................................51
🟫 6. Parallel Image Processing.......................................................................................................52
🧩 Comparison Table...........................................................................................................................52
🔁 Relation with Previous Topics........................................................................................................52
💡 Simple Real-Life Example...........................................................................................................53
⚙️Shared-Memory Programming......................................................................................................53
📘 Definition:....................................................................................................................................53
💡 Key Idea:......................................................................................................................................53
🧩 Main Concepts in Shared-Memory Programming........................................................................53
🟩 1. Threads.....................................................................................................................................54
🟦 2. Pthreads (POSIX Threads).....................................................................................................54
🟨 3. Locks (Mutexes).......................................................................................................................55
🟥 4. Semaphores..............................................................................................................................55
🧠 Example: Using Shared Memory with Threads and Locks..........................................................56
🔁 Relationship with Other Topics......................................................................................................57
💡 Real-Life Example...........................................................................................................................57
✅ Summary..........................................................................................................................................57
🌐 Distributed-Memory Programming.........................................................................................................57
🧠 What is Distributed-Memory Programming?......................................................................................57
💡 Real-Life Example............................................................................................................................58
⚙️Key Features of Distributed-Memory Systems..................................................................................58
🔹 Message Passing.................................................................................................................................58
📘 Definition:.......................................................................................................................................58
🧩 Basic Operations in Message Passing..............................................................................................59
💻 Example (Concept):.........................................................................................................................59
🧩 MPI (Message Passing Interface)........................................................................................................59
📘 Definition:.......................................................................................................................................59
⚙️Main Features of MPI:...................................................................................................................59
💻 Basic MPI Functions........................................................................................................................59
💡 Simple Example (Conceptual).........................................................................................................60
🧠 Advantages of MPI..........................................................................................................................60
⚠️Disadvantages...............................................................................................................................60
🧩 PVM (Parallel Virtual Machine)...........................................................................................................60
📘 Definition:.......................................................................................................................................60
⚙️Main Features of PVM:..................................................................................................................61
💻 How PVM Works:............................................................................................................................61
🧠 Advantages of PVM........................................................................................................................61
⚠️Disadvantages...............................................................................................................................61
🔁 MPI vs. PVM Comparison....................................................................................................................61
✅ Summary.............................................................................................................................................62
💡 Real-World Examples......................................................................................................................62
💻 Other Parallel Programming Systems......................................................................................................62
🧠 1. Distributed Shared Memory (DSM)................................................................................................62
📘 Definition:.......................................................................................................................................62
💡 How It Works..................................................................................................................................63
⚙️Advantages....................................................................................................................................63
⚠️Disadvantages...............................................................................................................................63
🧠 Example:.........................................................................................................................................63
🌐 2. Aurora: Scoped Behavior and Abstract Data Types........................................................................63
📘 Definition:.......................................................................................................................................63
💡 Key Concepts:.................................................................................................................................64
⚙️Advantages of Aurora....................................................................................................................64
🧠 Example (Conceptual):....................................................................................................................64
🏢 3. Enterprise: Process Templates........................................................................................................64
📘 Definition:.......................................................................................................................................64
💡 Key Idea:.........................................................................................................................................65
⚙️How It Works:................................................................................................................................65
🧩 Advantages:....................................................................................................................................65
🧠 Example:.........................................................................................................................................65
🔬 4. Research Topics in Parallel and Distributed Systems......................................................................65
✅ Summary.............................................................................................................................................66
Parallel and Distributed Computing
🔹 Introduction
In today’s world, computers need to process a huge amount of data and perform many tasks very
quickly. To achieve this, instead of depending on a single processor, we divide the work among
multiple processors or even multiple computers.
This idea is known as Parallel and Distributed Computing.
🟢 Definition:
Parallel computing means using multiple processors (or cores) inside a single computer to
perform many tasks at the same time.
Each processor works on a different part of a problem, and all processors work together to get
the final result faster.
🧩 Example:
💡 How it Works:
🌐 2. Distributed Computing
🟢 Definition:
Distributed computing means using many computers (connected through a network) to work
together on a common task.
Each computer works on a part of the problem and shares results with others.
🧩 Example:
💡 How it Works:
🧾 Conclusion
Both Parallel and Distributed Computing are used to make computers more powerful and
faster.
We use them when we need high performance, large data handling, or faster results, but we
must handle their complexity and costs carefully.
🧠 What is Speedup?
🔹 Definition:
Speedup tells us how much faster a program runs when we use multiple processors compared
to just one processor.
💡 Simple Example:
📊 Types of Speedup:
1. Linear Speedup:
If doubling the processors halves the execution time.
Example: 1 processor → 10 min, 2 processors → 5 min.
👉 Perfect condition (rare in real life).
2. Sub-linear Speedup:
When adding more processors doesn’t fully double the speed.
Example: 1 processor → 10 min, 2 processors → 6 min.
👉 Common in real systems (because of communication and synchronization delays).
3. Super-linear Speedup:
Sometimes speedup is even better than expected (rare case).
Example: 1 processor → 10 min, 2 processors → 4 min.
👉 Happens due to better use of memory or caching.
⚡ Amdahl’s Law
🔹 Definition:
Amdahl’s Law tells us that no matter how many processors we use, the maximum speedup is
limited by the part of the program that cannot be parallelized.
In simple words:
Even if we use 100 processors, the part of the task that must be done sequentially (one after
another) will limit the overall speed.
🧮 Formula:
Where:
💡 Example:
Suppose:
So even with 4 processors, the speedup is only 2.5× faster, not 4×.
That’s because the 20% sequential part limits the improvement.
If you run a large program on 4 processors (parallel computing) and it finishes faster,
you can use Speedup to measure how much faster, and Amdahl’s Law to understand why it
doesn’t become perfectly 4× faster.
A multiprocessor system is a single computer that has two or more processors (CPUs)
connected to a shared main memory.
All processors can access the same memory, so they can easily share data and work together on
the same task.
💡 Simple Example:
All students (processors) can read and write on the same board (memory).
If one student writes something, others can see it immediately.
⚙️How It Works:
Processors are connected through a common bus or interconnection network.
Each processor has its own small cache (for fast access), but all share the main memory.
Operating system manages how processors access memory to avoid conflicts.
⚡ Advantages:
1. Easy Communication: All processors use the same memory — no need for message
passing.
2. Simpler Programming: Easier to write programs because everyone accesses the same
data.
3. Fast Data Sharing: No delay in transferring data between processors.
⚠️Disadvantages:
1. Limited Scalability: Only a few processors can share memory efficiently (usually up to
32–64).
2. Memory Conflict: If many processors try to use memory at the same time, it causes
delay.
3. Costly Hardware: Building shared-memory systems is expensive.
🧠 Example:
Your modern laptop or desktop with 8 or 16 CPU cores uses shared memory
architecture.
All cores share the same RAM and work together.
In a distributed memory system, each computer (or node) has its own private memory and its
own processor.
They are connected through a network (like Ethernet or Internet) and communicate by
sending messages.
💡 Simple Example:
⚙️How It Works:
⚡ Advantages:
⚠️Disadvantages:
🧠 Example:
👉 So, each node has shared memory inside, and all nodes communicate outside via messages.
💡 Simple Example:
⚙️How It Works:
Each node (computer) has multiple processors sharing the same memory.
All nodes are connected by a fast local network (like Gigabit Ethernet or InfiniBand).
A cluster looks like one big computer to the user but is actually made up of many small
systems.
⚡ Advantages:
⚠️Disadvantages:
🔍 Comparison Table
Feature Multiprocessor Network of Workstations Cluster (Hybrid System)
(Shared Memory) (Distributed Memory)
Memory Shared among all Each node has its own Shared within nodes,
processors memory distributed between nodes
Communicatio Through shared Through messages over a Combination of both
n memory network
Scalability Limited Very high High
Cost Expensive Cheaper Moderate
Performance Very fast for small Slower due to network Very fast and scalable
scale delay
Example Multi-core PC Google Servers NASA Supercomputer
Cluster
🏁 Conclusion
Multiprocessors → Many processors inside one computer sharing one memory.
Distributed systems → Many computers, each with its own memory, connected through
a network.
Clusters → A combination of both: each computer has multiple processors, and all are
connected for teamwork.
🧠 How it Works
💡 Example
✅ Advantages
Difficult to manage — if two threads try to update the same data at once, it can cause
errors (race conditions).
Debugging multithreaded programs is challenging.
If one thread crashes, it may affect the entire program.
🧠 How it Works
Since processes don’t share memory, they must communicate by sending and
receiving messages through a network or communication channel.
This is done using methods like Message Passing Interface (MPI), sockets, or remote
procedure calls (RPC).
💡 Example
✅ Advantages
Isolation: Each process is independent, so one failure doesn’t crash the others.
Security: Processes can’t access each other’s memory directly.
Flexibility: Works well across multiple computers in a network.
❌ Disadvantages
Slower communication, since data must be sent through messages.
More programming complexity — developers must design message handling carefully.
Network issues can delay communication between processes.
🧩 What it is
DSM is a hybrid model — it tries to combine the ease of shared memory with the
flexibility of distributed systems.
Many computers are connected via a network, but software makes it look like they all
share one big memory.
🧠 How it Works
Each computer has its own memory, but when one computer needs data from another,
DSM automatically transfers that data over the network.
To the programmer, it appears as if all data is in one place, even though it’s spread
across many machines.
💡 Example
✅ Advantages
❌ Disadvantages
Slower than real shared memory, because data has to move through the network.
Difficult to keep data consistent (when one computer updates data, others must be
informed).
Needs complex software for memory synchronization.
🧩 What it is
🧠 How it Works
💡 Example
✅ Advantages
❌ Disadvantages
Data consistency issues if many users update the same data at once.
Network delays can affect synchronization.
Needs strong security to prevent unauthorized data access.
📊 Comparison Table
Architectur Memory Communicatio Common Example Advantages Disadvantage
e Type n Method Use s
Threads & Shared Direct Parallel Video Very fast, Hard to
Shared (same memory computing editing, efficient manage, race
Memory computer access games conditions
)
Processes Separate Network Distributed Banking, Independen Slower
& Message memory messages systems servers t, secure communicatio
Passing n
Distributed Simulate Network- High- Weather Easy for Complex
Shared d shared based performanc simulatio programme consistency
Memory e systems n rs
(DSM)
Distributed Shared Network Cloud Google Real-time Sync and
Shared data only updates systems Docs, collaboratio network
Data databases n issues
(DSD)
⚙️Real-Life Analogy
Threads and Shared Memory: All employees share one desk — fast but crowded!
Processes and Message Passing: Each employee has their own desk — they pass notes
to communicate.
DSM: Everyone has their own desk, but there’s a big whiteboard that automatically
syncs between rooms.
DSD: Everyone works on the same online document stored in the cloud.
🧠 1. Introduction
A Parallel Algorithm is an algorithm that allows multiple operations to be performed
simultaneously.
Instead of solving a problem step by step (as in a sequential algorithm), a parallel algorithm
divides the problem into smaller independent parts and executes them at the same time on
multiple processors or cores.
💡 Simple Definition
A Parallel Algorithm is one that splits a large task into smaller subtasks, which are processed
simultaneously by multiple processors to achieve faster results.
🧩 Example:
Sorting 1 million numbers → divide them into 10 sets of 100,000 → sort each set in parallel.
🧠 Example:
If you have 4 processors, each gets 25% of the data.
🔹 Step 3: Communication
💬 Example:
One processor may need results from another before combining final output.
🔹 Step 4: Synchronization
Synchronization ensures that all processors finish their assigned work before moving to
the next stage.
This prevents errors caused by missing or incomplete data.
⏰ Example:
In matrix multiplication, all partial results must be ready before computing the final matrix.
🔹 Step 5: Combination
After each processor finishes its part, the results are combined to form the final output.
🧮 Example:
Each processor sorts a subset, and then the program merges all subsets into one sorted list.
It measures how much faster a parallel algorithm performs compared to a sequential one.
Where:
🧠 Example:
If sequential time = 100 seconds, parallel time = 25 seconds →
Speedup = 100 / 25 = 4×
🧩 b) Efficiency
🧠 Example:
If Speedup = 4 using 8 processors → Efficiency = 4/8 = 0.5 (50%)
⚖️c) Scalability
Refers to how well performance improves when we increase the number of processors.
A good parallel algorithm scales well, meaning it keeps getting faster as we add more
processors.
💬 d) Overhead
Extra time required for communication, synchronization, and data management between
processors.
🧠 Example:
If processors spend too much time exchanging messages, performance drops even if you add
more CPUs.
🧮 6. Types of Parallelism
Parallel algorithms can use different types of parallelism, depending on how the work is
divided.
🧩 1. Data Parallelism
The same operation is applied to different chunks of data at the same time.
Each processor handles a part of the data.
🧠 Example:
If you have a list of 1,000 numbers to double, divide it among 4 processors → each doubles 250
numbers.
Different processors perform different operations (tasks) on the same or different data.
🧠 Example:
In a video editing app:
🔄 3. Pipeline Parallelism
Tasks are divided into stages; each stage works on a different part of the input at the
same time.
Like a factory assembly line.
🧠 Example:
In a CPU:
1. Fetch instruction
2. Decode
3. Execute
4. Write result
🔍 8. Performance Metrics
Metric Meaning Ideal Value
Speedup (S) How much faster the algorithm runs in parallel The higher, the better
Efficiency (E) How well processors are used Close to 1 (100%)
Scalability How performance improves with more High
processors
Overhead Extra time for communication/synchronization Low
Where:
🧠 Example:
If 80% of a program can be parallelized using 4 processors:
❌ Disadvantages
✨ 14. Conclusion
Parallel Algorithms are the foundation of high-performance computing.
They enable modern systems — from supercomputers to cloud platforms — to perform complex
calculations quickly by dividing and conquering tasks.
However, designing an efficient parallel algorithm requires balance between computation and
communication, good load distribution, and careful synchronization.
In short:
Parallel Algorithms make computers faster and smarter — but they also make programming
more challenging.
⚙️Concurrency and Synchronization (In Detail)
🧠 1. Introduction
When multiple tasks or processes run at the same time in a system, we call it concurrency.
But when these tasks share resources (like memory, files, or data), there is a risk of conflicts or
errors — that’s where synchronization comes in.
So basically:
💡 2. What is Concurrency?
Concurrency means that two or more tasks are being executed overlapping in time.
It doesn’t necessarily mean they’re running exactly at the same instant (like parallelism), but
they make progress independently.
🔹 Simple Definition:
Concurrency is when multiple processes or threads execute during the same period, sharing
system resources like CPU and memory.
🧩 Example 1:
Even if your CPU executes one task at a time (very fast), it switches between them, giving the
illusion of simultaneous execution.
🧩 Example 2 (Programming Level):
Both can run “concurrently,” meaning they share the CPU time in turns.
✅ In short:
All parallel systems are concurrent, but not all concurrent systems are parallel.
🧩 4. Benefits of Concurrency
1. Better CPU Utilization – No CPU time wasted waiting for I/O.
2. Faster Response – Systems stay responsive even under heavy load.
3. Simpler Program Design – Each task can be written independently.
4. Efficient Multitasking – Supports multiple users or background tasks.
5. Scalability – Easy to scale on multi-core systems.
5. Problems in Concurrency
When multiple tasks share resources (like memory, variables, or files), conflicts can occur.
Occurs when two or more processes try to change the same data at the same time, and the final
result depends on the timing.
🧠 Example:
Two threads trying to update a variable balance = balance + 100 at the same time.
If not synchronized, one update might get lost — wrong result!
⚰️b) Deadlock
Occurs when two processes wait for each other’s resources and neither can continue.
🧠 Example:
🌀 c) Starvation
When one process never gets CPU time or access to resources because others keep getting
priority.
🧩 d) Inconsistency
If multiple threads read and write shared data without coordination, the data may become
inconsistent or corrupted.
🧭 6. What is Synchronization?
Synchronization is the method used to control the execution order of concurrent processes so
that they do not interfere with each other.
It ensures that only one process accesses shared resources at a time — keeping data consistent
and preventing race conditions.
🔹 Simple Definition:
🧩 Real-Life Example:
Two people cannot withdraw money from the same account at the exact same time.
If they do, both might get full balance → error!
The system must synchronize access to that account record so only one withdrawal happens at a
time.
🧩 A. Process Synchronization
Used when independent processes (not sharing memory) need to coordinate their activities.
✅ Example:
In a producer-consumer problem:
🧩 B. Thread Synchronization
Used when multiple threads share the same memory space and need to access shared data.
✅ Example:
In a multi-threaded program, two threads updating the same variable must be synchronized to
avoid conflicts.
🔹 1. Locks (Mutexes)
A lock allows only one thread or process to access a shared resource at a time.
🧠 Example:
🔹 2. Semaphores
🧩 Example:
A semaphore initialized to 1 allows one process at a time.
If set to N, it allows N processes concurrently.
🔹 3. Monitors
🔹 4. Condition Variables
🔹 5. Message Passing
🧠 Example:
Used in distributed systems and MPI (Message Passing Interface).
✅ Solution Requirements:
1. Mutual Exclusion: Only one process can enter the critical section.
2. Progress: If no one is in the critical section, one process must be allowed to enter.
3. Bounded Waiting: No process should wait forever.
Parallel System (Shared Memory) Locks, mutexes, semaphores Threads in a CPU share data
In distributed systems, synchronization ensures all nodes agree on shared data (e.g., blockchain
consensus).
and
wait(full);
wait(mutex);
// Consume item from buffer
signal(mutex);
signal(empty);
✅ Synchronization ensures producer doesn’t overwrite full buffer and consumer doesn’t read
empty one.
🧠 13. Relation to Parallel Algorithms
Aspect Parallel Algorithms Concurrency &
Synchronization
Goal Execute multiple tasks faster Execute multiple tasks
safely
Focus Divide work among processors Coordinate shared access
Example Parallel sorting, matrix multiplication Locks, semaphores,
thread safety
Connection Parallel algorithms need synchronization to avoid data
conflicts when running concurrently
❌ Disadvantages
✨ 15. Conclusion
Concurrency and Synchronization are core concepts in modern computing.
They enable systems to handle multiple operations efficiently while ensuring data integrity
and coordination.
Without synchronization, concurrent systems would be unreliable and produce incorrect results.
In short:
Concurrency gives speed and multitasking,
Synchronization ensures correctness and stability.
⚙️Data and Work Partitioning
🧠 1. Introduction
In Parallel and Distributed Computing, the main goal is to divide a big problem into smaller
parts so that multiple processors can work on them simultaneously.
This process of dividing the work or data is known as partitioning (or decomposition).
💡 Simple Definition:
Partitioning means dividing a large task (or dataset) into smaller, independent parts that can be
processed in parallel by different processors.
Some processors may do too much work while others stay idle.
Communication overhead increases.
The system becomes inefficient and slow.
1. Data Partitioning
2. Work (Task) Partitioning
Both aim to distribute the computation load evenly, but they focus on different aspects of the
problem.
🧩 3. Data Partitioning
📘 Definition:
Data Partitioning means dividing the input data into smaller parts (subsets), and assigning each
subset to a different processor for processing.
Here, each processor performs the same operation but on different parts of the data.
🧠 Example 1:
We can divide the numbers into 4 equal sets of 250,000 numbers each.
Each processor calculates the average of its portion.
Then we combine all partial results to find the final average.
🧠 Example 2:
In image processing, each processor can handle a different part of the image — like one
processor processes the top-left corner, another handles the bottom-right, etc.
🔸 Disadvantages
Work Partitioning means dividing the total work or computation (i.e., the tasks or operations)
among multiple processors.
Here, each processor may perform a different operation (not necessarily the same one).
That’s why work partitioning is also called Task Parallelism.
🧠 Example 1:
🧠 Example 2:
In a web server:
One thread handles user requests
Another processes database queries
Another sends responses
🔸 Disadvantages
✅ In simple words:
🧮 7. Load Balancing
A key goal of partitioning is load balancing, which means ensuring each processor gets an
equal amount of work.
If one processor finishes early while others are still working, the system’s efficiency decreases.
✅ Example:
If Processor 1 gets a large block and Processor 2 gets a small one → total performance suffers.
Hence, equal partitioning or dynamic task allocation is used.
✅ Example:
In Hadoop (a distributed computing framework), data partitioning is done automatically using
the MapReduce model:
✅ Trade-off:
Fine-grained = more parallelism but more communication.
Coarse-grained = less communication but less flexibility.
💡 12. Real-Life Examples
Domain Example Partitioning Type
Scientific Computing Dividing a large matrix into smaller submatrices Data
Web Search Engines Each server indexes a different set of web pages Data
Machine Learning Each GPU trains part of a neural network Data
Video Games Different threads handle physics, rendering, and sound Work
Banking Systems One server processes transactions, another manages logs Work
✨ 14. Conclusion
Data and Work Partitioning are fundamental steps in designing any parallel or distributed
algorithm.
They determine how efficiently a system can use its processors and how well it scales as we add
more resources.
In short:
Both together help achieve maximum speedup, efficiency, and scalability in modern
computing systems.
There are several common strategies used in Parallel and Distributed Computing to achieve
this efficiently.
🟦 1. Task Parallelism (Functional Parallelism)
Meaning:
In this strategy, different tasks or functions are executed in parallel.
Each processor performs a different operation on the same or different data.
Example:
Suppose you’re editing a video —
All these tasks run at the same time but perform different functions.
Used in:
Multimedia processing
Web servers (handling multiple requests)
Robotics (different sensors running parallel tasks)
🟩 2. Data Parallelism
Meaning:
In data parallelism, the same operation is performed on different pieces of data at the same
time.
Each processor handles a portion of the total data.
Example:
If you want to find the sum of 1 million numbers,
Used in:
Scientific computations
Image and video processing
Machine learning (training models on large datasets)
🟨 3. Pipeline Parallelism
Meaning:
The work is divided into stages, where each stage performs part of the task.
As soon as one stage finishes, its output becomes the input for the next stage — just like an
assembly line in a factory.
Example:
In video streaming:
Used in:
🟧 4. Hybrid Parallelism
Meaning:
Hybrid parallelism is a combination of data and task parallelism.
It uses both techniques together to get better performance.
Example:
In a weather simulation:
Task parallelism: One group of processors handles temperature, another handles wind
speed.
Data parallelism: Within each group, the data (like different regions) is divided among
processors.
Used in:
Meaning:
In this method, the system executes multiple possible tasks in parallel before knowing which
one is needed.
If one task gives the correct result, the others are discarded.
Example:
In artificial intelligence, different possible solutions might be calculated simultaneously, and the
best one is chosen.
Used in:
Artificial intelligence
Predictive systems
Compiler optimization
🟦 6. Loop-Level Parallelism
Meaning:
This strategy focuses on parallelizing loops in a program.
If the loop iterations are independent, they can be executed at the same time.
Example:
for i in range(1000):
A[i] = B[i] + C[i]
Each iteration can be handled by a separate processor since they don’t depend on each other.
Used in:
Numerical analysis
Image pixel processing
Array computations
⚙️Summary Table
Strategy What it Does Example
Task Parallelism Runs different tasks at the same time Video editing (audio + video +
effects)
Data Parallelism Runs the same task on different data Sum of large datasets
Pipeline Breaks task into stages like an Video streaming
Parallelism assembly line
Hybrid Parallelism Combines data + task parallelism Weather simulation
Speculative Runs multiple possible tasks before AI predictions
Parallelism knowing result
Loop-Level Runs independent loop iterations at Array computations
Parallelism once
In Parallel Algorithms, these strategies help design efficient algorithms that divide
work properly.
In Data and Work Partitioning, you decide how to split data/work — these strategies
are the methods to actually perform that division.
In Concurrency and Synchronization, once tasks are running in parallel,
synchronization ensures they don’t interfere with each other.
Granularity refers to how much work is done by each part (or task) of a parallel program
before communication or synchronization happens.
In simple words:
It tells us how big or small each piece of work is when we divide a task into parts to run in
parallel.
When a large program is divided into smaller tasks for parallel execution:
Granularity helps decide how many processors should be used and how tasks communicate
with each other.
🟩 1. Fine-Grained Parallelism
Meaning:
Advantages:
Disadvantages:
High communication overhead (too many small tasks need constant communication).
Managing and synchronizing many small tasks is complex.
Example:
Adding two large arrays element by element:
Used in:
Real-time systems
Simulations requiring close coordination
🟦 2. Coarse-Grained Parallelism
Meaning:
Advantages:
Disadvantages:
May lead to load imbalance (some processors finish early, others late).
May not fully utilize all processors.
Example:
Dividing an image into 4 large parts and assigning each processor one part to process
completely.
Each processor works mostly independently.
Used in:
Scientific simulations
Batch processing
Data analysis with large datasets
Advantages:
Balanced performance
Moderate communication cost
Easier to manage than fine-grained systems
Example:
Dividing a 1000x1000 image into 10x10 blocks —
Each processor handles one block (not too small, not too big).
Used in:
Image processing
Computer graphics
Distributed data processing
🧩 Comparison Table
Type Task Size Communication Performance Example
Frequency
Fine-Grained Very Very High May slow due to Element-wise
Small overhead operations
Coarse- Large Low Fast but less Large data chunks
Grained balanced
Medium- Moderate Balanced Good balance Image block
Grained processing
💡 Real-Life Example
Fine-grained: Everyone chops one small vegetable — too much coordination, slows
things down.
Coarse-grained: Each person cooks one full dish — less coordination, faster overall.
Medium-grained: Each person handles one part of a meal (like salad, dessert) —
balanced teamwork.
Load Balancing means distributing work evenly among all processors or computers in a
parallel or distributed system so that no processor stays idle while others are overloaded.
In simple words:
Load balancing ensures that every processor gets a fair amount of work — not too much, not
too little — so the system runs efficiently and quickly.
Meaning:
In static load balancing, the work is divided before execution begins.
The amount of work assigned to each processor is fixed at the start and does not change during
execution.
How it works:
Tasks are divided equally based on known data (like size or complexity).
The distribution stays the same throughout the process.
Advantages:
Disadvantages:
Not suitable when tasks take different amounts of time (can cause imbalance).
If one processor is slower or gets a harder task, it can delay the entire process.
Example:
Suppose you divide 100 tasks among 5 processors → each gets 20 tasks.
If one processor gets heavier tasks, it will finish later than others.
Used in:
Systems where workload is predictable.
Scientific simulations with known data sizes.
Meaning:
In dynamic load balancing, the system continuously checks how busy each processor is during
execution and redistributes tasks if needed.
How it works:
If one processor finishes early, it can take extra work from overloaded processors.
The system tries to keep all processors equally busy.
Advantages:
Disadvantages:
Example:
If one processor finishes its tasks early, it can take remaining work from another processor that
still has pending tasks.
Used in:
Cloud computing
Distributed networks
Real-time processing systems
🧠 Real-Life Example
Imagine a group project with 5 members:
If one person does most of the work while others relax, the project finishes late
(imbalance).
If everyone does equal work, the project finishes faster (balanced).
This is the same idea behind load balancing — fair work distribution for faster results.
Load balancing ensures that all processors work efficiently and none stay idle, which improves
performance, resource use, and speed in parallel and distributed systems.
🟩 1. Parallel Search
Definition:
Parallel search means finding an item in a large dataset by dividing the data into smaller parts
and letting multiple processors search simultaneously.
How it works:
Example:
Suppose you have a list of 1 million numbers and you need to find the number 500.
Real-world example:
Advantages:
🟦 2. Parallel Sorting
Definition:
Parallel sorting means sorting large data by dividing it among multiple processors, sorting
each part, and then merging the results.
Example:
Sorting a list of 1 million numbers using 4 processors →
Each sorts 250,000 numbers, then results are combined.
Used in:
Definition:
Matrix multiplication is a common operation in scientific and AI computations.
Parallel matrix multiplication divides matrices into smaller submatrices and multiplies them
simultaneously.
How it works:
Example:
For multiplying two 1000×1000 matrices using 4 processors:
Each processor handles one quarter of the matrix multiplication.
Used in:
Machine learning
Graphics processing
Scientific computing
Benefits:
Definition:
Prefix sum means computing cumulative sums in parallel.
It’s often used in algorithms like sorting, searching, and data compression.
Example:
Given numbers: [1, 2, 3, 4]
The prefix sum result is [1, 3, 6, 10].
In parallel computing:
Used in:
Data analysis
Compilers
GPU algorithms
Definition:
Used to process large graphs (networks) faster — for example, finding shortest paths or
connectivity.
Examples:
Used in:
Definition:
In image processing, each pixel or block of pixels can be processed independently — making it
perfect for parallel execution.
Example:
For applying a filter to a 4K image:
Used in:
Medical imaging
Computer vision
Photography and video editing software
🧩 Comparison Table
Algorithm Purpose How Parallelism is Used Example Use
Parallel Search Find data quickly Split data among Keyword
processors search
Parallel Sorting Sort large datasets Each processor sorts part Database
of the data sorting
Parallel Matrix Multiply matrices Each processor handles AI training
Multiplication faster submatrix
Parallel Prefix Sum Compute cumulative Each handles partial sum Data analysis
results
Parallel Graph Process large graphs Explore nodes/edges in Social
Algorithms parallel network
Parallel Image Process pixels Divide image into regions Filter
Processing simultaneously application
⚙️Shared-Memory Programming
📘 Definition:
In shared-memory programming, multiple processors (or threads) share the same memory
space.
Each processor can directly read and write data from a common memory area.
In simple words:
All threads or processors work together on a common task using the same memory — they can
see and modify each other’s data.
💡 Key Idea:
Shared-memory systems are easy to program because data does not need to be sent or received
between processors.
However, they require synchronization (like locks and semaphores) to prevent conflicts when
multiple threads access the same data.
🟩 1. Threads
Definition:
A thread is the smallest unit of execution inside a program.
Multiple threads can run in parallel, performing different parts of the same program at the same
time.
Example:
In a web browser:
o One thread loads a webpage.
o Another thread plays a video.
o Another handles user input.
In shared-memory systems:
All threads share the same memory, so they can access the same variables or data structures.
Benefits:
Definition:
Pthreads stands for POSIX Threads, which is a standard API (Application Programming
Interface) for creating and managing threads in C and C++ programs.
Create threads
Synchronize threads (using locks or condition variables)
Control thread execution (start, join, cancel, etc.)
Example (concept):
Advantages:
Used in:
🟨 3. Locks (Mutexes)
Definition:
A lock (also called a mutex, short for mutual exclusion) is used to protect shared data from
being accessed by multiple threads at the same time.
Why needed:
If two threads try to update the same variable simultaneously, results can be wrong or
unpredictable — this is called a race condition.
How it works:
Example (concept):
pthread_mutex_lock(&lock);
// Critical section (shared data)
pthread_mutex_unlock(&lock);
Advantages:
If used incorrectly, can cause deadlocks (when two threads wait for each other forever).
🟥 4. Semaphores
Definition:
A semaphore is another synchronization tool used to control access to shared resources.
It uses a counter to keep track of how many threads can access a resource at the same time.
Types of Semaphores:
1. Binary Semaphore (0 or 1): Works like a lock (only one thread at a time).
2. Counting Semaphore: Allows a certain number of threads to access the resource
simultaneously.
Example:
Imagine a system with 3 printers:
Semaphore value = 3
Only 3 threads can print at once.
When one printer becomes free, the semaphore increases again.
Advantages:
Disadvantages:
Without a lock:
Two threads might read the same value (e.g., 50) and both write back 51 → final count
becomes incorrect.
With a lock:
Each thread waits until the previous one finishes updating the variable → result stays
correct.
💡 Real-Life Example
Think of a shared whiteboard in a classroom:
✅ Summary
Term Meaning Purpose
Shared Memory Common memory area for all threads Easier data sharing
Thread Small unit of execution Run multiple tasks at once
Pthreads Library for thread management Create and synchronize threads
Lock (Mutex) Allows one thread to access data Prevent data corruption
Semaphore Controls how many threads can access Manage limited resources
data
🌐 Distributed-Memory Programming
So, if processors need to work together, they must communicate by sending and receiving
messages — this is known as Message Passing.
💡 Real-Life Example
🔹 Message Passing
📘 Definition:
Message Passing is a way for processors to communicate and share data in a distributed-
memory environment by sending and receiving messages.
Each processor:
Operation Meaning
Send Transmit a message to another processor.
Receive Accept a message from another processor.
Broadcast Send the same message to multiple processors.
Gather Collect data from multiple processors.
Scatter Distribute data among multiple processors.
💻 Example (Concept):
Let’s say we have 4 computers (P1, P2, P3, P4) working together.
This method ensures all processors work simultaneously and share data through messages.
MPI is the most popular and widely used tool for parallel programming in clusters and
supercomputers.
⚙️Main Features of MPI:
Function Description
MPI_Init() Starts the MPI environment.
MPI_Comm_size() Finds how many processes are running.
MPI_Comm_rank() Finds the ID of each process.
MPI_Send() Sends a message to another process.
MPI_Recv() Receives a message from another process.
MPI_Finalize() Ends the MPI environment.
🧠 Advantages of MPI
⚠️Disadvantages
Each computer (or node) runs a PVM daemon that helps it communicate with others.
🧠 Advantages of PVM
⚠️Disadvantages
✅ Summary
Concept Description
Distributed-Memory Each processor has its own private memory and communicates via
Programming message passing.
Message Passing Technique to exchange data between processors through messages.
MPI (Message Passing Standard high-performance library for distributed programming.
Interface)
PVM (Parallel Virtual Software system that connects many computers into one virtual
Machine) machine.
💡 Real-World Examples
Besides Shared-Memory (Threads, Pthreads) and Distributed-Memory (MPI, PVM), there are
other systems and models that provide easier and more flexible ways to build parallel
programs.
These systems try to simplify communication, data sharing, and synchronization between
processors.
In DSM:
Each processor has its own local memory (like in distributed systems).
But the software provides a virtual shared memory — meaning all processors can
appear to access the same memory space.
It gives programmers the simplicity of shared memory and the scalability of distributed
systems.
💡 How It Works
⚙️Advantages
⚠️Disadvantages
🧠 Example:
Used in:
Multiprocessor servers
Cluster systems
Parallel simulations
Aurora is an experimental parallel programming system that introduces the idea of scoped
behavior and abstract data types (ADTs) to organize and control parallelism.
It was designed to make parallel programs easier to understand, develop, and maintain.
💡 Key Concepts:
🔹 Scoped Behavior
Defines which parts of a program can run in parallel and what data they can access.
Each “scope” has its own set of variables and parallel activities.
Helps avoid conflicts between parallel tasks.
These are data structures that bundle data and operations together (like objects).
Aurora uses ADTs to manage parallel tasks safely by limiting how different parts of
the program access data.
⚙️Advantages of Aurora
🧠 Example (Conceptual):
Enterprise is another parallel programming environment that uses the concept of process
templates.
A process template defines a pattern or blueprint for creating multiple processes that do
similar work.
💡 Key Idea:
Instead of writing the same process multiple times, a template is written once and instantiated
(copied) as many times as needed.
⚙️How It Works:
🧩 Advantages:
🧠 Example:
In a weather simulation:
A process template defines how to calculate temperature for one grid cell.
The system creates hundreds of processes, each working on a different region of the
world.
✅ Summary
System Key Idea Advantages Example Use
DSM (Distributed Combines shared & Easier programming, Cluster computing
Shared Memory) distributed models scalable
Aurora Scoped behavior & ADTs Safe, structured Research systems
parallelism
Enterprise Process templates Simple large-scale Simulations, data
parallelism processing
Research Topics Emerging areas in parallel Innovation & Academic & industrial
computing optimization research