Skip to main content

Chapter 1: Computer and Operating System Basics

Know your tools, and you'll use them better.

Chapter Goals​

After completing this chapter, you should be able to:

  • Describe the basic components of a computer: processor, memory, storage, I/O
  • Explain the difference between CPU and GPU, and their roles in research computing
  • Distinguish between RAM and disk storage
  • Understand the role of an operating system
  • Use file paths correctly and understand file extensions
  • Distinguish between processes, threads, and programs
  • Understand what "programming" actually means

Motivation​

You might think: "I'm not a CS student — why do I need to know about hardware?" The reason is simple:

  • Your simulation runs slowly — is the CPU not fast enough, or is there not enough memory?
  • Your advisor says "request a GPU node" — you need to know what kinds of computation GPUs accelerate
  • Your program throws MemoryError — you need to know what "memory" refers to here
  • Your data files are 50 GB — you need to decide where to store them

You don't need deep hardware knowledge, but building the right mental model will help you know where to look when things go wrong.

1.1 Basic Computer Architecture​

A computer can be simplified into four parts:

⌨️
Input Devices
keyboard, mouse
→
⚙️
CPU
+ Memory (RAM)
🎮
GPU
+ VRAM
→
🖥️
Output Devices
monitor, files
↕
💾
Storage
disk / SSD
ComponentAnalogyRole
CPUBrainExecutes computational instructions
Memory (RAM)DeskHolds data currently in use; fast but lost on power-off
Disk (HDD/SSD)BookshelfLong-term data storage; slower but persistent
Input devicesEyes and earsReceives external information
Output devicesMouth and handsPresents results to the user
In a research context

When you run a Python script:

  1. The script file is stored on disk
  2. The Python interpreter loads the script into memory
  3. The CPU executes instructions line by line
  4. Results are printed to the screen or written back to disk

1.2 CPU vs. GPU: What Each Does Best​

CPU (Central Processing Unit)​

  • Fewer cores (typically 4–16), but each is powerful
  • Excels at sequential execution of complex logic
  • Best for: general-purpose computing, logic-heavy programs, most research code

GPU (Graphics Processing Unit)​

  • Many more cores (thousands), but each is simpler
  • Excels at massively parallel computation — performing the same operation on large amounts of data simultaneously
  • Best for: matrix operations, deep learning, molecular dynamics simulations, Monte Carlo simulations
CPU: a few highly capable workers, good at complex, precise tasks
GPU: thousands of ordinary workers, good at massive amounts of simple, repetitive work

What This Means for Physics Students​

Task TypeBetter ProcessorExample
Symbolic computationCPUMathematica derivations, SymPy
Small-scale numerical computationCPUSolving ODEs, fitting data
Large-scale matrix operationsGPUDeep learning, large-scale linear algebra
Monte Carlo simulationsCPU or GPUDepends on implementation
Don't worry about GPUs yet

Most entry-level research computing is fine with a CPU. When you actually need GPU acceleration, you can dive deeper then.

1.3 Memory vs. Disk: Capacity, Speed, and Purpose​

This is one of the most commonly confused concepts for beginners.

PropertyMemory (RAM)Disk (HDD/SSD)
SpeedVery fast (~ns)Slower (~ms; SSD much faster than HDD)
CapacitySmaller (8–64 GB typical)Larger (256 GB – several TB)
After power-offData lostData preserved
PurposeHolds running programs and active dataStores files and installed software
CostExpensiveCheap

Real-World Impact in Research​

What happens when memory runs out?

Before running large arrays, estimate the memory first: float64 takes 8 bytes per element, so 10⁵ × 10⁴ = 10⁹ elements × 8 bytes = 8 GB.

# This array requires ~8 GB of memory
import numpy as np
a = np.zeros((10**5, 10**4)) # 10^9 float64 elements

If your computer only has 8 GB of RAM, running this will likely cause the program to be killed by the OS (Killed) or raise MemoryError.

What happens when disk space runs out?

  • Can't save new files
  • Programs can't write output
  • The system slows down or crashes
Build a habit: estimate resource requirements before running large computations
  • How large is the data? Is there enough memory?
  • How large will the output files be? Is there enough disk space?
  • How long will it run? Is the CPU sufficient?

1.4 What Is an Operating System?​

An Operating System (OS) is system software that manages a computer's hardware and software resources. It is the "translator" between you and the hardware.

🧑‍💻
You (User)
↓
📦
Applications
Python · VS Code · Browser
↓
🖥️
Operating System
macOS / Linux / Windows
↓
⚙️
Hardware
CPU · RAM · Disk · GPU

The Three Major Operating Systems​

OSKernelCharacteristicsResearch Use
macOSDarwin (Unix-like)Great GUI, terminal ready out of the boxPersonal development, daily research
Linux (Ubuntu)LinuxOpen source, server standardServers, supercomputers, heavy computation
WindowsNTMost users, rich ecosystemDaily use; research via WSL

Why Do Researchers Mostly Use Linux?​

  • Nearly all supercomputers and computing clusters run Linux
  • Most scientific software targets Linux first
  • The command-line toolchain is most complete
  • Better performance scheduling and resource utilization
  • Free and open source — no licensing costs for university servers

This doesn't mean you have to install Linux on your personal computer. macOS is naturally Unix-like, and Windows with WSL can provide a Linux environment.

1.5 Files, Directories, Paths, and Extensions​

Files and Directories​

  • File: The basic unit of stored data — e.g., simulation.py, data.csv
  • Directory: Also called a "folder"; used to organize files

Paths​

A path is the "address" of a file in the file system.

# Unix/macOS/Linux style (forward slashes /)
/home/student/research/simulation.py

# Windows style (backslashes \)
C:\Users\student\research\simulation.py

Absolute path vs. relative path:

# Absolute path: full path from the root directory
/home/student/research/simulation.py

# Relative path: path relative to the current directory
# Assuming current directory is /home/student/
research/simulation.py # relative path
./research/simulation.py # same as above; ./ means current directory
../other_project/data.csv # .. means parent directory

Extensions​

The part of a filename after the last . is the extension. It hints at the file type:

ExtensionTypeCommon Use
.pyPython scriptData analysis, simulations
.f90Fortran sourceNumerical computation
.c / .cppC/C++ sourceHigh-performance computing
.texLaTeX filePaper writing
.csvComma-separated dataExperimental data
.dat / .txtText dataSimulation output
.pdfPDF documentPapers, reports
.shShell scriptAutomation tasks
Extensions don't determine file content

Renaming .txt to .py doesn't make a text file into a Python program. An extension is just a "label" — the actual content determines what the file is.

1.6 Processes, Threads, and Programs​

ConceptA Better AnalogyMeaning
ProgramA recipeCode stored on disk — a static set of instructions
ProcessAn active cooking session (the kitchen in action)A running instance of a program, with its own memory and resources
ThreadA specific worker in the kitchen (one line of work)An execution flow inside a process; multiple threads can run concurrently
📄
Program
Recipe on disk
→
🍳 Process (the kitchen)
🧑‍🍳 Thread 1
🧑‍🍳 Thread 2
🧑‍🍳 Thread 3
# View currently running processes
# macOS / Linux:
ps aux

# Windows PowerShell:
Get-Process

Why Does This Matter?​

  • Your program runs slowly — it might be using only a single thread, while your CPU has 8 cores
  • You want to run multiple simulations simultaneously — you need to understand processes
  • A program "freezes" — you need to know how to find and kill the corresponding process
# Kill a process (Linux/macOS)
kill <PID>

# Force kill
kill -9 <PID>

1.7 What Is Programming?​

Programming = describing the steps to solve a problem in a language the computer understands.

A simple example — calculating the energy of a harmonic oscillator:

# Quantum harmonic oscillator energy levels
# E_n = hbar * omega * (n + 1/2)

hbar = 1.0545718e-34 # reduced Planck constant (J·s)
omega = 2 * 3.14159 * 1e12 # angular frequency (rad/s)

for n in range(5):
E = hbar * omega * (n + 0.5)
print(f"n = {n}, E = {E:.4e} J")

You don't need to become a "programmer" — you don't need to build polished applications or design complex multi-interface systems. For physics students, programming is a tool — like mathematics. You need to master it to the extent that it lets you solve your physics problems.

Programming Languages Common in Research​

LanguageCharacteristicsUse in Physics
PythonEasy to learn, rich librariesData analysis, visualization, rapid prototyping
C/C++High performanceLarge-scale simulations, low-level libraries
FortranTraditional strength in numerical computingLegacy physics codes, supercomputer programs
JuliaModern high-performanceEmerging research language; easy and fast
MathematicaSymbolic computationAnalytic derivations, special functions

1.8 What Do "Code," "Script," "Software," and "Environment" Mean?​

These words are often used interchangeably in conversation, but they have distinct meanings:

TermMeaningExample
CodeText written in a programming languageenergy = 0.5 * k * x**2
ScriptA code file that can be run directlyplot_spectrum.py
Software / ProgramA complete executable applicationVASP, Gaussian, LAMMPS
Library / PackageA collection of code written by others for you to useNumPy, SciPy, TensorFlow
EnvironmentThe combination of all dependencies needed to run codePython 3.11 + NumPy 1.24 + ...
ToolchainA set of tools needed to accomplish a class of tasksCompiler + linker + debugger
"Environment" is where research computing most often breaks

"It works on my machine" is the most common (and most frustrating) phrase in research computing. Learning to manage environments is one of the core goals of this guide.

FAQ​

Q: Do I need to buy an expensive computer?

A: Not for getting started. Most learning and small-scale computation works fine on a regular laptop. Large-scale computation should be done on your institution's server or a supercomputer. At minimum, aim for 8 GB RAM and a 256 GB SSD.

Q: Is an Apple Silicon Mac suitable for research computing?

A: Very much so. Apple Silicon chips are powerful and energy-efficient. Nearly all research software has been adapted for ARM. The one caveat: some older Fortran code may require extra configuration.

Q: How much hardware knowledge do I need?

A: What's in this chapter is enough. You need the right mental model — not deep hardware engineering knowledge.

Summary​

  • A computer consists of CPU, memory, disk, and I/O devices
  • CPUs excel at complex sequential tasks; GPUs excel at massively parallel tasks
  • Memory is fast and temporary; disk is slow and permanent
  • The OS is the bridge between you and the hardware; research servers almost always run Linux
  • Understanding file paths (absolute/relative) is a prerequisite for using the command line
  • A program is static code; a process is a running program
  • For physics students, programming is a tool, not an end in itself

Exercises​

Exercise 1.1: Check Your Computer's Specs​

Find the following information in the terminal (or system settings):

# macOS
sysctl -n machdep.cpu.brand_string # CPU model
sysctl -n hw.memsize # Memory size (bytes)
df -h # Disk space
sw_vers # OS version

# Ubuntu
lscpu # CPU info
free -h # Memory info
df -h # Disk space
lsb_release -a # OS version

# Windows PowerShell
Get-WmiObject -Class Win32_Processor # CPU info
Get-WmiObject -Class Win32_PhysicalMemory | Select Capacity # Memory
Get-PSDrive C # C drive space
winver # OS version

Exercise 1.2: Estimate Memory Requirements​

A physics simulation needs to store a 1000 × 1000 × 1000 three-dimensional array, where each element is a 64-bit float (8 bytes). Calculate:

  1. How much memory does this array require? (in GB)
  2. Does your computer have enough?
  3. If not, what are your options?
Answer
  1. 1000 × 1000 × 1000 × 8 bytes = 8 × 10⁹ bytes = 8 GB (strictly speaking, 8,000,000,000 bytes ≈ 7.45 GiB)
  2. It depends on your computer. If you have 8 GB of RAM, this single array would nearly exhaust all available memory (the OS itself needs 2–3 GB), so it's effectively not enough. 16 GB or more would be comfortable.
  3. Possible solutions include:
    • Use a more memory-efficient data type (e.g., 32-bit float float32, cutting memory in half to ~3.7 GiB)
    • Process the data in chunks instead of loading the entire array at once
    • Use sparse matrices (if the data contains many zeros)
    • Run the simulation on a server or HPC cluster with more memory
    • Use memory-mapped files, letting the OS load data on demand

Exercise 1.3: Identify File Types​

What might each of the following files contain? What program would typically open them?

  1. hartree_fock.f90
  2. plot_dos.py
  3. POSCAR
  4. results.csv
  5. manuscript.tex
  6. run_job.sh
Answer
FilenameExtensionContentHow to open
hartree_fock.f90.f90Fortran 90 source code (implementation of the Hartree-Fock method)Text editor (VS Code, vim); compile with gfortran
plot_dos.py.pyPython script (likely plots a density of states, DOS)Text editor; run with python3 plot_dos.py
POSCARno extensionVASP (first-principles calculation software) crystal structure input fileText editor; visualize with VESTA
results.csv.csvComma-separated data fileExcel, text editor, Python (pandas.read_csv)
manuscript.tex.texLaTeX paper source fileText editor; compile with xelatex or pdflatex to PDF
run_job.sh.shShell script (likely a job submission script)Text editor; run with bash run_job.sh

Exercise 1.4: CPU Cores and Parallelism​

How many cores does your CPU have? If you want to run 4 independent Monte Carlo simulations simultaneously, each single-threaded, can your CPU handle all of them at once? Why or why not?

Answer

Check your CPU core count:

# macOS
sysctl -n hw.ncpu

# Linux
nproc

# Windows PowerShell
(Get-WmiObject -Class Win32_Processor).NumberOfLogicalProcessors
  • If your CPU has 4 or more cores (modern laptops typically have 4–16 cores), then yes — you can run 4 single-threaded simulations simultaneously, each on its own core, without interference.
  • If your CPU has only 2 cores, the OS can still "simultaneously" run 4 simulations (via time-slice scheduling), but each simulation will only get about 50% of CPU time, roughly doubling the total wall time compared to the 4-core case.
  • Hyper-Threading: For example, a 4-core/8-thread CPU has 4 physical cores and 8 logical cores. Four single-threaded tasks can run fully in parallel on the 4 physical cores, achieving near-ideal performance.