#include "stdafx.h"

#include <mpi.h>


int main(int argc, char *argv[])
{
    int Pid;
	int numprocs;
	int prev, next;
	int x, y;
	int tag=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_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_Send( &x, 1, MPI_INT, next, 0, MPI_COMM_WORLD);
	MPI_Recv( &y, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, &status);
	printf("Pid: %d  X: %d    Y: %d \n",  Pid, x, y);

	MPI_Finalize();

	return 0;
}

