Chapter Three Parallel Computing
Chapter Three Parallel Computing
-Introduction
Motivation for parallel architectures (performance, scalability, efficiency)
Challenges in parallel systems (communication, synchronization, memory
access or memory bandwidth, race conditions, deadlocks, consistency)
-Parallel Architectures
Overview of parallel computer architectures
Shared memory systems
Uniform Memory Access (UMA)
Non-Uniform Memory Access (NUMA)
Cache coherence (cache coherence problem, Cache coherence
protocols(Snooping protocols & Directory-based protocols))
Distributed-memory systems (i.e. Message passing model)
Hybrid memory systems
Advantages and limitations of each architectures
-Role of Interconnection networks and routing protocols in
parallel systems
Introduction
Why do you need to know about hardware architecture?
Hardware determines (parallel) software performance. In order to write
efficient parallel software, you must be aware of the hardware design and
constraints.
It is ultimately the hardware architecture that determines the cost
(execution time) associated with each algorithmic idea.
Parallel Computer Architecture is actually a type (or extension) of computer
hardware architecture.
How multiple processors/cores, memory, caches and interconnections are
designed and organized in hardware to execute tasks in parallel.
Computer Architecture (in general)→ Design of a computer system (CPU,
memory, I/O)
Parallel Computer Architecture→ Design of systems with multiple processing
units working together
Introduction
Why do you need to know about hardware architecture?
Much of parallel computer architecture is about:-
Designing machines that overcome the sequential and parallel bottlenecks to achieve
higher performance and efficiency.
Making programmer’s job easier in writing correct and high-performance parallel
programs
Ordering of operations such as: A, B, C, D
In what order should the hardware execute (and report the results of) these
operations?
Preserving an “expected” (more accurately, “agreed upon”) order simplifies
programmer’s life
Ease of debugging; ease of state recovery, exception handling
Preserving an “expected” order usually makes the hardware designer’s life
difficult
Especially if the goal is to design a high-performance processor
Processors want to do things out-of-order for performance! But make it
appear in-order externally (for correctness)
prints the message "Hello, world:"
prints the message "Hello, world:"
to the console.
. to the console.
"Hello, world:"
prints the message "Hello, world:"
to the console.
to the console.
"Hello, world:"
prints the message "Hello, world:"
to the console.
to the console.
"Hello, world:"
prints the message "Hello, world:"
to the console.
to the console.
#include <stdio.h>
#include <omp.h>
Barrier = Hardware Synchronization
intmain() { Hello, world: 2 0 3 4?
printf("Hello, world:");
#pragma omp parallel {
printf(" %d", omp_get_thread_num());
#pragma omp barrier // Synchronization point
#pragma omp single
printf("\n"); // Only one thread prints newline after all threads finish
}
return 0;
}
Components of Parallel Computer Architecture
Registers
General-purpose registers: Registers directly accessible by the CPU cores for storing
temporary data and intermediate computation results.
Special-purpose registers: Registers dedicated to specific functions, such as program
counter, stack pointer, and status flags, essential for CPU operations and control flow.
Cache Memory
L1 Cache: Level 1 cache located closest to the CPU cores, offering fast access to
frequently accessed data and instructions.
L2 Cache: Level 2 cache situated between L1 cache and main memory, providing larger
storage capacity and slightly slower access speeds.
L3 Cache: Level 3 cache shared among multiple CPU cores, offering a larger cache size
and serving as a shared resource for improving data locality and reducing memory access
latency.
Components of Parallel Computing Architecture
Interconnection Networks
In a shared memory MP, we need to connect different processors and
memory modules
Types of interconnect:
➢Shared bus
➢Crossbar: Fully connected
➢Ring
➢Mesh
➢2-D Torus
➢Hypercube
Number of hops vs. number of links: Compare N processors and M memory
modules
Components of Parallel Computing Architecture
Buses
System Bus: Connects the CPU, memory, and other internal
components within a computer system. It facilitates
communication and data transfer between these components.
Memory Bus: Dedicated bus for transferring data between the CPU
and main memory (RAM). It ensures fast and efficient access to
memory resources.
Switches
Crossbar Switches: High-performance switches that provide multiple paths for data transmission
between input and output ports. They enable simultaneous communication between multiple pairs of
devices, improving bandwidth and reducing latency.
Packet Switches: Switches that forward data in discrete packets based on destination addresses.
They efficiently manage network traffic by dynamically allocating bandwidth and prioritizing
packets based on quality of service (QoS) parameters.
Networks
Ethernet: A widely used networking technology for local area networks (LANs) and wide area
networks (WANs). It employs Ethernet cables and switches to transmit data packets between
devices within a network.
InfiniBand: A high-speed interconnect technology commonly used in high-performance computing
(HPC) environments. It offers low-latency, high-bandwidth communication between compute nodes
in clustered systems.
Fiber Channel: A storage area network (SAN) technology that enables high-speed data transfer
between servers and storage devices over fiber optic cables. It provides reliable and scalable
connectivity for enterprise storage solutions.
Components of Parallel Computing Architecture
One definition of parallel computer architecture
A parallel computer is a collection of processing elements, memory &
caches that cooperate to solve large problems fast. Key issues:
Resource Allocation:- This is about how you design the system
how large a collection? How many processors do we need? Is there multicore
processor? Or Is there GPU HW in that of we want to implement parallelism?
how powerful are the elements? How powerful should each processor be?
how much memory? Cache?
Data access, Communication and Synchronization:-This is the heart of parallel computing
how do the elements cooperate and communicate? How do processors talk?
how are data transmitted between processors? How do they share data?
what are the abstractions and primitives for cooperation? How do they coordinate?
Performance and Scalability:- This is about how fast the system actually runs
how does it all translate into performance?
Does adding processors really make it faster? What happens when we keep adding processors?
One definition of parallel computer architecture
A parallel architecture is defined by how these three things work together:
1. Resources allocation (hardware design)
2. Communication & coordination (interaction)
3. Performance & scalability (result)-Speedup achieved, Efficiency, Ability to grow system
Parallel architecture performance depends on the interaction between
resource allocation, communication, and synchronization mechanisms.
Efficient systems minimize communication overhead, balance workload
among processors, and provide scalable interconnection networks.
Poor coordination or excessive communication limits scalability and reduces
performance.
The efficiency of a parallel architecture is determined by how well its
hardware resources support low-cost communication and synchronization to
achieve scalable performance.
Why study parallel arch & programming models?
The Answer before 15 or more years: High Performance (Speed)
Because it allows you to achieve high performance beyond what we get with CPU clock frequency
scaling.
To achieve higher performance by increasing CPU clock frequency. Performance was improved
mainly by: Increasing clock speed (GHz scaling)
The Answer Today: Everywhere Computing + Efficiency + Scalability + Speedup
Because it seems to be the best available way to achieve higher performance in the foreseeable
future. Now it is the main path to performance improvement, is not clock speed.
CPU clock rates are no longer increasing! ---The higher the clock speed, the more heat is
generated, and we've now hit a stage where it is no longer efficient to increase processor
Parallelism speed due to the amount of energy that goes into cooling it.
Instruction-level-parallelism is not increasing either!
Improving performance further on sequential code becomes very complicated +
diminishing returns
Without explicit parallelism or architectural specialization, performance becomes a zero-sum game.
Specialization is more disruptive than parallel programming (and is mostly about parallelism
anyway)
Why study parallel arch & programming models?
In the past, CPUs were designed with a single core running at very high clock
frequencies, because increasing the clock speed was the main way to improve
performance.
However, this approach reached physical limits due to heat generation and high-
power consumption, making it difficult to keep increasing the clock frequency.
CPU clock speed scaling has stopped due to heat and power limits, and instruction-level parallelism
has reached diminishing returns.
the historical tight coupling between hardware and software which leads to
the above most common parallel architectures.
When we say parallel architectures that are tightly coupled to specific programming
models, meaning the hardware design is optimized for a particular way of expressing
parallelism.
The introduction of high-level programming models has been a critical step in decoupling
parallel hardware from specific software paradigms.
Programming models like OpenMP and CUDA offer higher-level abstractions, allowing
developers to focus on parallelism without worrying about the specific hardware being
used.
These models provide a consistent interface to parallelize code, whether you're running on
a multi-core CPU, a GPU, or even a distributed system.
What is the solution for decoupling?
OpenMP: A directive-based parallel programming model that enables multi-
threading within shared-memory systems. By using compiler directives,
OpenMP allows for parallel execution without needing to worry about the
underlying hardware architecture.
CUDA: A parallel computing platform and application programming interface
(API) that allows developers to write software that can run on GPUs,
abstracting away the hardware-specific intricacies.
Where:-
Each processor is first connected to the cache then the cache is linked to the bus.
At last, the bus is connected to the memory.
This UMA architecture reduces the contention for the bus through fetching the
instructions directly from the individual isolated cache.
It also provides an equal probability for reading and writing to each processor.
Uniform Memory Access (UMA
UMA uses single, multiple, crossbar buses
Limitations of UMA
Limited scalability
Bandwidth bottleneck
Memory contention
Restricted memory capacity
Not ideal for larder/complex systems
Non-Uniform Memory Access (NUMA)
Each processor has its own local memory, and access to that local memory is faster
than accessing memory on another processor's board (remote memory).
NUMA is often used in systems with multiple SMPs linked together.
Suitable for real-time and time-critical applications where faster access to local data
is crucial.
Not all processors have equal access time to all memories
Memory is physically distributed but logically shared among all cores
Every CPU can access all memory but access time depend on location.
If cache coherency is maintained, then may also be called CC-NUMA - Cache
Coherent NUMA
HOW DOES IT WORK ?
A CPU first checks the L1 cache on the microprocessor when searching for data
at a certain memory address.
After then, it switches to the larger L2 cache chip before reaching the third level
of cache (L3). This third level is provided by the NUMA setup.
The processor will check the distant memory, which is close to the other
microprocessors, if it is still unable to locate the data.
Non-Uniform Memory Access (NUMA)
One drawback of SMP is that when more processors are added, the shared
bus or data channel becomes overloaded, which slowing down performance.
In order to prevent all accessible data from travelling on the main bus,
NUMA adds an intermediate level of memory that is shared across a few
microprocessors.
This aids in addressing performance bottleneck problems in UMA.
Non-Uniform Memory Access (NUMA)
NUMA?
Local and remote memory
A processor can access both its local memory and remote memory attached to other
processors.
Faster local access
Every processor access to its local memory is much faster than accessing
remote memory attached to other processors.
This non-uniformity in access times is the key features of NUMA.
Scalable architecture than UMA
Multiple memory controllers but one MC in UMA
Ideal for larger/complex systems
Shared Memory Architecture
Shared Memory Multiprocessors: Memory Hierarchy
Problem: sharing memory means more than one processor can send requests to
memory
➢High memory bandwidth required
To avoid sending lots of memory requests, processors use caches to:
aims
➢Filter out many memory requests
To reduce overhead on the shared mem/bus
➢Reduce average memory latency To increase speed
➢Reduce memory bandwidth requirements
Typically, more than one level of caches is used
➢L1 caches: small and fast
➢L2 caches: bigger, slower
➢L3 caches: largest, slower
➢L3 cache is shared because it is the last-level cache and serves all CPU cores,
allowing efficient data sharing, reduced duplication, and better use of chip space.
Shared Memory Multiprocessors: Memory Hierarchy
Cache coherence---it is the uniformity of shared resource data in multiple
local caches
Problem: Using caches means multiple copies of the same memory location
may exist
➢leads to cache coherence/ memory coherence issues/problems
➢ Updates to the same location may lead to bugs
Example:
Processor 1 reads A
Processor 2 reads A
Processor 1 writes to A
Now, processor 2’s cache contains stale data, here is the problem
Cache coherence need to be implemented in hardware using a cache
coherence protocol
Shared Memory Multiprocessors: Memory Hierarchy
A memory system is coherent if:
1. A read by processor P to address X that follows a write by P to address X,
should return the value of the write by P (assuming no other processor wrote
to X in between).
3. Writes to the same address are serialized: two writes to address X by any
two processors are observed in the same order by all processors.
Should be in some order even if they operate at the same time
Assume the computation order is done 1st P1, then p2, p3, p4? Is the above cc-problem?
Why do we introduce this cache coherence problem into our shared architectures?
Shared Memory Multiprocessors: Memory Hierarchy
Cache coherence problems
Shared Memory Multiprocessors: Memory Hierarchy
Cache coherence protocol classification
Cache coherence(same memory location) –the behavior of reads and writes
to the same memory location. If multiple processors access the same variable
(same memory address), do they see the same value?
Memory consistency models (different memory locations)--the behavior of
reads and writes with respect to accesses to other memory locations.
Hardware based solutions to cache coherence problems exist as below.
Two main types of cache coherence protocols:
➢Snooping-based protocol/ bus-based protocol
❑Each cache monitors (snoops on) the shared communication medium (bus) to track
memory operations from other processors. Snooping = listening/watching
❑When one processor reads/writes data, it sends a message on the bus
❑ Each processor’s cache continuously listens to the bus to detect (Reads, Writes, Updates
from other processors). Based on what they hear, they (Update their data or Invalidate their
copies). Broadcast Communication:- Every operation is announced to all caches.
Shared Memory Multiprocessors: Memory Hierarchy
Snooping-based protocol/ bus-based protocol
In snooping-based cache coherence protocols, all caches monitor a shared
communication bus to observe memory operations performed by other
processors.
When a processor updates a memory location, it broadcasts the operation,
and other caches snoop the bus and forcing other caches to invalidate or
update their local copies, ensuring consistency across all processors using
policies like MESI.
This ensures that all processors maintain a consistent view of shared data.
How this protocol maintain coherence?
Common snooping protocol approaches
Write-update-write through
Write update-write back
Write invalidate-write through
Write invalidate-write back
Shared Memory Multiprocessors: Memory Hierarchy
Write policy → how updates are propagated to other caches
Write-update
Write-invalidate
Memory write policy → how data is written to main memory
Write-through
Write-back
Write-update + Write-through
How it works
When a processor writes:
It updates its cache
It updates all other caches (write-update)
It also writes to main memory immediately (write-through)
Shared Memory Multiprocessors: Memory Hierarchy
Write-update + Write-back
How it works
When a processor writes:
Updates its cache
Sends updated value to other caches
Does NOT update memory immediately
Memory updated only when cache block is replaced
MOESI or MOEFSI
➢Same as MESI, but adds an O “Own” state
➢O state is for blocks that are different from memory and owned by cache. When another CPU requests
a block in M, the cache sends it to the other CPU and changes state to O
➢Cache with O block is responsible for sending data to other read requesters, and updating memory
when the block is evicted
➢Advantages:
❑ Less memory traffic: Memory only updated on an eviction of the O-block, not on a read request for an M-block
❑ Less coherence traffic: Only the cache with the O-block is responsible for sending shared copy on a read request
Shared Memory: Pro and Con
Advantages
• Global address space provides a user-friendly programming perspective to
memory
• Data sharing between tasks is both fast and uniform due to the proximity of
memory to CPUs
Disadvantages:
• Primary disadvantage is the lack of scalability between memory and CPUs.
Adding more CPUs can geometrically increases traffic on the shared memory-
CPU path, and for cache coherent systems, geometrically increase traffic
associated with cache/memory management.
• Programmer responsibility for synchronization constructs that insure "correct"
access of global memory.
• Expense: it becomes increasingly difficult and expensive to design and
produce shared memory machines with ever increasing numbers of processors.
Distributed Memory
Like shared memory systems, distributed memory systems vary widely but share a
common characteristic.
Distributed memory systems require a communication network to connect inter-
processor memory.
Distributed-memory architecture comprises multiple independent processing units,
each with its own memory space.
Communication between processors is achieved through message passing over a
network.
This architecture offers scalability and fault tolerance but requires explicit data
distribution and communication protocols.
Processors have their own local memory. Memory addresses in one processor do not
map to another processor, so there is no concept of global address space across all
processors.
Because each processor has its own local memory, it operates independently.
Changes it makes to its local memory have no effect on the memory of other
processors. Hence, the concept of cache coherency does not apply.
Distributed Memory
When a processor needs access to data in another processor, it is usually the
task of the programmer to explicitly define how and when data is
communicated.
Synchronisation between tasks is likewise the programmer's responsibility.
The network "fabric" used for data transfer varies widely, though it can can
be as simple as Ethernet.
Distributed memory model is a memory architecture model used in parallel or
distributed systems.
Each processor has its own private memory
Processors communicate using message passing
Example Technologies:
MPI (Message Passing Interface)
Supercomputers using cluster nodes
Clusters
Grid Computing
Modern systems can simulate distributed memory inside one physical machine.
Distributed Memory: Pro and Con
Advantages
• Memory is scalable with number of processors. Increase the number of
processors and the size of memory increases proportionately.
• Each processor can rapidly access its own memory without interference and
without the overhead incurred with trying to maintain cache coherency.
• Cost effectiveness: can use commodity, off-the-shelf processors and networking.
Disadvantages
• The programmer is responsible for many of the details associated with data
communication between processors.
• It may be difficult to map existing data structures, based on global memory, to
this memory organization.
• Non-uniform memory access (NUMA) times
Hybrid Distributed-Shared Memory
The largest and fastest computers in the world today employ both
shared and distributed memory architectures.