This repository contains solutions for the MPI parallel computing assignment, which includes two problems: Counting Prime Numbers and Caesar Cipher Encryption.
The task is to write a parallel C program to count prime numbers between a given range using MPI_Send and MPI_Receive only.
-
Master Process:
- Calculates the sub-range size
r = (y - x) / p
. - Broadcasts
x
andr
to each slave process using MPI_Send. - Receives sub-count from each slave process using MPI_Receive.
- Prints the total count of primes between
x
andy
.
- Calculates the sub-range size
-
Slave Process:
- Receives
x
andr
through MPI_Receive. - Calculates the lower bound
a
and upper boundb
according to its rank. - Counts primes in its sub-range (between
a
andb
). - Prints the partial count.
- Sends this partial count to the master process using MPI_Send.
- Receives
- Compile the program using MPI:
mpicc -g counting_primes.c -o counting_primes -lmpi -lmpi_cxx
- Run the program using mpiexec:
mpirun -n <num_processes> ./counting_primes