Skip to content

fatihsert41/MPI_Process

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CENG 342 - HW1: Rock-Paper-Scissors Game with MPI

Student: Suleyman Fatih Sert - 22050111031
Course: CENG 342 - Parallel Programming
Date: March 2026

Project Description

This project implements a Rock-Paper-Scissors game using MPI (Message Passing Interface) with 2 processes. The program supports two different communication modes to demonstrate distributed memory parallel programming concepts.

Game Rules

  • Rock beats Scissors
  • Scissors beats Paper
  • Paper beats Rock
  • If both processes choose the same move, the result is a draw and the round is replayed
  • The game continues until one process reaches 5 points

Communication Modes

Mode 0 - Point-to-Point (P2P)

Uses MPI_Send and MPI_Recv for direct communication between processes:

  • Process 1 sends its move to Process 0 using MPI_Send (tag 20)
  • Process 0 (referee) receives the move with MPI_Recv, determines the winner, updates the score, and prints the results
  • Process 0 sends the game status (continue/stop) back to Process 1 using MPI_Send (tag 30)

Mode 1 - Collective Communication

Uses MPI_Gather and MPI_Bcast for group communication:

  • MPI_Gather collects both processes' moves at Process 0
  • Process 0 evaluates the round and updates the score
  • MPI_Bcast broadcasts the game status (continue/stop) to all processes

Program Structure

Function Description
move_name() Converts move integer (0,1,2) to string (ROCK, PAPER, SCISSORS)
find_winner() Determines the winner of a round (0=draw, 1=P0 wins, 2=P1 wins)
play_p2p() Runs the game using point-to-point communication
play_collective() Runs the game using collective communication
main() Initializes MPI, handles mode selection, and starts the game

Process Roles

  • Process 0 (Referee): Receives moves, determines winners, tracks score, prints all output
  • Process 1 (Player): Generates random moves and sends them to Process 0

Random Number Generation

Each process uses a different seed for random number generation:

srand(time(NULL) + rank * 100);

This ensures that both processes generate independent random moves in each run.

Files

File Description
game.c Main source code
Makefile Build configuration
report.pdf Project report with screenshots
hw1_p2p.png Screenshot of P2P mode run
hw1_collective.png Screenshot of Collective mode run
hw1_general.png Screenshot of general run

Build & Run

make
mpirun -n 2 ./game

Example Output

The game starts
Select mode: 0 (P2P) or 1 (Collective)
0
Mode: 0
Turn 1, Process-0: ROCK, Process-1: PAPER
Process-1 wins, Score: 0 - 1
Turn 2, Process-0: SCISSORS, Process-1: SCISSORS
Draw! Replaying...
Turn 3, Process-0: PAPER, Process-1: ROCK
Process-0 wins, Score: 1 - 1
...
Process-1 has won the game with score: 5 - 3 in 9 turns.
The game ends

Screenshots

P2P Mode

P2P Mode

Collective Mode

Collective Mode

General Run

General Run

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors