+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
bc9a89f
master
1// Author: Wes Kendall 2// Copyright 2011 www.mpitutorial.com 3// This code is provided freely with the tutorials on mpitutorial.com. Feel 4// free to modify it for your own use. Any distribution of the code must 5// either provide a link to www.mpitutorial.com or keep this header intact. 6// 7// MPI_Send, MPI_Recv example. Communicates the number -1 from process 0 8// to process 1. 9// 10#include <mpi.h> 11#include <stdio.h> 12#include <stdlib.h> 13 14int main (int argc ,char ** argv ) { 15// Initialize the MPI environment 16MPI_Init (NULL ,NULL ); 17// Find out rank, size 18int world_rank ; 19MPI_Comm_rank (MPI_COMM_WORLD ,& world_rank ); 20int world_size ; 21MPI_Comm_size (MPI_COMM_WORLD ,& world_size ); 22 23// We are assuming at least 2 processes for this task 24if (world_size < 2 ) { 25fprintf (stderr ,"World size must be greater than 1 for %s\n" ,argv [0 ]); 26MPI_Abort (MPI_COMM_WORLD ,1 ); 27 } 28 29int number ; 30if (world_rank == 0 ) { 31// If we are rank 0, set the number to -1 and send it to process 1 32number = -1 ; 33/* MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) */ 34MPI_Send (& number ,1 ,MPI_INT ,1 ,0 ,MPI_COMM_WORLD ); 35 }else if (world_rank == 1 ) { 36/* MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status status) */ 37MPI_Recv (& number ,1 ,MPI_INT ,0 ,0 ,MPI_COMM_WORLD ,MPI_STATUS_IGNORE ); 38printf ("Process 1 received number %d from process 0\n" ,number ); 39 } 40MPI_Finalize (); 41}