This repository contains a high-performance implementation of Monte Carlo Tree Search (MCTS) applied to a stochastic Gridworld pathfinding problem.
Implemented for the Project Work in Architectures and Platforms for Artificial Intelligence at the University of Bologna (a.y. 2025/2026).
The goal of the agent is to navigate a
The project implements:
- Serial MCTS: A baseline implementation.
- Root Parallelization (OpenMP): Multiple independent MCTS trees are executed in parallel on different CPU cores. Their results are aggregated (ensemble method) to determine the final move.
- Leaf Parallelization (CUDA): The tree search and selection logic remain on the CPU, while the computationally expensive rollout (simulation) phase is offloaded to the GPU. A batch of parallel simulations is executed for every expanded node.
The project uses a Makefile to manage the build process for both the CPU and GPU executables.
To build the entire project run
makeThis will create two directories:
- obj/: Intermediate object files.
- bin/: Final executables.
To clean the build artifacts run
make cleanTo manually compile the two implementations run
gcc -std=c99 -Wall -Wextra -fopenmp \
src/gridworld.c src/mcts.c src/main.c \
-o bin/mcts_omp \
-lmfor OMP and
nvcc -c src/cuda_rollout.cu -o cuda_rollout.o
gcc -std=c11 -Wall -Wextra -fopenmp -DENABLE_GPU \
src/gridworld.c src/mcts.c src/main.c cuda_rollout.o \
-o bin/mcts_cuda \
-lm -lcudartfor CUDA
to specify the number of threads, set the OMP_NUM_THREADS environment variable:
export OMP_NUM_THREADS=8
Then run the OpenMP executable:
./bin/mcts_omp [seed]run
./bin/mcts_cuda [seed] [rollouts]seed: (optional) Random seed for reproducibility (default = 36).rollouts: (optional, CUDA only) Number of rollouts per simulation (default = 256).