5. Write a MPI Program to demonstration of MPI_Send and MPI_Recv.
- How to run Program ?
- Click Build on codeblocks only → Build or press
Ctrl+F9
- This will create an
.exe
file inside your projectbin\Debug
folder. - Go to your project folder (e.g.
OneDrive\Desktop\Parallel-programs\Program5\bin\Debug
) based on where you saved your program. - You’ll find something like: main.exe or FileName.exe for example (
Program5
.exe) - Open Command Prompt.
- Navigate to Your
.exe
Location (eg: cd OneDrive\Desktop\Parallel-programs\Program5\bin\Debug) based on where you saved your program. - Type command to run the program: mpiexec -n 2 FileName.exe for example (
Program5
.exe).
- Click Build on codeblocks only → Build or press

PROGRAM:
#include <mpi.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int rank, size;
int number;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (size < 2) {
if (rank == 0)
printf("Please run with at least 2 processes.\n");
MPI_Finalize();
return 0;
}
if (rank == 0) {
number = 100;
printf("Process %d sending number %d to process 1\n", rank, number);
MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else if (rank == 1) {
MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Process %d received number %d from process 0\n", rank, number);
}
MPI_Finalize();
return 0;
}
OUTPUT:

s i got output for give given.
i tried as -n 4 p5.exe no changes is observed, like no of processes — nochanges in output. plz explain
i really dont know the theory by this stage actually.
plz provide 2 more cases of output for better understanding