Simulate Ring All-Reduce and Account for Its Bandwidth
Last updated: November 29, 2026
Quick Overview
Simulate the ring all-reduce used for gradient synchronization: each of n ranks holds a buffer, and after a reduce-scatter phase and an all-gather phase every rank must hold the elementwise sum. Return the results, the number of communication steps, and elements sent per rank.
NVIDIA
November 29, 20260
0
0 solved
Simulate the ring all-reduce used for gradient synchronization: each of n ranks holds a buffer, and after a reduce-scatter phase and an all-gather phase every rank must hold the elementwise sum. Return the results, the number of communication steps, and elements sent per rank.
Asked at NVIDIA for NCCL, distributed training and networking roles, where ring and tree collectives over NVLink and InfiniBand are the core product. The interviewer checks the chunk indexing in both phases, that simultaneous sends are modeled correctly, and that you can derive why ring all-reduce is bandwidth optimal.
What the Interviewer Expects
- Splits each buffer into n chunks and indexes chunks modulo n
- Implements reduce-scatter: at step s rank r sends chunk (r - s) mod n to rank r + 1, which accumulates
- Implements all-gather: rank r forwards its completed chunk (r + 1 - s) mod n, which the receiver overwrites
- Snapshots messages per step so sends are simultaneous
- Derives 2(n-1) steps and 2(n-1)/n times buffer size sent per rank
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Why does the per-rank traffic barely grow with n, and what does grow?
- When is a tree algorithm better than a ring?
- How would you handle a buffer length not divisible by n?
- How does a hierarchical all-reduce exploit NVLink within a node and InfiniBand across nodes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: n equal-length buffers whose length is divisible by n. Output: every rank holds the full elementwise sum, plus step count and per-rank elements sent. Each step, every rank sends one chunk to it...
High-Level Design
Phase 1, reduce-scatter: at step s, rank r sends chunk (r - s) mod n to rank r + 1, which adds it into its own copy. After n-1 steps, rank r holds the complete sum of chunk (r + 1) mod n. Phase ...