1
Sri Raghavendra Educational Institutions Society (R)
(Approved by AICTE, Accredited by NAAC, Affiliated to VTU, Karnataka)
Sri Krishna Institute of Technology
www.skit.org.in
Prepared by:
Latha
Course: Parallel Computing
Department: Computer Science &Engineering
Course Code: BCS702 | Semester: VII | Credits: 04
Teaching Hours: 3:0:2:0 | CIE Marks: 50 | SEE Marks: 50
2
Vision of CSE Dept.
To be in the frontier of Computer Science & Engineering and to create Technically competent graduates with ethical, moral values committed to meet Industry and Societal needs.
Mission of CSE Dept.
M1: To produce ethical, motivated, and skilled engineers through theoretical knowledge and practical applications.
M2: Inculcate problem solving and team building skills and promote lifelong learning with a sense of social responsibilities.
M3:To facilitate functional ambience for research, consultancy and entrepreneurship.
Course Objectives
Explore Parallel Programming
Understand the fundamental need for parallel programming in modern computing
MIMD Systems
Explain how to parallelize applications on Multiple Instruction, Multiple Data systems
MPI Library
Demonstrate how to apply Message Passing Interface library to parallelize suitable programs
OpenMP
Demonstrate how to apply OpenMP pragma and directives to parallelize suitable programs
CUDA Programming
Demonstrate how to design CUDA programs for GPU-based parallel computing
Classification of Parallel Computers
Flynn's Taxonomy
Based on instruction and data streams:
Memory Architecture
Based on memory access:
SIMD Systems
Single Instruction, Multiple Data systems apply the same instruction simultaneously to multiple data streams.
Control Unit
One control unit broadcasts instructions to multiple datapaths
Multiple Datapaths
Each datapath either executes the instruction on its data or remains idle
Data Parallelism
Ideal for operations on large data arrays (e.g., vector addition)
Modern implementations include vector processors and GPUs, which are highly efficient for data-parallel problems but struggle with other types of parallelism.
Parallel Execution: SIMD applies the same instrExample: For auction (addition) to multiple data elements simultaneously.
loop x[i] += y[i];, SIMD can process several x and y values at once.
Vector Processors
Operates on arrays/vectors (not individual scalars like CPUs).
Advantages: High memory bandwidth, efficient data use, compiler support for auto-vectorization.
Limitations: Struggles with irregular data, limited scalability by vector length, expensive for long vectors, commodity systems support only short vectors.
Graphics Processing Units
Graphics Pipeline: Converts objects (points, lines, triangles) into pixels; programmable via short parallel shader functions.
Prof. Latha, Dept of CS&E
9
Key Characteristics of MIMD
MIMD Systems
shared-memory systems v/s distributed-memory systems
Prof. Latha, Dept of CS&E
11
In shared-memory systems, multiple processors are connected to a common memory through an interconnection network, allowing each processor to access any memory location. Communication between processors typically occurs implicitly by accessing shared data structures.
Distributed-memory systems pair each processor with its own private memory, and these processor-memory pairs communicate explicitly over a network. Communication usually involves sending messages or using special functions to access another processor’s memory
UMA and NUMA multicore system of Shared Memory Model
Prof. Latha, Dept of CS&E
12
Distributed-Memory Systems
Prof. Latha, Dept of CS&E
13
Importance of Interconnects
Shared-Memory Interconnects
Prof. Latha, Dept of CS&E
14
Switched Interconnects
Crossbar Structure
Conflict and Access
Performance and Cost Tradeoff
15
Simultaneous memory accesses by the processors
Distributed-memory interconnects
Distributed interconnects are of two types:
Examples of Direct Interconnects
16
A ring
Two-Dimensional Toroidal Mesh
In short:
17
A toroidal mesh
Bisection
Bisection width:
Bisection bandwidth:
Key distinction:
18
Fig 1.7 (a): Only two communications can take place between the halves
Fig 1.7 (b): Four simultaneous connections can take place.
Fully connected network
19
Hypercube
The hypercube is a highly connected direct interconnect, implemented in real systems.
🔹 Structure of a Hypercube
🔹 Bisection Width of Hypercube
Ring → 2 2D Mesh → √p�Hypercube → p/2 (scales linearly with number of nodes!)
👉 This means the hypercube supports far more simultaneous cross-network communications than rings/meshes.
20
(a) One (b) two and (c) three-dimensional hypercubes
Indirect interconnects
Indirect interconnects - switches may not be directly linked to processors.
Examples of simple indirect interconnects
21
A generic indirect network.
A crossbar interconnect for distributed-memory.
omega network
it is composed of multiple two-by-two crossbar switches but it does not support all communications simultaneously.
For instance, if processor 0 sends data to processor 6, processor 1 cannot concurrently send data to processor 7.
omega network is more cost-efficient, requiring only 1/2plog2(p) of the 2X2 crossbar switches, totaling 2plog2(p) switches—significantly fewer than the p^2 switches used in a full crossbar.
Latency and bandwidth
Latency is the time delay between the start of transmission and the arrival of the first byte at the destination
bandwidth refers to the rate at which data is received after the first byte.
Together, these factors determine the total time to send a message of n bytes across an interconnect with latency l seconds and bandwidth b bytes per second.
message transmission time = l + n/b
22
Mindmap of interconnects
23
Cache Coherence
eg. The shared variable x is initialized to 2, while y0 (Core 0), y1, and z1 (Core 1) are private variables owned by their respective cores.
24
25
Cache coherence protocols
Cache coherence protocols ensure all caches see a consistent view of memory.
26
Snooping Cache Coherence
27
Snooping Cache Coherence
28
Directory-based cache coherence
29
30
False Sharing
31
32
Shared-Memory Programming
Dynamic Threads
33
Static Threads
Nondeterminism
Example: Shared variable update
Suppose we have:
Both threads execute and after completion of instruction:
34
Race Conditions and Synchronization in Shared-Memory Systems
Parallel Access to a Shared Variable
Scenario: Core 0 and Core 1 both attempt to update the same shared variable x concurrently.Each core uses its own private value (my_val) in the update.
Operation Sequence:
Each core executes the following steps:
Load x.
Load my_val.
Compute x + my_val.
Store the result back into x.
Although these steps appear independent, both cores affect the same memory location.
35
Race Condition
When two or more threads concurrently access and modify a shared resource, the result depends on the unpredictable order of execution.
Both threads read x = 0 before writing.
Depending on timing, the final value of x could be 7 or 19, instead of the correct 26.
This loss of updates is a classic race condition.
Ensuring Correctness
The operation x += my_val must be atomic: No other thread can access or modify x until the update completes.
A block of code that must not be executed by more than one thread at a time. Eg: placing x += my_val inside a critical section ensures correct results.
A mutex (mutual exclusion lock) enforces that only one thread can enter the critical section at a time.
Thread acquires the lock before entering and Thread releases the lock after completing the update.
Mutexes are supported at both the hardware and operating system levels.
It is the programmer’s responsibility to use synchronization constructs to avoid race conditions.
36
Distributed Memory Systems and Message-Passing Model
In distributed memory system, each processor (core) has its own private memory.
No direct access to another processor’s memory (communication is explicit) since processors may be located on entirely different machines, connected by a network. Hence Parallelism is achieved by running separate processes
👉 This is why frameworks like MPI are necessary—
they let independent processes talk to each other.
37
Example: only process 1 sends a message, only process 0 receives
char message[100];
my_rank = Get_rank();
if (my_rank == 1) {
sprintf(message, "Greetings from process 1");
Send(message, MSG_CHAR, 100, 0); // send to rank 0
}
else if (my_rank == 0) {
Receive(message, MSG_CHAR, 100, 1); // receive from rank 1
printf("Process 0 > Received: %s\n", message);
}
Blocking vs Non-blocking Communication
Message-passing APIs (like MPI) provide:
38
Advantages and Challenges
✅ Advantages:
⚠️ Challenges:
This is why MPI is sometimes called the assembly language of parallel programming.
39
One-Sided Communication
In Message Passing system/ (Send/Receive): Both processes, sending and receiving process must participate explicitly. Eg: Process 0 calls Send, Process 1 calls Receive. Synchronization is “built-in” because both sides must act.
In One-sided (RMA): Only one process initiates communication-Eg. Process 0 can directly read from or write to memory belonging to Process
✅ Advantages
⚠️ Drawbacks
40
Partitioned global address space languages
Partitioned Global Address Space (PGAS) languages offer
41
42
43
44
45
46