#include<mpi.h>
#include<stdio.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
int main(int argc, char *argv[]) {
    MPI_Status status;
    int rank,this_rank,that_rank,i,j;
    MPI_Comm A_New_MPI_World;
    int dim[2],period[2],reorder,rank_list[4][3],shifts[12][5];
    int coord[2],id;
    int the_rank,the_targetL,the_targetR;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    dim[0]=4; dim[1]=3;
    #include "myshifts.h"
    period[0]=TRUE; period[1]=FALSE;
    int send_receive[2];
    reorder=TRUE;   /* Can the processes be reordered, may result in improved performance.*/
    MPI_Cart_create(MPI_COMM_WORLD,2,dim,period,reorder,&A_New_MPI_World);
    if (rank==0) {
        coord[0]=2; coord[1]=1;
        MPI_Cart_rank(A_New_MPI_World,coord,&send_receive[0]);
        send_receive[1]=right(coord);
    }
    MPI_Bcast(&send_receive, 2, MPI_INT, 0, A_New_MPI_World);
    MPI_Barrier(A_New_MPI_World);
    the_rank=send_receive[0];
    the_targetR=send_receive[1];

    if (rank == the_rank) {
        char *tosend="Hello right of (2,1)";
        MPI_Send(&tosend, 50, MPI_CHAR,the_targetR, 123, A_New_MPI_World);
        printf("Task %i just sent \"%s\" to %i\n ",the_rank,tosend,the_targetR);
    }
    if (rank==the_targetR) {
        char *toget;
        MPI_Recv(&toget, 50, MPI_CHAR,the_rank, 123, A_New_MPI_World, &status);
        printf("Task %i heard \"%s\"\n ",rank,toget);
    }
    MPI_Finalize();
}