Skip to content

Gabriel-Pedde/Advanced-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced C++ Programming

A collection of C++ exercises and examples from the Master in High Performance Computing (MHPC) curriculum at SISSA/ICTP, Trieste. Covers modern C++17 from fundamentals through templates and metaprogramming, then extends to parallel scientific computing with MPI and the C++ standard library.


Structure

.
├── examples/        # Standalone feature examples (strings, lambdas, OOP, memory)
├── lec1–lec7/       # Daily exercises (progressive difficulty)
├── advection_ex/    # Standalone 1D advection PDE solver
├── l8_mpi/          # Distributed memory parallelism (MPI)
├── l9_std/          # Shared memory parallelism (C++17 std::execution)
├── l10_test/        # Unit testing with Google Test
└── fun/             # Conway's Game of Life with SFML

Weekly Exercises

References, functions, file I/O, first classes, operator overloading, templates intro. Key exercise: matrixMultiplication/ — matrix multiply from scratch with CMake.

Manual allocation (new/delete), destructors, copy and move constructors, smart pointers. Key exercise: matrixMemory/ — matrix class in two versions: raw pointers vs. unique_ptr.

std::vector, std::map, std::string, STL algorithms, lambda functions, scoped timer. Key exercises:

  • addMat/ — matrix class with operator+, operator*, and operator<<
  • simpleTime/ — custom scoped timer measuring matrix operations
  • sortTime/ & vecTiming/ — STL sort performance benchmarking

A 2D heat equation solver using J acobi iteration. Demonstrates mesh data structures, boundary conditions, and file-driven parameters. Output can be animated with gnuplot.

cd lec4/jacobi && mkdir build && cd build
cmake .. && make
./jacobi ../parameters.txt
gnuplot ../gif.gp   # generates jacobi.gif

Custom linked list with a full iterator interface (range-based for, push_back, push_front, find, erase). Template classes with proper copy semantics.

  • fibonacci/ — compile-time Fibonacci via template recursion and if constexpr (C++17)
  • varSmall/ — variadic templates
  • tuple/std::tuple and structured bindings
  • shapes/ — polymorphic shape hierarchy: abstract base class, Triangle and variadic-template Polygon, virtual perimeter() and print_coordinates()
  • errorHandling/ — custom exception class integrated into the bisection root finder
  • pointerMatrix/ — pointer-based dynamic 2D array

Standalone Projects

Solves the 1D scalar advection equation over 100,000 time steps using a template mesh class and lambda-based boundary conditions. Outputs field snapshots for gnuplot animation.

cd advection_ex && mkdir build && cd build
cmake .. && make
./advection
gnuplot ../gif.gp   # generates advection.gif

Interactive Game of Life rendered with SFML. The grid is a class inheriting from sf::Drawable, with live/dead cell tracking, next_generation() stepping, and save/load functionality. Includes several saved patterns (gun.txt, ships.txt, etc.).

# Ubuntu/Debian: sudo apt install libsfml-dev
g++ -o life.x life.cpp -lsfml-window -lsfml-graphics -lsfml-system
./life.x              # draw cells, press Space to start, S to save, Q to quit
./life.x gun.txt      # load a saved pattern

Parallel Computing

Directory Demonstrates
hello/ MPI initialization, rank, size
comms/ Point-to-point MPI_Send / MPI_Recv
ring/, ring2/ Ring communication pattern
mpi_functions/ Collective operations: allgather, allreduce, scatter, gather (and v variants)
mpi_matrix/ Distributed matrix operations
mpi_scheduler/ Dynamic work distribution across processes
advection_parallel/ Domain decomposition applied to the advection solver

See mpi/mpi_intro.md for an overview of MPI concepts.

Directory Demonstrates
par_jacobi/ Jacobi solver parallelized with std::execution::par
module_jacobi/ Modular refactoring of the Jacobi solver
span/ std::span for non-owning array views (C++20)
Directory Demonstrates
jacobi_test/ Unit tests for the Jacobi solver
3d_jacobi/ 3D extension of the solver
pi/ Monte Carlo π calculation with validation tests

Examples Reference

The examples/ directory contains self-contained files demonstrating individual language features:

File / Directory Feature
cppstring.cpp std::string — construction, capacity, iteration
operators1–3.cpp Operator overloading, friend operators
lambdas.cpp Captures (by value/reference), mutable, STL integration
iterator.cpp Custom iterator for a template class
custom_alloc.cpp Custom memory allocation patterns
errors/try1–6.cpp Exception hierarchy, custom ap_error class
inheritance/ Single/multiple inheritance, virtual functions, virtual destructor
memory/new1–5.cpp new/delete, copy/move semantics, unique_ptr

Building

All exercises use CMake:

mkdir build && cd build
cmake ..
make

MPI examples require an MPI implementation (OpenMPI or MPICH):

cd l8_mpi/hello && mkdir build && cd build
cmake .. && make
mpirun -np 4 ./mpi_hello.x

Game of Life requires the SFML library (no CMake — compile directly):

# Ubuntu/Debian: sudo apt install libsfml-dev
cd fun/sfml
g++ -o life.x life.cpp -lsfml-window -lsfml-graphics -lsfml-system
./life.x              # optionally pass a saved pattern file as argument

Part Of

Master in High Performance Computing (MHPC)
SISSA / ICTP / University of Trieste — 2025/26 Course: P1.4 — Advanced Programming (C++)

About

C++ exercises from the MHPC curriculum at SISSA/ICTP, Trieste. Covers modern C++17: templates, STL, OOP, and metaprogramming. Extends to parallel scientific computing with MPI and std::execution.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors