Skip to content

HPC / CFD Written Exam Preparation

Four practice sets (basic → very hard), short/medium/long answer templates, comparison tables, common traps, and time-management tips. Use this last week before the exam.


Time-Management Plan

For a typical 90-minute, 60-mark written exam:

  1. 0–5 min: read every question; mark difficulty (★ easy, ★★ medium, ★★★ hard).
  2. 5–60 min: answer in this order — easiest → hardest. Spend ~ minute per mark.
  3. 60–80 min: tackle hardest questions you skipped.
  4. 80–90 min: revise; check command syntax; write missing units.

Each answer should follow:

  • State (definition / claim).
  • Show (example / command / code / diagram).
  • Explain (one sentence interpretation).
  • Conclude (link to HPC/CFD).

If short on time, write bullet points — graders can scan them.


Answer Templates

Definition Question Template

"[Term] means [...]. It is used for [...]. In HPC/CFD, it helps because [...]. Example: [...]."

Command-Explanation Template

"The command cmd flags args does [...]. The flag -X means [...]. The input is [...]. The output is [...]. A common mistake is [...]."

Code-Explanation Template

"This code first [...]. Then [...]. Finally [...]. The output is [...]. The important concept demonstrated is [...]."

Difference-Question Template

"The main difference between A and B is [...]. A is used when [...]. B is used when [...]. Example: [...]."

Debugging Template

"The error is [...]. It happens because [...]. The corrected version is .... This works because [...]."

Long-Answer Template

Introduction. (1 sentence: what) Main concept. (2-3 sentences: theory) Step-by-step. (numbered list of how) Diagram. (text sketch + label) Example command/code. (block) Real HPC/CFD link. (1-2 sentences) Conclusion. (1 sentence: takeaway)


Comparison Tables (memorise)

Unix vs Linux

Aspect Unix Linux
Year 1970 1991
Owner AT&T → SCO Linus + community
Licence proprietary GPLv2
Cost paid free
Variants AIX, Solaris, HP-UX, macOS Ubuntu, Rocky, …

Unix vs POSIX vs GNU vs Linux

Unix POSIX GNU Linux
What OS family Standard Userland Kernel
When 1970 1988 1983 1991
Who AT&T IEEE Stallman Torvalds

Kernel vs User mode

Mode Privileges Crash impact Examples
User limited program dies bash, gcc
Kernel full system panic drivers, schedulers

Absolute vs Relative path

Absolute Relative
Starts with / yes no
Depends on cwd no yes
Example /home/me/x ../data/x

> >> < 2> 2>&1

Op Action
> overwrite stdout
>> append stdout
< feed stdin from file
2> redirect stderr
2>&1 merge stderr into stdout

Redirection vs Pipe

redirect > pipe \|
target file on disk next command
persistent yes no

Regex vs Globbing

Regex Glob
Used by grep/sed/awk/Vim shell
Operates on text filenames
* means 0+ of previous any string
? means optional previous one char
Anchors ^ $ none

BRE vs ERE

Char BRE ERE
() {} + ? \| literal meta
escape gives meta literal
Tools grep, sed grep -E, awk

grep vs awk vs sed

grep awk sed
Job select lines field/record processing stream edit
Strength fast filter arithmetic substitution
Example grep ERROR f awk -F, '{print $1}' sed 's/foo/bar/g'

scp vs rsync vs sftp vs sshfs

scp rsync sftp sshfs
Mode one-shot one-shot incremental interactive mount
Resumable no yes partial n/a
Best for quick copy repeated big manual exploration edit live

while vs until

while until
Loops while cond is true cond is false
Exits when cond becomes false cond becomes true

for (list) vs for (C-style) vs while

for x in list for ((;;)) while [ cond ]
Use known list counter condition
Example for f in *.cpp for ((i=0;i<5;++i)) while read l

Script vs compiled program

Script Compiled
Execution interpreter CPU-native
Speed slow for math fast
Edit-run cycle fast recompile

Call by value / pointer / reference

value pointer reference
Syntax f(int) f(int*) f(int&)
Caller passes copy address original alias
Modifies caller no yes yes
Nullable n/a yes no

Pointer vs Reference

pointer reference
Syntax int *p; *p int& r; r
Reseat yes no
Null yes no

Git commit vs push

commit push
Where local repo remote repo
Visible to team no yes

Branch vs Merge

branch merge
Action new line of dev combine two
Command git switch -c x git merge x

OpenMP vs MPI

OpenMP MPI
Memory shared distributed
Within one node many nodes
API pragmas function calls
Compile -fopenmp mpic++

Make vs CMake

Make CMake
Type builder generator
Cross-platform limited yes
Files Makefile CMakeLists.txt

gdb step vs next

step next
Function call enters runs as one unit
Use unknown function known function

valgrind vs ASan

valgrind ASan
Recompile no yes
Slowdown ~30× ~2×

PRACTICE SET 1 — BASIC

Theory

Q1.1 Define HPC.
A. HPC aggregates many cores so calculations finish in hours not years; needed for CFD where \(10^{9}\) cells × \(10^{5}\) steps require \(\geq 10^{15}\) ops.

Q1.2 What is the kernel?
A. The privileged core of the OS that schedules processes, manages memory, talks to drivers, and serves system calls.

Q1.3 Difference between login shell and non-login shell.
A. A login shell reads /etc/profile + ~/.bash_profile; a non-login interactive shell reads ~/.bashrc. Convention: source .bashrc from .bash_profile.

Commands

Q1.4 Write chmod to give owner read+write+execute, others read.
A. chmod 744 file (or symbolic chmod u=rwx,go=r file).

Q1.5 Show contents of file ~/data.txt.
A. cat ~/data.txt.

Q1.6 Find every .log file in ~.
A. find ~ -type f -name "*.log".

Output Prediction

Q1.7 echo "x" > a; echo "y" > a; cat a
A. y (overwrite).

Q1.8 echo "x" >> a; echo "y" >> a; cat a (after : > a) →
A. x newline y.

Marking-Scheme Answers

For each: 1 mark per concept (max 3). E.g. Q1.1: 1 HPC name expansion + 1 reason for CFD + 1 example.

Common mistakes

  • Confusing > with >>.
  • Forgetting chmod is chmod (not chmode).

PRACTICE SET 2 — INTERMEDIATE

Output Prediction

Q2.1 Predict:

$ ls -l | grep "^d" | wc -l
A. Number of subdirectories in current directory.

Q2.2 Given data.csv:

id,name,dept,salary
1,Alice,Eng,80000
2,Bob,Sales,40000
3,Carol,Eng,95000
Run: awk -F, 'NR>1 && $3=="Eng"{s+=$4; n++} END{print s/n}' data.csv
A. 87500.

Q2.3 Given t.txt:

foo bar foo
baz foo
Run: sed -i 's/foo/FOO/' t.txt; cat t.txt
A.
FOO bar foo
baz FOO
(only first per line because no g).

Small Bash scripts

Q2.4 Write a Bash script that prints "even" or "odd" for a positional argument.
A.

#!/bin/bash
[ -z "$1" ] && { echo "need arg"; exit 1; }
(( $1 % 2 == 0 )) && echo even || echo odd

Regex / grep / sed / awk

Q2.5 Regex matching German postal codes (5 digits).
A. ^[0-9]{5}$.

Q2.6 sed to comment lines containing TODO with //.
A. sed -E 's|^(.*TODO.*)$|// \1|' file.

Q2.7 awk: column 2 sum but only when col 3 != "skip".
A. awk '$3 != "skip" {s+=$2} END{print s}' file.

Git workflow

Q2.8 Steps to push a new branch feature/x and open a Merge Request.
A. git switch -c feature/x; ...edit...; git add .; git commit -m "..."; git push -u origin feature/x then open MR in GitLab UI.

Marking & Common Mistakes

  • Q2.1: count includes "total" line if not filtered. (Use ^d to be safe.)
  • Q2.3: forgot g flag → only one substitution per line. The example is intentional.

PRACTICE SET 3 — HARD

Debugging

Q3.1 Find the bug:

int *p; *p = 5;
A. p is uninitialised; *p writes to random memory → segfault. Fix: initialise (int a; int *p = &a; *p = 5;).

Q3.2 Find the bug:

if [ $a == "yes" ]; then echo OK; fi
A. Single brackets need spaces around = (not ==); also unquoted $a may break if empty. Fix: if [ "$a" = "yes" ]; then ... fi or [[ "$a" == "yes" ]].

Q3.3 Find the bug:

while [ $c -lt 5 ]; do
    arr[$c]=23
done
A. Infinite loop — c never increments. Fix: ((c++)) inside.

Multi-step workflows

Q3.4 Edit a file remotely, commit, push, and submit the result on cluster.

A.

ssh hpc
vim ~/code/solver.cpp
cd ~/code
git add solver.cpp && git commit -m "fix" && git push
sbatch run.sbatch

C++ pointer/reference

Q3.5 Predict:

int a = 10;
int& r = a;
int* p = &a;
r = 20;
*p = 30;
std::cout << a << " " << r << " " << *p;
A. 30 30 30 — all three refer to the same memory.

Gnuplot

Q3.6 Write a script that fits f(x)=a*log(x)+b to data.txt and overlays it on a scatter.

A.

f(x) = a*log(x) + b
fit f(x) 'data.txt' u 1:2 via a,b
plot 'data.txt' u 1:2 t 'data' w p, f(x) t sprintf('fit %.2f log+%.2f',a,b) w l

Shell scripting

Q3.7 Modify backup-data.sh to add a -d flag that deletes files in DEST not present in SRC (use --delete with rsync).

A. Add d to OPTSTRING, set DELETE=1, and pass --delete to rsync when 1.


PRACTICE SET 4 — VERY HARD

Mixed integration

Q4.1 Describe in 250 words a CFD researcher's full daily workflow, naming the relevant chapter for each step.

A. Edit (Ch. 5) ⇒ Git commit (Ch. 10) ⇒ ssh+rsync (Ch. 4) ⇒ module load + cmake build (Ch. 12 + 15) ⇒ sbatch SLURM job (Ch. 15) ⇒ MPI/OpenMP execution (Ch. 14) ⇒ awk/grep/sed result extraction (Ch. 7) ⇒ gnuplot postprocessing (Ch. 9) ⇒ rsync results to laptop (Ch. 4) ⇒ Git tag (Ch. 10) for paper reproducibility.

Real HPC/CFD

Q4.2 Given the following SBATCH header:

#SBATCH --nodes=8 --ntasks-per-node=4 --cpus-per-task=8 --time=06:00:00
How many cores total does the job use? What is the maximum walltime in seconds?
A. 8×4×8 = 256 cores; 6 × 3600 = 21 600 s walltime.

Q4.3 A CFD job runs at 4 PFLOPS on 1024 nodes; serial fraction estimated 1%. Predict speed-up vs perfect scaling at 16 384 nodes.
A. Amdahl with f=0.01: \(S=1/(0.01+(0.99)/16384)\approx 100\); perfect would give 16 384× of single node — Amdahl caps at 100×.

Long Answer

Q4.4 Walk through Chapter 12's three demos (compiling, Makefile, CMake). Explain what each demonstrates and why both Make and CMake exist.

A. - demo01_compiling: shows the four-stage pipeline .cpp→.i→.s→.o→exec plus header-guard prevention of double-inclusion. - demo02_makefile: hand-written Makefile builds three shared libraries and the main executable; shows -fPIC -shared, -L/-l, and the rule syntax. - demo03_cmake: same project via CMakeLists.txt; CMake generates the Makefile, handles output directories and installation. - Why both? Make is direct but platform-specific; CMake adds portability, dependency management, and integrations (find_package, ctest, install). Modern CFD codes (SU2, OpenFOAM-extend, AMReX) use CMake or its successors.

Complex debugging

Q4.5 A simulation hangs after 10 hours on rank 7 only. List 5 possible causes and how you'd diagnose each.

A. (1) MPI deadlock — gstack or mpirun gdb to attach; (2) IO bottleneck on a Lustre OST — lfs check; (3) memory exhaustion — sacct MaxRSS; (4) unbalanced work — profile with score-p / valgrind; (5) network packet loss — dmesg. For each: collect logs, attach gdb, reproduce in interactive salloc.

Marking & Common mistakes

  • Q4.2: forgetting nodes × ntasks-per-node × cpus-per-task = total.
  • Q4.3: forgetting Amdahl plateau at \(1/f\).
  • Q4.4: confusing Make's target/dep/recipe with CMake's imperative-vs-declarative model.

Common Written-Exam Traps

Trap Right answer
chmode chmod
[$a==$b] [ "$a" = "$b" ]
> overwrites instead of appends use >>
Forgot git add before commit always stage first
Forgot -E in grep/sed for ERE add -E
Forgot -O0 -g for gdb optimisations remove vars
Forgot MPI_Finalize always call
Forgot module load inside sbatch script inherits clean env
Forgot quotes around "$VAR" safety with spaces
TAB vs spaces in Makefile TAB only
Login-node compute jobs always submit via sbatch
Permission 644 for SSH private key needs 600

Bangla Quick Notes (most-asked terms)

  • HPC = অনেক কম্পিউটার একসাথে কাজ করিয়ে বড় সমস্যা দ্রুত সমাধান করা।
  • Kernel = অপারেটিং সিস্টেমের মূল অংশ যা হার্ডওয়্যার নিয়ন্ত্রণ করে।
  • POSIX = ইউনিক্স-জাতীয় সিস্টেমের জন্য মান যা পোর্টেবিলিটি নিশ্চিত করে।
  • chmod 755 = মালিকের সব, অন্যদের পড়া + চালানোর অনুমতি।
  • ssh-keygen = পাবলিক/প্রাইভেট কী জোড়া তৈরি করার কমান্ড।
  • rsync = শুধু পরিবর্তিত অংশ কপি করে যা scp এর চেয়ে দ্রুত।
  • Vim macro = কীস্ট্রোক রেকর্ড করে পরে রিপ্লে করার ক্ষমতা।
  • regex = টেক্সট প্যাটার্ন বর্ণনা করার ভাষা।
  • awk = কলাম-ভিত্তিক টেক্সট প্রসেসিং ভাষা।
  • sed = লাইন-বাই-লাইন স্ট্রীম এডিটর।
  • gdb = ডিবাগার, ব্রেকপয়েন্ট সেট করা যায়।
  • valgrind = মেমরি লিক ও ভুল সনাক্তকারী।
  • OpenMP = থ্রেড-ভিত্তিক শেয়ারড মেমরি সমান্তরাল।
  • MPI = বার্তা-ভিত্তিক ডিস্ট্রিবিউটেড মেমরি সমান্তরাল।
  • SLURM = জব শিডিউলার যা ক্লাস্টারে কাজ বরাদ্দ করে।

German Quick Notes (most-asked terms)

  • HPC = Hochleistungsrechnen
  • Kernel = Kern
  • POSIX = POSIX-Standard
  • Berechtigung = Permission
  • Anmeldeknoten = Login node
  • Rechenknoten = Compute node
  • Auftragsskript = Job script
  • Verschlüsselung = Encryption
  • Symmetrisch / Asymmetrisch = Symmetric / Asymmetric
  • Pufferüberlauf = Buffer overflow
  • Speicherleck = Memory leak
  • Wettlaufbedingung = Race condition
  • Verklemmung = Deadlock
  • Übersetzer = Compiler
  • Linker = Linker
  • Statische / Dynamische Bibliothek = Static / Dynamic library
  • Header-Schutz = Header guard
  • Gebietszerlegung = Domain decomposition
  • Geisterzelle = Ghost / halo cell
  • Wandzeit = Walltime
  • Warteschlange = Queue
  • Verteilter Speicher = Distributed memory
  • Gemeinsamer Speicher = Shared memory

End of written-exam preparation file.