UNIT 2: BLOCKCHAIN TECHNOLOGY & PARALLEL COMPUTING
I. BLOCKCHAIN TECHNOLOGY
A. Fundamental Cryptography
Cryptographic Hash Functions
A deterministic algorithm that maps data of arbitrary size to a fixed-size string (hash/digest). Essential for blockchain integrity.
Properties:
-
Deterministic: Same input → same output.
-
Quick Computation: Fast to generate for any input.
-
Pre-image Resistance: Hard to reverse (find input from hash).
-
Small Change → Big Difference: Avalanche effect; minor input change drastically alters output.
-
Collision Resistant: Hard to find two different inputs with same output.
-
Puzzle-friendly: Hard to find an input that hashes to a desired output (crucial for PoW).
[!TIP] Exam Focus: Properties are frequently asked. Link each property to its blockchain use (e.g., collision resistance prevents block tampering).
Public Key Cryptography (Asymmetric)
Uses a key pair: Public Key (shared) and Private Key (secret).
-
Encryption:
Encrypt(Public Key, Message)→ OnlyPrivate Keycan decrypt. -
Digital Signature:
Sign(Private Key, Message)→ Anyone withPublic Keycan verify signature and message integrity. -
Application in Blockchain: Creates Bitcoin addresses (hashed public keys) and signs transactions to prove ownership without revealing the private key.
Merkle Trees
A binary hash tree where leaves are hashes of data blocks (e.g., transaction hashes). Non-leaf nodes are hashes of their children.
DiagramCANVAS: A binary tree. Leaf nodes L1, L2, L3, L4 are hashes of transactions. Parent nodes H12 = Hash(H1+H2), H34 = Hash(H3+H4). Root = Hash(H12+H34).
Importance in Blockchain:
-
Efficient Verification: Allows Merkle Proof to verify a single transaction's inclusion in a block without downloading the entire block (lightweight clients/SPV).
-
Data Integrity: Any change in a leaf transaction changes all ancestor hashes up to the root. Root hash is stored in block header; tampering is easily detectable.
-
Scalability: Enables pruning of old transactions while maintaining proof of their existence.
[!TIP] Common Pitfall: Don't just state "used for efficiency." Explicitly mention Merkle Proof and SPV (Simplified Payment Verification).
B. Blockchain Structure and Operation
Block Structure
DiagramCANVAS: A block diagram with two main sections: Block Header and Block Body. Header contains: Version, Previous Block Hash, Merkle Root, Timestamp, Difficulty Target, Nonce. Body contains: Transaction Counter & List of Transactions.
-
Block Header: Contains metadata. Previous Block Hash creates the immutable chain.
-
Block Body: Contains the list of transactions. In Bitcoin, the first is the Coinbase transaction (miner reward).
Bitcoin P2P Network
A decentralized, unstructured overlay network. Nodes (full nodes, miners, SPV clients) connect to a few random peers.
-
Transaction Propagation: A node broadcasts a new transaction to its peers, who validate and rebroadcast (flooding protocol).
-
Block Propagation: A miner that finds a valid block broadcasts it. Nodes validate the block (transactions, PoW) and adopt it if valid, extending the chain.
Transaction Processing in Bitcoin
-
Creation: User A signs a transaction (inputs = UTXOs from previous tx, outputs = amount to B + change).
-
Broadcast: Sent to P2P network.
-
Validation by Nodes: Checks digital signature, UTXO existence, no double-spend, valid script.
-
Mempool: Valid transactions wait in the memory pool (mempool) to be included in a block.
-
Mining: Miners select transactions from mempool, create a candidate block, and solve PoW.
-
Confirmation: Once block is mined and accepted, transaction gets 1 confirmation. Each subsequent block adds another confirmation.
Double Spending Problem & Prevention
-
Problem: Malicious user spends the same digital token (UTXO) twice by broadcasting two conflicting transactions.
-
Prevention in Blockchain:
-
Global Consensus: The network agrees on a single, canonical history of transactions (the longest valid chain).
-
Confirmation Depth: A transaction in a block is "final" only after several subsequent blocks are added (typically 6 in Bitcoin). The probability of an attacker rewriting history decreases exponentially with confirmations.
-
Timestamp & Ordering: Transactions are ordered in blocks. The first transaction to be included in a block that gets accepted by the network is the valid one.
-
C. Consensus Mechanisms
Overview of Distributed Consensus
Agreement among distributed nodes on the state of the ledger (which block is next) without a central authority. Must handle node failures and malicious actors (Byzantine faults).
Proof of Work (PoW)
-
Concept: Miners compete to solve a computationally intensive but easily verifiable puzzle: find a nonce such that
Hash(Block Header) < Target. -
HashCash PoW: Original idea (anti-spam). Puzzle: find
xsuch thatHash(Email + x)hasnleading zeros. -
Bitcoin PoW: Puzzle:
Hash(Version | Prev_Hash | Merkle_Root | Timestamp | Bits | Nonce) < Target. Difficulty adjusts to maintain ~10 min block time. -
Attacks on PoW:
-
51% Attack: If an attacker controls >50% hash power, they can exclude/alter transactions and double-spend.
-
Monopoly Problem: Mining power centralizes in large pools due to economies of scale, defeating decentralization.
-
Proof of Elapsed Time (PoET)
-
Concept: Uses a trusted execution environment (TEE, e.g., Intel SGX) to randomly elect a leader.
-
Process:
-
Each validator requests a random wait time from the TEE.
-
TEE confidentially returns a random wait time.
-
Validator with the shortest wait time wakes up first and proposes the next block.
-
Others verify the TEE attestation and the block.
-
-
Advantage: Low energy consumption vs PoW. Disadvantage: Relies on trusted hardware vendor.
Byzantine Fault Tolerance (BFT)
Tolerates up to f Byzantine (malicious/faulty) nodes in a system of 3f+1 nodes.
-
Lamport-Shostak-Pease (Practical BFT) Algorithm:
-
Primary (Leader) broadcasts a value (proposal).
-
Replicas broadcast
PRE-PREPAREmessage with proposal to all. -
Replicas collect
PREPAREmessages from2fothers. On receiving2f+1PREPAREs, they enter prepared state and broadcastCOMMIT. -
On receiving
2f+1COMMITs, they enter committed state and execute the value.
Key: Requires
3f+1nodes to tolerateffaults. Communication-heavy (O(n²)). -
Raft Consensus Algorithm
-
Concept: A leader-based consensus for non-Byzantine (crash-fault) environments. Prioritizes understandability.
-
Roles: Leader, Follower, Candidate.
-
Process:
-
Leader Election: Timeout → Candidate requests votes. Wins with majority → becomes Leader.
-
Log Replication: Leader appends entries to its log and replicates to Followers. When majority replicate, entry is committed.
-
-
Difference from BFT: Simpler, but assumes nodes are only faulty (crash), not malicious.
Consensus in Permissioned Blockchains
-
Design Issues: Identity management, membership service, performance vs. decentralization trade-off, regulatory compliance.
-
Types of Consensus Protocols:
-
Crash-Fault Tolerant (CFT): Raft, Paxos. For trusted environments.
-
Byzantine-Fault Tolerant (BFT): PBFT, Tendermint. For hostile environments with known identities.
-
Hybrid: e.g., HoneyBadgerBFT (BFT, asynchronous).
-
[!TIP] Exam Distinction: Permissionless (Bitcoin, Ethereum) → PoW/PoS, anonymous, Sybil-resistant. Permissioned (Fabric, Corda) → Known identities, BFT/RAFT, higher throughput.
D. Smart Contracts
Definition & Essential Characteristics
A self-executing contract with terms written in code, deployed on a blockchain. Characteristics:
-
Self-Executing: Automatically executes when predefined conditions are met.
-
Immutable: Once deployed, code cannot be changed (unless designed with upgradeability).
-
Decentralized: Runs on all nodes in the network.
-
Deterministic: Same input → same output on all nodes.
-
Trustless: No need for trusted intermediary.
-
Transparent: Code is visible to all.
Bitcoin Script
-
A stack-based, non-Turing-complete language (no loops).
-
Purpose: Simple transaction validation logic (e.g.,
Pay-to-Public-Key-Hash- P2PKH). -
Limitation: Cannot express complex logic (e.g., multi-step agreements). Not a "smart contract" platform in the modern sense.
Ethereum Smart Contracts
-
Written in Solidity (Turing-complete, high-level).
-
Compiled to EVM bytecode and deployed to an Ethereum address.
-
Gas: Execution fee paid in ETH to prevent infinite loops/spam.
-
Features: Can store state, call other contracts, handle complex logic (DeFi, NFTs, DAOs).
Hyperledger Fabric Smart Contracts (Chaincode)
-
Written in Go, Java, or JavaScript.
-
Execution: Runs in a separate Docker container (chaincode container) from the peer process.
-
Key Difference: Execute-Order-Validate architecture. Transactions are executed (simulated) by endorsing peers, then ordered, then validated by all peers. This allows for private data and confidentiality.
-
Access Control: Managed by Membership Service Provider (MSP).
[!TIP] Key Contrast: Ethereum = Order-Execute (global state, all nodes execute all). Fabric = Execute-Order-Validate (private data, selective execution).
E. Blockchain Platforms
Bitcoin
-
Purpose: Decentralized digital currency (peer-to-peer electronic cash).
-
Consensus: Proof of Work (SHA-256).
-
Smart Contracts: Limited (Bitcoin Script).
-
Token: BTC (native currency, used for fees & rewards).
Ethereum
-
Purpose: Decentralized platform for applications (world computer).
-
Consensus: PoW (Eth1) → PoS (Eth2/Casper).
-
Smart Contracts: Full-featured (Solidity, Vyper).
-
Token: ETH (native currency for gas).
-
Key Feature: EVM (Ethereum Virtual Machine).
Hyperledger Fabric
-
Purpose: Permissioned enterprise blockchain framework for confidential transactions.
-
Architecture:
-
Peers: Host ledgers & chaincode. Endorsing Peers simulate transactions.
-
Ordering Service: Orders transactions into blocks (Raft, Kafka, BFT-SMaRt). Separate from peers.
-
Membership Service: Manages identities (MSP).
-
Channels: Private subnets for confidential transactions between specific organizations.
DiagramCANVAS: Fabric Architecture. Client App -> Peers (Endorsing, Committing) & Ordering Service. Peers connected via Channels. MSP box managing identities. -
-
Identities & Policies:
-
Identities: X.509 certificates issued by a CA, managed by MSP.
-
Policies: Define who can read/write (e.g.,
AND('Org1.member', 'Org2.member')). Policies for endorsement, validation, channel creation.
-
-
Use Cases: Supply chain traceability, trade finance, healthcare records, inter-bank settlements.
Ripple & Corda
| Feature | Ripple (XRP Ledger) | Corda |
|---|---|---|
| Primary Use | Cross-border payments, liquidity | Regulated financial agreements (legal contracts) |
| Consensus | RPCA (Ripple Protocol Consensus Algorithm) - Unique Node List (UNL) based, not PoW/BFT. | Not a blockchain. Uses Notary clusters (BFT/RAFT) for transaction uniqueness. No global ledger. |
| Data Sharing | All transactions public on ledger. | Point-to-point. Only involved parties see transaction data. |
| Smart Contracts | Hooks (lightweight, on-ledger logic). | CorDapps (JVM-based, enforce legal prose). |
| Token | XRP (native digital asset for bridge currency). | No native token. Assets are represented as states. |
| Privacy | Low. | High by design. |
F. Blockchain Identity Management Systems
-
Problem: Centralized identity providers (Google, Facebook) control user data → single point of failure, privacy loss.
-
Blockchain Solution: Self-Sovereign Identity (SSI).
-
User controls their identity (private keys).
-
Identity is a set of verifiable credentials (VCs) issued by authorities (e.g., university degree, passport).
-
VCs are cryptographically signed and stored in a digital wallet.
-
Decentralized Identifiers (DIDs): Unique IDs anchored on-chain that point to DID documents (public keys, service endpoints).
-
Verification: Relying party verifies VC signature & issuer's DID without contacting the issuer directly.
-
-
Benefit: Privacy, user control, reduced fraud, interoperability.
G. Mining
Block Mining Process (Bitcoin)
-
Collect pending transactions from mempool.
-
Create candidate block header (Prev_hash, Merkle_root, Timestamp, Bits, Nonce).
-
Start PoW: Iterate Nonce (and extra nonce) to find
Hash(Header) < Target. -
On success: Broadcast block to network.
-
On acceptance: Receive block reward (new BTC) + transaction fees.
Types of Mining
-
Solo Mining: Individual miner. Very low probability of finding a block with small hash power.
-
Pool Mining: Miners combine hash power. Pool operator finds block, rewards split proportionally. Reduces variance.
-
Cloud Mining: Renting hash power from a remote facility. Often scams.
-
Staking (for PoS): "Minting" by locking up coins as collateral (e.g., Ethereum 2.0).
H. Applications and Use Cases
Mortgage Process: Traditional vs Blockchain
| Traditional | Blockchain-Enabled |
|---|---|
| Manual, paper-heavy (weeks). | Digitized, automated (days/hours). |
| Multiple intermediaries (lenders, title companies, appraisers). | Shared, permissioned ledger among verified participants. |
| Data silos; repeated verification. | Single source of truth. Immutable audit trail. |
| High risk of fraud, errors. | Smart contracts automate escrow, payments upon conditions (e.g., appraisal complete). |
| Slow, costly. | Faster, cheaper, transparent. |
Supply Chain Finance
-
Problem: SMEs face cash flow gaps due to long payment cycles. Banks rely on manual, slow invoice verification.
-
Blockchain Solution:
-
Immutable record of invoice creation → approval → payment on a shared ledger.
-
Smart contracts automatically release payment upon delivery confirmation (IoT sensor data).
-
Invoice financing: Banks can instantly verify invoice authenticity on-chain, reducing risk and enabling faster lending to SMEs.
-
Improvement: Transparency, reduced fraud, faster settlements, lower costs.
-
Cross-Border Payments
-
Problem: Traditional (SWIFT) is slow (2-5 days), expensive (multiple fees), lacks transparency.
-
Blockchain Solution (e.g., RippleNet):
-
Use a digital asset (XRP) as a bridge currency for instant liquidity.
-
Transactions settle in seconds on a distributed ledger.
-
Lower costs, end-to-end tracking, 24/7 operation.
-
Blockchain-Enabled Trade (Trade Finance)
-
Process: Letters of Credit (LC), bills of lading, invoices.
-
Blockchain Solution (e.g., we.trade, Marco Polo):
-
All trade documents (LC, bill of lading) digitized as tokens on a permissioned ledger.
-
Smart contracts automate LC issuance, amendment, and payment upon document presentation.
-
Benefit: Reduces processing from 5-10 days to <24 hours, cuts fraud, improves trust among unknown trading partners.
-
II. PARALLEL COMPUTING
A. Basic Terminology and Concepts
| Terminology | Parallelism | Pipelining |
|---|---|---|
| Definition | Simultaneous execution of multiple tasks/instructions on multiple processing units. | Overlapped execution of instruction stages (IF, ID, EX, MEM, WB) in a single processor. |
| Hardware | Requires multiple processors/cores. | Implemented within a single CPU's control unit. |
| Goal | Increase throughput (tasks per unit time). | Increase instruction throughput (CPI reduction). |
| Analogy | Multiple workers building a house. | Assembly line for building houses. |
| Terminology | Serial Processing | Parallel Processing |
| :--- | :--- | :--- |
| Execution | One instruction at a time, sequentially. | Multiple instructions/instructions streams executed simultaneously. |
| Hardware | Uniprocessor. | Multiprocessor/Multicore, GPU, cluster. |
| Speedup Limit | Baseline. | Limited by Amdahl's Law. |
| Terminology | Control Flow Computer | Data Flow Computer |
| :--- | :--- | :--- |
| Execution Trigger | Program counter (PC) dictates next instruction. | Instruction executes when its input data is available. |
| Architecture | Von Neumann. | No PC; uses a token-driven execution graph. |
| Parallelism | Implicit (compiler/CPU finds ILP). | Explicit & Massive (inherent in program structure). |
| Status | Dominant. | Research/niche (e.g., TensorFlow dataflow graphs). |
| Terminology | Uniprocessor System | Multiprocessor System |
| :--- | :--- | :--- |
| Definition | Single CPU. | Two or more CPUs sharing memory & resources. |
| Parallelism | None (or ILP via pipelining/superscalar). | True parallelism (multiple threads/processes). |
| Goal | Faster single-threaded performance. | Increased throughput, responsiveness, scalability. |
B. Parallel Architectures
Characteristics of MIMD Multiprocessors
(Multiple Instruction streams, Multiple Data streams)
-
Independent Execution: Each processor has its own control unit, executes its own instruction stream.
-
Shared Memory: Processors communicate via a shared global memory (UMA or NUMA).
-
Asynchronous Operation: Processors run asynchronously; need synchronization (locks, barriers).
-
Heterogeneity Possible: Can have different processor types (CPU+GPU).
-
Programming Model: Shared-memory programming (threads, OpenMP).
Distinction from: Multiple Computer Systems (distributed memory, networked, OS per node) & Computer Networks (loosely coupled, geographically dispersed).
Pipeline Speedup Proof (k-stage linear pipeline)
-
Non-pipelined (Serial) Processor: Time for one instruction =
k * t(wheret= stage delay). Time forninstructions =n * k * t. -
Pipelined Processor:
-
First instruction finishes at
k * t. -
Each subsequent instruction finishes every
t(steady state). -
Time for
ninstructions =(k * t) + (n - 1) * t.
-
-
Speedup (S):
$$ S = \frac{\text{Time}_{\text{serial}}}{\text{Time}_{\text{pipeline}}} = \frac{n * k * t}{k * t + (n - 1) * t} $$
For large `n` (steady state), `S ≈ \frac{n * k * t}{n * t} = k`.
\boxed{S_{\text{max}} = k}
- Ideal Speedup equals number of stages. Real Speedup <
kdue to pipeline hazards (structural, data, control).
C. Memory Systems and Cache Coherence
Disadvantages of Caches using Virtual Addresses
-
Cache Flush on Context Switch: Different processes use same virtual addresses but different physical pages. Cache must be flushed (or tagged with ASID) on every context switch → high overhead.
-
Coherence Complexity: Multiple virtual addresses (from different processes) may map to same physical address. Cache coherence protocols must handle this aliasing → more complex tags (need physical address or process ID).
-
I/O & DMA Issues: Direct Memory Access (DMA) uses physical addresses. Cache with virtual addresses must handle I/O coherence (maintaining consistency between cache and I/O-modified memory).
Solution: Physically Addressed Caches (PAC). Tags store physical addresses. Requires MMU lookup before cache access (adds latency) but solves above problems.
Centralized vs Distributed Shared Caches
| Centralized Shared Cache | Distributed Shared Cache | |
|---|---|---|
| Structure | Single, large cache (L3) shared by all cores. | Each core/node has a local cache (L1/L2), but caches are connected in a network. |
| Pros | Simple coherence (snooping on single bus), large capacity, low latency for shared data. | Scalable (no single point of congestion), lower average access latency for local data, no shared bus bottleneck. |
| Cons | Bus bottleneck (snooping traffic), single point of failure, limited scalability (cores > 8-16). | High latency for remote cache access, complex coherence (directory-based), non-uniform memory access (NUCA). |
| Example | Modern multi-core CPUs (Intel, AMD). | NUMA systems, many-core GPUs, multi-socket servers. |
Snooping-based vs Directory-based Cache Coherence
| Snooping-based | Directory-based | |
|---|---|---|
| Mechanism | All caches monitor (snoop) a shared broadcast medium (bus) for memory transactions. | A central directory tracks the state (Shared/Modified/Invalid) of each cache line and which caches hold it. |
| Scalability | Poor. Broadcast traffic O(n) → bus saturation. |
Good. Point-to-point messages O(1) or O(log n). |
| Latency | Low for local transactions (single bus cycle). | Higher (directory lookup + messages). |
| Complexity | Simple protocols (MSI, MESI). | Complex directory management (distribution, false sharing). |
| Used In | Small-scale SMPs (≤16 cores). | Large-scale NUMA, multi-socket, clusters. |
Multicache Coherence Problem & Solutions
-
Problem: In a system with multiple caches, a memory location cached in two places may be modified by one CPU, leaving the other with a stale value.
-
Solutions:
-
Snooping Protocols (Bus-based):
-
Write-Invalidate: On write, broadcast invalidate. Other caches invalidate line.
-
Write-Update (Write-Broadcast): On write, broadcast new data. Other caches update line.
-
States: MSI (Modified, Shared, Invalid) → MESI (adds Exclusive).
-
-
Directory Protocols (Scalable):
-
A directory (central or distributed) tracks sharers.
-
On read/write, processor queries directory. Directory coordinates invalidations/updates.
-
-
Timestamp-based: Use timestamps to order accesses (rare).
-
Hardware Solutions: Memory Order Buffers (MOB), store buffers to manage ordering within a core.
-
D. Specialized Architectures
GPU Architecture and Applications
-
Architecture (SIMT - Single Instruction, Multiple Thread):
-
Many-core: Hundreds to thousands of smaller, efficient CUDA Cores / Stream Processors.
-
Grouped into Streaming Multiprocessors (SMs). Each SM has:
-
Warp Schedulers (32 threads = 1 warp).
-
Registers, shared memory (scratchpad), texture units.
-
-
High Memory Bandwidth: GDDR/HBM.
-
Design Goal: Throughput over latency. Hide memory latency with massive thread switching.
DiagramCANVAS: GPU Block Diagram. Host (CPU) connected via PCIe to GPU DRAM. GPU contains multiple SMs. Each SM has warp schedulers, registers, shared memory, cores. Warp = 32 threads. -
-
Applications:
-
Graphics Rendering: Pixel/vertex shading (highly parallel).
-
General-Purpose GPU (GPGPU): Scientific computing, AI/Deep Learning (matrix ops), molecular dynamics, financial modeling, video encoding.
-
Key: Problems with high data parallelism and high arithmetic intensity.
-
E. Parallel Programming
Transaction vs Transactional Memory
| Transaction (DB) | Transactional Memory (TM) | |
|---|---|---|
| Purpose | ACID properties for persistent data (disk). | Atomicity & Isolation for in-memory data (shared memory). |
| Scope | Long-lived, durable. | Short-lived, in program scope. |
| Conflict Handling | Locking, deadlocks possible. | Optimistic: Execute speculatively, commit only if no conflict. |
| Implementation | Software (DBMS). | Hardware TM (HTM) (Intel TSX) or Software TM (STM). |
| Goal | Replace explicit locks for shared memory concurrency. |
Categories of Parallelism
-
Data Parallelism: Same operation on different data elements (SIMD, GPU kernels,
#pragma omp parallel for). -
Task Parallelism: Different tasks (functions) run concurrently (thread pool,
std::async). -
Pipeline Parallelism: Task broken into stages; different data items in different stages (assembly line). Common in streaming apps.
-
Implicit Parallelism: Compiler/Runtime extracts parallelism automatically (auto-parallelizing compilers, OpenMP
#pragma).
Steps to Design Parallel Programs
-
Decomposition: Break problem into concurrent tasks (data/task/pipeline).
-
Assignment: Map tasks to processes/threads (static/dynamic).
-
Orchestration: Manage interactions (synchronization: locks, barriers; communication: message passing, shared memory).
-
Mapping: Bind processes/threads to physical processors (affinity) for performance.
-
Testing & Debugging: Race conditions, deadlocks. Use tools (Helgrind, ThreadSanitizer).
Distributed-Memory Programming with MPI
-
Model: Processes with private address spaces. Communicate via explicit messages.
-
Key MPI Concepts:
-
MPI_Init/MPI_Finalize -
Communicator:
MPI_COMM_WORLD(all processes). -
Rank: Process ID in communicator.
-
Size: Total processes.
-
Point-to-Point:
MPI_Send,MPI_Recv(blocking/non-blocking). -
Collective:
MPI_Bcast(broadcast),MPI_Scatter/Gather,MPI_Reduce.
-
-
Typical Pattern:
MPI_Init(...); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); if(rank == 0) { data = ...; MPI_Scatter(data, ...); } else { MPI_Scatter(NULL, ...); } local_compute(); MPI_Reduce(&local_result, &global_result, ...); MPI_Finalize();
I/O Handling in Parallel Programming Languages
-
Challenge: Multiple processes/threads writing to same file → race conditions, interleaved output.
-
Solutions:
-
Independent Files: Each process writes to its own file (
output.rank0,output.rank1). Post-process to combine. -
Collective I/O: Processes cooperate to read/write a shared file in disjoint regions (MPI-IO
MPI_File_read_at). OS/parallel filesystem ( Lustre, GPFS) optimizes. -
Synchronized I/O: Use a lock (e.g.,
#pragma omp criticalfor OpenMP) so only one thread writes at a time. Slow. -
Log-Structured: Each process writes to a private buffer; a dedicated I/O process collects and writes sequentially.
-
Thread Management
-
Creation/Joining:
pthread_create,pthread_join(POSIX);std::thread(C++11). -
Thread Pool: Pre-create a fixed number of worker threads. Submit tasks (work queues). Reduces creation overhead, controls concurrency.
-
Thread-Local Storage (TLS):
__thread(C),thread_local(C++). Each thread has its own copy of a variable. -
Affinity: Bind thread to specific CPU core (
pthread_setaffinity_np) to reduce cache misses and context switches.
Parallel Data Management
-
Partitioning: Distribute data structures (arrays, graphs) across processors.
-
Block: Contiguous chunks.
-
Cyclic: Round-robin assignment (good for load balancing).
-
Block-Cyclic: Hybrid.
-
-
Replication: Copy read-only data on all processors.
-
Redistribution: Moving data between partitions (expensive). Needed for algorithm phases with different access patterns.
-
Load Balancing: Dynamic scheduling (
#pragma omp for schedule(dynamic)), work-stealing.
Fusing Map and Scan Operations
-
Map: Apply function
fto each element:[a,b,c] → [f(a), f(b), f(c)]. Embarrassingly parallel. -
Scan (Prefix Sum): Compute all intermediate sums:
[a,b,c] → [a, a+b, a+b+c]. Has data dependency. -
Fusing: Combining map and scan into a single pass to reduce memory traffic.
-
Example: Compute
scan(f(x))without creating intermediate array. -
Algorithm: Each thread computes local
f(x)and local scan. Then a global scan on the partial sums. Finally, adjust each local scan by adding the global prefix sum of its partition. -
Benefit:
O(n)work,O(log n)span (parallel time), half the memory reads/writes vs separate map+scan.
-
F. Performance and Future Trends
Performance Metrics of Parallel Systems
-
Speedup (S):
S = T_serial / T_parallel. -
Efficiency (E):
E = S / p(p = processors). Measures resource utilization. -
Scalability: Ability to maintain efficiency as
pincreases. Strong scaling: Fixed problem size, increasep. Weak scaling: Increase problem size withp. -
Amdahl's Law:
S_max = 1 / ( (1 - P) + P/p )whereP= parallel fraction. Serial portion limits speedup. -
Gustafson's Law:
S = p - (1 - P)*(p - 1). Assumes problem size scales withp. More optimistic. -
Cost-Effectiveness:
S / cost(p).
Architectural Characteristics of Future Systems
-
Heterogeneity: Integration of CPU + GPU + FPGA + AI Accelerators (TPU, NPU) on package/chip.
-
Memory Hierarchy Deepening: More levels (HBM, MCDRAM), non-uniform access (NUMA) dominant.
-
Interconnect Evolution: From buses → rings → meshes → chiplet-based interconnects (UCIe) with high bandwidth, low latency.
-
Power & Thermal Limits: Dark Silicon - not all transistors can be powered simultaneously. Requires specialized accelerators for efficiency.
-
Approximate Computing: Trading precision for energy/performance (e.g., AI inference).
-
In-Memory/Processing-in-Memory (PIM): Reducing data movement by placing compute near memory (HBM with logic layer).
-
Quantum-Classical Hybrid: Quantum accelerators for specific problems (optimization, simulation) coupled with classical HPC systems.
-
Security & Reliability: Hardware support for confidential computing (TEEs like Intel SGX, AMD SEV), memory safety (CHERI), and resilience (fault-tolerant designs).
[!TIP] Exam Focus: Amdahl vs Gustafson is a classic distinction. Future trends emphasize specialization over generalization due to power constraints.