This repository contains the assignments and homework code for the High Performance Computing course at the University of Genoa. The projects demonstrate the use of parallel programming models including CUDA, OpenMP, and MPI to accelerate computationally intensive algorithms.
- 1. CUDA Assignment (Heat Equation)
- 2. OpenMP Assignment (Discrete Fourier Transform)
- 3. MPI Assignment (Pi Calculation)
- 4. Final Project (Bellman-Ford)
- Prerequisites
Folder: cuda_assignment/
This assignment implements a parallelized solution to the 2D Heat Equation using Finite Difference Methods. It compares the execution time of a sequential CPU implementation against a parallelized GPU implementation using CUDA.
- Uses CUDA for massive parallelization on the GPU.
- Utilizes Shared Memory to optimize memory access patterns during the 5-point stencil derivative computation.
- Avoids out-of-bounds global memory accesses by properly mapping grid/block threads to global matrix indices.
cd cuda_assignment
make
./cuda_homework 1000 1000 # Dimensions of the 2D arrayFolder: openmp_assignment/
This project implements the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT). It parallelizes the intensive nested loops using OpenMP to significantly decrease execution time.
- Parallelized using
#pragma omp parallel forconstructs. - Properly scopes private vs. shared variables to avoid data race conditions.
cd openmp_assignment
make
./dftwFolder: mpi_assignment/
Calculates the value of
-
Sequential Version: (
pi_sequential.c) Computes the integral sequentially. Useslong long intto gracefully handle an extremely high number of intervals ($100 \times 10^9$ ) without integer overflow. -
MPI Version: (
pi_mpi.c) Divides the integral range across multiple processes using Message Passing Interface (MPI). It utilizesMPI_Reduceto efficiently aggregate the partial sums computed by each node into the final$\pi$ value.
cd mpi_assignment
# Compile both versions
make
# Run sequential version
./pi_sequential
# Run MPI version
mpirun -np 4 ./pi_mpi # Run with 4 processesFolder: final_project/
This is the final project for the HPC course. It implements the Bellman-Ford algorithm for finding the shortest paths from a single source vertex to all other vertices in a weighted digraph. The implementation handles negative edge weights and detects negative cycles. It includes implementations using Serial execution, OpenMP, MPI, and CUDA to analyze and compare performance across different parallelization paradigms.
- Serial Version: A standard sequential implementation.
- OpenMP Version: Uses OpenMP to parallelize the relaxation loops across multiple CPU cores.
- MPI Version: Distributed memory implementation using MPI.
- CUDA Version: Massively parallel GPU implementation to map vertices and edges to threads.
cd final_project
# Compile all versions
make
# Run the executable, for example OpenMP with an input file:
./openmp_bellman_ford input1.txtTo compile and run all the assignments in this repository, you will need:
- GCC with OpenMP support (
-fopenmpflag) - CUDA Toolkit (for
nvccand GPU execution) - MPI Implementation (e.g., OpenMPI or MPICH for
mpiccandmpirun) - Make (for building the projects)
You can build all the assignments at once using the provided Makefile at the root directory:
makeTo clean all compiled executables:
make cleanUniversity of Genoa - High Performance Computing