Muhammad Ali Pp Lab 5.docx

  • Uploaded by: Muhammad Ali
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Muhammad Ali Pp Lab 5.docx as PDF for free.

More details

  • Words: 162
  • Pages: 1
CSL-342: Parallel Programming lab Semester BSIT – 06 Student Name: Muhammad Ali Registration: 45911

Exercises Exercise 1 (write a code for MPI RING program by using MPI_Send and MPI_Recv processes,using five processes. In this task, a value is passed around by all processes in a ring-like fashion). Code #include "stdafx.h" #include "mpi.h" #include "iostream" using namespace std; 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 token; if (world_rank != 0) { MPI_Recv(&token, 1, MPI_INT, world_rank 1, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);

Output:

cout << "Process " << world_rank << " received token " << token << " from process " << world_rank - 1<<endl; } else{ token = -1; } MPI_Send(&token, 1, MPI_INT, (world_rank + 1) % world_size, 0,MPI_COMM_WORLD); if (world_rank == 0) { MPI_Recv(&token, 1, MPI_INT, world_size - 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); cout << "Process " << world_rank << " received token " << token << " from process " << world_size - 1<<endl; } MPI_Finalize(); }

Related Documents

Muhammad Ali
November 2019 32
Muhammad Ali
November 2019 27
Muhammad Ali
July 2020 19

More Documents from ""