0% found this document useful (0 votes)
40 views3 pages

Name:Bhumika Verma REG NO:19BCE1418 COURSE:CSE4001 (L49+50) Faculty:Dr.R.Gayathri

The document contains code snippets and output from two MPI programs. The first program demonstrates point to point communication between two processes. The second program implements a ping pong algorithm between two processes to count to 10.

Uploaded by

bhumika.verma00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Name:Bhumika Verma REG NO:19BCE1418 COURSE:CSE4001 (L49+50) Faculty:Dr.R.Gayathri

The document contains code snippets and output from two MPI programs. The first program demonstrates point to point communication between two processes. The second program implements a ping pong algorithm between two processes to count to 10.

Uploaded by

bhumika.verma00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

NAME:BHUMIKA VERMA

REG NO:19BCE1418
COURSE:CSE4001(L49+50)
FACULTY:DR.R.GAYATHRI
LAB-6
QUESTION 1:

CODE:
#include <mpi.h>
#include <stdio.h>
int main(int argc,char *argv[])
{
MPI_Init(&argc,&argv);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int number;
if (world_rank == 0)
{
number = -1;
MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if (world_rank == 1) {
MPI_Recv(&number, 1, MPI_INT, 0, 0,
MPI_COMM_WORLD,MPI_STATUS_IGNORE);
printf("Process 1 received number %d from process
0\n",number);
}
}

OUTPUT:
QUESTION 2:

CODE:
#include <stdio.h>
#include <mpi.h>
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv)
{
int my_id, root_process, ierr, num_procs;
MPI_Status status;
MPI_Init(&argc, &argv);

int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int ping_pong_count = 0;
int partner_rank = (world_rank + 1) % 2;
while (ping_pong_count < 10) {
if (world_rank == ping_pong_count % 2) {
// Increment the ping pong count before you send it
ping_pong_count++;
MPI_Send(&ping_pong_count, 1,MPI_INT,
partner_rank,0,MPI_COMM_WORLD);
printf("%d sent to %d, pingpong count=%d\n",
world_rank,partner_rank,ping_pong_count);
} else {
MPI_Recv(&ping_pong_count, 1, MPI_INT,
partner_rank,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE);
printf("%d received from %d, ping pong count=
%d\n",world_rank,partner_rank, ping_pong_count);
}
}
MPI_Finalize();
}
OUTPUT:

You might also like