Skip to content

About

Parallel heat diffusion simulation on PCBs using MPI. Achieves 55x speedup with 85% efficiency on 48 processes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

MPI Heat Diffusion Simulation

A parallel implementation of 2D heat diffusion simulation on printed circuit boards (PCBs) using MPI (Message Passing Interface). The project parallelizes the thermal analysis of multiple chip configurations to find optimal placement that minimizes average board temperature.

Project Overview

This project was developed for the Parallel Computing Systems course at EHU. The goal is to simulate heat diffusion across a PCB with multiple heat-generating chips, testing different chip configurations to identify the one that produces the lowest average temperature.

The simulation discretizes the heat equation using finite differences:

T(t+1)[i,j] = T(t)[i,j] + 0.1 * (sum of 8 neighbors - 8 * T(t)[i,j])

The board is divided into a 2D grid where each point's temperature is iteratively updated based on neighboring temperatures, heat injection from chips, and air cooling in ventilated zones.

Features

  • Serial baseline implementation for correctness verification
  • Parallel implementation with blocking MPI communications (MPI_Ssend/MPI_Recv)
  • Optimized parallel implementation with non-blocking communications (MPI_Isend/MPI_Irecv)
  • Horizontal domain decomposition with ghost row exchange
  • Support for non-uniform row distribution when grid size is not divisible by process count
  • Convergence detection via global temperature reduction (MPI_Allreduce)

Performance Results

Tested on an HPC cluster with Intel Xeon Gold 6130 CPUs (16 cores @ 2.10GHz), simulating 20 chip configurations on a 2000x1000 grid:

Processes Time (s) Speedup Efficiency
1 3608.49 - -
2 1696.82 2.13 94%
4 776.33 4.65 86%
8 395.41 9.13 88%
16 191.57 18.84 85%
32 96.04 37.57 85%
48 64.92 55.59 86%

The implementation achieves near-linear speedup with consistent efficiency around 85-86% across different process counts, demonstrating effective load balancing and minimal communication overhead.

Project Structure

mpi-heat-diffusion/
├── src/
│   ├── serial/                    # Baseline serial implementation
│   │   ├── heat_s.c               # Main program
│   │   ├── diffusion_s.c          # Thermal diffusion algorithms
│   │   ├── faux_s.c               # I/O and auxiliary functions
│   │   └── defines.h              # Data structures and constants
│   ├── parallel/                  # MPI with blocking communications
│   │   ├── heat_p.c               # Parallel main program
│   │   ├── diffusion_p.c          # Parallel diffusion with MPI
│   │   ├── faux_p.c               # Parallel I/O utilities
│   │   └── defines.h
│   └── parallel_optimized/        # MPI with non-blocking communications
│       ├── heat_p.c
│       ├── diffusion_p.c
│       ├── faux_p.c
│       └── defines.h
├── docs/
│   └── mpi_heat_diffusion_report.pdf
└── data/
    ├── card0                      # Test configuration (200x100 grid)
    └── card                       # Full configuration (2000x1000 grid)

Implementation Details

Domain Decomposition

The 2D grid is partitioned horizontally among MPI processes. Each process handles a contiguous set of rows plus two ghost rows (one above, one below) for boundary exchange:

int rows_per_process = (NROW - 2) / num_processes;
int remaining_rows = (NROW - 2) % num_processes;

// Processes with pid < remaining_rows get one extra row
if (pid < remaining_rows) {
    start_row = pid * (rows_per_process + 1) + 1;
    end_row = start_row + rows_per_process;
} else {
    start_row = pid * rows_per_process + remaining_rows + 1;
    end_row = start_row + rows_per_process - 1;
}

Ghost Row Exchange

Blocking version:

if (pid > 0) {
    MPI_Recv(grid, NCOL, MPI_FLOAT, pid - 1, 0, MPI_COMM_WORLD, &status);
    MPI_Ssend(&grid[NCOL], NCOL, MPI_FLOAT, pid - 1, 0, MPI_COMM_WORLD);
}
if (pid < num_processes - 1) {
    MPI_Ssend(&grid[rows * NCOL], NCOL, MPI_FLOAT, pid + 1, 0, MPI_COMM_WORLD);
    MPI_Recv(&grid[(rows + 1) * NCOL], NCOL, MPI_FLOAT, pid + 1, 0, MPI_COMM_WORLD, &status);
}

Non-blocking version:

if (pid > 0) {
    MPI_Irecv(grid, NCOL, MPI_FLOAT, pid - 1, 0, MPI_COMM_WORLD, &request[n++]);
    MPI_Isend(&grid[NCOL], NCOL, MPI_FLOAT, pid - 1, 0, MPI_COMM_WORLD, &request[n++]);
}
if (pid < num_processes - 1) {
    MPI_Isend(&grid[rows * NCOL], NCOL, MPI_FLOAT, pid + 1, 0, MPI_COMM_WORLD, &request[n++]);
    MPI_Irecv(&grid[(rows + 1) * NCOL], NCOL, MPI_FLOAT, pid + 1, 0, MPI_COMM_WORLD, &request[n++]);
}
MPI_Waitall(n, request, status);

Result Gathering

Since processes may have different numbers of rows, MPI_Gatherv is used to reconstruct the complete grid:

int *sendcounts = malloc(num_processes * sizeof(int));
int *displs = malloc(num_processes * sizeof(int));
int sum = 0;

for (int i = 0; i < num_processes; i++) {
    sendcounts[i] = (i < remaining_rows) ? 
                    (rows_per_process + 1) * NCOL : 
                    rows_per_process * NCOL;
    displs[i] = sum;
    sum += sendcounts[i];
}

MPI_Gatherv(&grid[NCOL], sendcounts[pid], MPI_FLOAT,
            &total_grid[NCOL], sendcounts, displs, MPI_FLOAT, 0, MPI_COMM_WORLD);

Building and Running

Prerequisites

  • MPI implementation (OpenMPI, MPICH, or Intel MPI)
  • GCC or Intel C Compiler

Compilation

# Serial version
gcc -O3 -o heat_s src/serial/heat_s.c src/serial/diffusion_s.c src/serial/faux_s.c -lm

# Parallel version
mpicc -O3 -o heat_p src/parallel_optimized/heat_p.c src/parallel_optimized/diffusion_p.c src/parallel_optimized/faux_p.c -lm

Execution

# Serial
./heat_s data/card0

# Parallel (e.g., 8 processes)
mpirun -np 8 ./heat_p data/card0

# On a cluster with SLURM
srun -n 48 ./heat_p data/card

Output

The program outputs:

  • Temperature results for each configuration
  • Best configuration with minimum average temperature
  • Execution time

Result files are generated for visualization:

  • card_par.res - Final temperature distribution
  • card_par.chips - Initial chip positions

Algorithm

  1. Initialization: Read chip configurations, distribute grid rows among processes
  2. For each configuration:
    • Initialize chip temperatures in local subgrid
    • Iterative loop until convergence:
      • Heat injection at chip positions
      • Air cooling in ventilated zone (central 10% of board width)
      • Exchange ghost rows with neighbors
      • Compute thermal diffusion (8-neighbor stencil)
      • Every 10 iterations: check convergence via MPI_Allreduce
    • Gather results at root process
  3. Output: Report best configuration and write result files

Technical Specifications

  • Grid size: Configurable via scale factor (1-12), base size 200x100
  • Convergence criteria: Temperature change < threshold OR max iterations reached
  • Stencil: 9-point (8 neighbors + center)
  • Boundary conditions: Fixed temperature at edges (ambient temperature)

License

This project was developed for academic purposes at the University of the Basque Country (EHU).

About

Parallel heat diffusion simulation on PCBs using MPI. Achieves 55x speedup with 85% efficiency on 48 processes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages