# Project 01

This archive contains only the student presentation and finished small examples. It does not include a turnkey official gamma program, full-size answer data or private instructor notes.

## 1. Start in the correct folder

The extracted archive root is `NMP_Project01_Worked_Examples/`. the commands below run from **that extracted root**, where `examples/` and `Makefile` are visible.

```bash
pwd
ls examples
mkdir -p bin data plots
g++ --version
```

Run Bash commands in Ubuntu/Linux.

## 2. Direct compiler commands

Each source is independently compilable. Do not link `examples/*.cpp` into one executable: each file has its own main. The first seven rows below need only the C++17 standard library. Commands assume the `bin` directory above exists.

```bash
g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/01_dot_product.cpp -o bin/01_dot_product
./bin/01_dot_product

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/02_vector_norm.cpp -o bin/02_vector_norm
./bin/02_vector_norm

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/03_matrix_storage.cpp -o bin/03_matrix_storage
./bin/03_matrix_storage

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/04_matrix_vector.cpp -o bin/04_matrix_vector
./bin/04_matrix_vector

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/05_matrix_products.cpp -o bin/05_matrix_products
./bin/05_matrix_products

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/06_toy_iterations_csv.cpp -o bin/06_toy_iterations_csv
./bin/06_toy_iterations_csv data/toy_run01.csv

g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/08_timing_small_example.cpp -o bin/08_timing_small_example
./bin/08_timing_small_example
```

Stop at the first error. Immediately after a command, `echo $?` shows its exit status: zero means that program’s checks completed, not that your official project is finished. E06 deliberately refuses to overwrite an existing CSV. For another run choose `data/toy_run02.csv`. Create the parent directory first. E08’s exact durations depend on the machine; its numerical checks must pass.

### CBLAS example E07

Only this example needs the installed CBLAS header and a working library. Its actual tiny calculation is also the availability probe. The primary link command follows the handout; missing headers/linkage remain an explicit blocker, not a reason to fake a library result.

```bash
g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/07_cblas_small_product.cpp -o bin/07_cblas_small_product -lblas -lm
./bin/07_cblas_small_product
```

The output is `CBLAS AB:` followed by rows `19 22` and `43 50`, then `All four entries checked`. The test uses real `cblas_dgemm`, not the manual routine. Alternative implementation flags must be verified locally; no OpenBLAS installation or Taurus software fix is assumed. On managed systems report missing software to the instructor/administrator.

### Optional precision example E09

```bash
g++ -std=c++17 -Wall -Wextra -Wpedantic -O2 examples/09_precision_example.cpp -o bin/09_precision_example
./bin/09_precision_example
```

It reports actual stored values and type properties. Optional precision exploration is not another official graded task.

## 3. Known small observations

| Example | Hand-checkable observation |
|---|---|
| E01 | Dot product 32. |
| E02 | Squared norm 25; norm 5. |
| E03 | Packed row `[1,2,3,4,5,6]`; packed column `[1,4,2,5,3,6]`; padding checks pass. |
| E04 | First vector `(5,11)`, second `(27,59)`; norms `sqrt(146)`, `sqrt(4210)`. |
| E05 | AB `[19,22;43,50]`; AA `[7,10;15,22]`; elementwise square `[1,4;9,16]`. |
| E06 | Three post-update vectors `(3,3)`, `(9,9)`, `(27,27)` and norms `3^k*sqrt(2)`. |
| E07 | The same AB as E05, computed by CBLAS. |
| E08 | Five real durations after a warm-up; all entries checked against the separate row-sum formula. |
| E09 | Actual finite type values; exact strings can depend on platform. |

These are tiny demonstration fixtures, not the official 2000-square numerical results.

## 4. Run the toy-to-plot sequence

Python 3 with Matplotlib is needed for this helper; NumPy is not needed for its CSV reader. Complete the C++ run before plotting. When E06 above already generated `data/toy_run01.csv`, start with `head` rather than rerunning it into an existing file.

```bash
head -n 4 data/toy_run01.csv
python3 plotting/plot_toy_norms.py data/toy_run01.csv --output plots/toy_run01
```

The helper creates `plots/toy_run01/toy_run01.png` and `.pdf` from the actual CSV. Default operation is headless and needs no display. `--show` requests an optional GUI window; that GUI mode was not tested here. Existing plots are protected unless `--overwrite` is deliberately passed.

Fresh second run:

```bash
./bin/06_toy_iterations_csv data/toy_run02.csv
python3 plotting/plot_toy_norms.py data/toy_run02.csv --output plots/toy_run02
```

The exact header is `iteration,norm2`, followed by steps 1,2,3. `norm2` denotes Euclidean norm, not squared norm. A missing or malformed input produces a concise error and nonzero exit. This helper intentionally accepts three toy rows; students adapt or write a separate reader for their own thirty-step project. It does not generate missing numerical data. The shipped `recorded_toy_data/toy_reference.csv` documents the production run and is not a default fresh-run destination.

## 5. Optional Makefile

```bash
make core
make check
make blas
make check-blas
make optional
make help
```

`make core` builds the standard-library examples without any BLAS dependency. `make check` runs them; its CSV test writes only into a temporary directory. `make blas` compiles/links/runs the actual E07 check. `make optional` builds and runs E09. `make clean` removes only the named example binaries, not data, plots or source. There are no install/download actions. `CXX`, `CXXFLAGS` and `BLAS_LIBS` are configurable for an actually available toolchain; changing flags may require `make clean` before rebuilding.

Additional public small-fixture checks can be run after building:

```bash
python3 tests/check_examples.py
python3 tests/check_examples.py --with-blas
```

The second command needs a successfully built E07. These checks operate only on tiny fixtures and temporary output, not the assessed project.


## Test scope

The demonstration programs and headless plot chain were tested in a local Debian/Linux container.
