6.1.5 · D3 · HinglishParallelism & Multicore

Worked examplesShared memory vs distributed memory

4,499 words20 min read↑ Read in English

6.1.5 · D3 · Hardware › Parallelism & Multicore › Shared memory vs distributed memory

Yeh page parent topic ka drill ground hai. Parent ne tumhe ideas bataye; yahan hum har tarah ke questions count karte hain jo yeh ideas throw kar sakti hain, phir ek example solve karte hain. Kuch bhi hand-wave nahi hai: har number derive kiya gaya hai, har unit check ki gayi hai.

Kisi bhi formula ko touch karne se pehle, ek promise: main koi symbol use nahi karunga jab tak main clearly nahi keh deta ki uska matlab kya hai aur woh kis picture mein rehta hai.

Neeche wali figure exactly yeh do pictures side by side draw karti hai. Left half dekho: teen cores (lavender circles) sab ek butter-coloured memory mein reach karte hain cheap two-way whisper arrows (coral) ke saath — lekin notice karo ki ek table kitni crowded hai. Ab right half: har core apna khud ka mint memory box rakhta hai, aur share karne ka ek hi tarika hai — ek one-way coral "letter" arrow nodes ke beech. Woh left-vs-right contrast hi poori page hai; neeche har example bas ek side par numbers dalta hai.

Figure — Shared memory vs distributed memory

The scenario matrix

Yahan "scenario" = ek shape of problem. Agar hum har row ke liye ek example solve karein, koi bhi exam question tumhe surprise nahi kar sakta. Neeche ki table har cell ko plain words mein naam deti hai — compact symbols (kitne cores/caches), (message size bytes mein) aur (network bandwidth) sab "The three tools" mein immediately baad mein define hain, kisi bhi example ke use karne se pehle.

# Cell (case class) Ise distinct kya banata hai Covered by
A Shared, cache-hit dominated Almost saare accesses cache hit karte hain → tiny average time Ex 1
B Shared, coherence-storm Kaafi cores ek line par likh rahe hain → bus invalidations se flood ho jaata hai Ex 2
C Shared, degenerate: false sharing Alag variables, same cache line → hidden invalidations Ex 3
D Distributed, latency-bound (small msg) Message itna chhota ki fixed stamp cost dominate karti hai Ex 4
E Distributed, bandwidth-bound (big msg) Message itni badi ki per-byte cost dominate karti hai Ex 5
F Distributed, collective (AllReduce) Cost slowly (logarithm ki tarah) badhti hai core count ke saath Ex 6
G Zero / limiting input Empty message; single core; formulas kya kehte hain? Ex 7
H Crossover word problem Real decision: ek task ke liye shared ya distributed choose karo Ex 8
I Exam twist: mixed / trap Setup jo lagta hai ek ko favor karti hai lekin karti nahi Ex 9

Hum parent se teen formulas reuse karte hain, yahan restate ki gayi hain taaki kuch assume na ho.


Cell A — Shared, cache-hit dominated


Cell B — Shared, coherence-storm


Cell C — Shared, degenerate: false sharing


Cell D — Distributed, latency-bound (small message)

Agla figure exactly yahi idea plot karta hai. Horizontal axis message size bytes mein hai (log scale, left par byte se right par bytes tak); vertical axis total send time microseconds mein hai (bhi log scale). Lavender curve follow karo (total ): far left par yeh coral dashed "latency floor" se chipki hai — woh flat stamp hi Ex 4 ka answer hai, coral dot se marked. Mint dotted line pure per-byte term hai; far right par lavender curve uske saath upar jaati hai — woh steep region Ex 5 hai, mint dot se marked. Legend teeno lines ka naam leta hai. Jahan coral floor aur mint slope cross karte hain woh "latency vs bandwidth" crossover hai — poori distributed story ek plot mein.

Figure — Shared memory vs distributed memory

Cell E — Distributed, bandwidth-bound (big message)


Cell F — Distributed, collective (AllReduce grows like log N)


Cell G — Zero aur limiting inputs


Cell H — Crossover word problem


Cell I — Exam twist / trap


Recall Self-test (reveal karne se pehle answer do)

Average access time formula hit aur miss ko kisse weight karta hai? ::: Hit rate aur uske complement se; yeh ek weighted average hai, hamesha aur ke beech. Ex 2 mein total 14 kyun hai, 64 kyun nahi? ::: Pehle broadcast ke baad (7 invalidations) sirf ek cache line own karta hai, isliye baad ki writes sirf ownership migrate karti hain (7 hand-offs) — kisi aur ke paas invalidate karne ke liye copy nahi. False sharing (Ex 3) independent variables ke saath bhi kyun hurt karta hai? ::: Coherence poori cache lines par kaam karti hai; ek 64-byte line mein do logically-separate ints cores ke beech line ko ping-pong karte hain. Ek zero-byte message kitna cost karta hai (Ex 7)? ::: Exactly — fixed latency; kuch bhi, chahe kuch bhi na ho, free mein nahi bhej sakte. Ex 8 mein shared memory kyun jeeta hai? ::: Kaafi tiny frequent updates ke liye, message stamp () shared update ( ns) ko dwarf karta hai, messaging ko ~33× slower banata hai. Batching win (Ex 9) exist karta hai kyunki latency ___ per pay hoti hai aur bandwidth ___ per. ::: per message; per byte.