Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

121 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPD-Project

Particle Simulation Project

Overview

This project is a simulation of particles moving in a 2D space under the influence of gravitational forces. The simulation is implemented in three versions:

  • Serial implementation (C/C++)
  • Parallel implementation using OpenMP
  • Parallel implementation using MPI (not yet implemented in the assignment but could be extended)

The goal is to gain hands-on experience with parallel programming on shared-memory systems (OpenMP) and compare performance against the sequential version.

Problem Description

The simulation follows an N-body problem approach but optimizes calculations using the particle-in-cell (PIC) method. The main considerations are:

  • Particles interact with others in their own grid cell and adjacent cells.
  • Collisions occur when two particles come within a distance of ε = 0.005.
  • The simulation space wraps around at its boundaries.
  • Motion follows Newtonian mechanics with a fixed time-step of Δ = 0.1.

Implementation Details

Input Parameters

The program expects five command-line arguments:

  1. Seed (integer) - Initializes the random number generator.
  2. Space size (double) - Side length of the square simulation area.
  3. Grid size (integer) - Number of cells along each dimension.
  4. Number of particles (integer) - Total particles in the simulation.
  5. Time-steps (integer) - Number of simulation iterations.

Output

The program prints exactly two lines:

  1. Final x and y coordinates of particle 0, formatted to three decimal places.
  2. The number of particles that collided during the simulation.

Example:

$ ./parsim 1 2 3 10 1
1.570 0.056
0

Execution Time Measurement

Execution time is measured using omp_get_wtime() and printed to stderr. The result is printed separately to stdout.

Compilation and Execution

To compile the serial version:

gcc -o parsim parsim.c -fopenmp

To compile the OpenMP version:

gcc -o parsim-omp parsim-omp.c -fopenmp

To run the serial version:

./parsim <seed> <space_size> <grid_size> <num_particles> <time_steps>

To run the OpenMP version (with thread count specified by environment variable):

export OMP_NUM_THREADS=4
./parsim-omp <seed> <space_size> <grid_size> <num_particles> <time_steps>

Debug Mode

There's a debug mode that is activated if the flag -d is passed as an argument. This mode prints the grid and particles at each time step.

To run the serial version in debug mode:

./parsim -v <seed> <space_size> <grid_size> <num_particles> <time_steps> -d

Report

To build the report, run the following command:

cd report
pdflatex report.tex

Authors

Simão Sanguinho - 102082 Pedro Ribeiro - 102663 José Pereira - 103252 Parallel and Distributed Computing - 2024/2025

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages