Parallel CPU Benchmark
Celia answers a simple question. How much faster does a program get when you give it more CPU cores? To find out, it multiplies big grids of numbers (called matrices) using 1 thread, then 2, then 4, and so on. It times each run and draws a chart of the results.
The chart shows something interesting. For small grids, extra threads barely help, and sometimes they even slow things down. For big grids, they help a lot.
- Written in C++ with OpenMP, which splits a loop across CPU cores
- Saves results to a CSV file
- Draws the chart with Python and Matplotlib
- Celia multiplies square matrices with a plain triple loop on purpose
- The outer loop gets split across threads with OpenMP
- It tries every matrix size with every thread count you ask for
- Each setup runs several times, and the fastest run is kept
- Before timing anything, it checks that the parallel answer matches the serial one
- If they disagree, it prints a warning
- Speed is reported in seconds and in GFLOPS (billions of math operations per second)
The simple loop keeps the code easy to read. It also means the GFLOPS numbers are for comparing thread counts, not for showing off peak speed.
flowchart LR
CLI["Benchmark CLI<br/>matrix sizes · threads · repeats"]
CORE["Matrix Kernel<br/>C++17"]
SERIAL["Serial Multiply"]
PARALLEL["OpenMP Multiply"]
TIMER["Benchmark Runner<br/>Timing · GFLOPS"]
CSV["CSV Results"]
PLOT["Matplotlib<br/>Performance Plot"]
CLI --> CORE
CORE --> SERIAL
CORE --> PARALLEL
SERIAL -->|correctness baseline| TIMER
PARALLEL -->|timed workload| TIMER
TIMER --> CSV
CSV --> PLOT
- C++17 for the matrix math and benchmark logic
- OpenMP for multi-threading
- CMake for building
- Python and Matplotlib for the charts
- C++17 runs close to the hardware, so timings reflect the CPU
- OpenMP adds threads with one line above a loop
- CMake builds on Windows, Mac, and Linux
- CSV opens in almost anything
- Python and Matplotlib draw the charts quickly
flowchart LR
CLI["Benchmark CLI: C++17"] --> Math["Matrix multiply with OpenMP threads"]
Math --> CSV["CSV file"]
CSV --> Chart["Python + Matplotlib chart"]
You'll need a C++17 compiler with OpenMP support, and CMake 3.10 or newer.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config ReleaseThat makes a celia program in build/ (it's celia.exe on Windows).
Here's an example run.
./build/celia --sizes 256,512,768,1024 --threads 1,2,4,8 --repeats 3 --output results.csvYou can change these options.
--sizessets the matrix sizes, as a comma-separated list (default64,128,256,512)--threadssets the thread counts to compare (default1,2,4,8)--repeatssets how many timed runs each setup gets (default3)--outputsets where the CSV goes (defaultresults.csv)
The CSV has one row per setup, like this example.
matrix_size,threads,seconds,gflops
256,1,0.006,5.59
256,2,0.003,11.18
256,4,0.001,33.55
512,1,0.048,5.59
512,2,0.027,9.94
512,4,0.014,19.17
First, install the plotting tools.
pip install -r scripts/requirements.txtThen make the chart.
python scripts/plot_results.py results.csv -o results.png- The chart plots time against matrix size
- Each thread count gets its own line
- That makes it easy to spot where extra threads start to pay off
- Add
--log-yto put time on a log scale - That helps when the big sizes dwarf the small ones
celia/
├── CMakeLists.txt
├── src/
│ ├── matrix.hpp
│ ├── matrix.cpp
│ └── main.cpp
└── scripts/
├── plot_results.py
└── requirements.txt
matrix.hppandmatrix.cpphold the matrix type and the serial and OpenMP multiplicationmain.cppis the command line, the timing, the correctness check, and the CSV outputplot_results.pyturns the CSV into a chart