#include "stdafx.h"

#include <mpi.h>

// send3

int main(int argc, char *argv[])
{
    int Pid;
	int numprocs;
	int prev, next;
	int x, y;
	int tag1=0;
	int tag2=0;
	MPI_Status	status;

	MPI_Init(&argc, &argv);

	MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
	MPI_Comm_rank(MPI_COMM_WORLD,&Pid);
	prev = (Pid-1+numprocs) % numprocs;
	next = (Pid+1) % numprocs;
	x=Pid+1;


	MPI_Sendrecv(	
		&x,	1,	MPI_INT,	next,	tag1,
		&y,	1,	MPI_INT,	prev,	tag2,	
		MPI_COMM_WORLD, &status);
	
	printf("Pid: %d  X: %d    Y: %d \n",  Pid, x, y);

	MPI_Finalize();

	return 0;
}

