#include<mpi.h>
#include<stdio.h>
#define TRUE 1
#define FALSE 0
int main(int argc, char *argv[]) {
    MPI_Status status;
    int rank,i,j;
    MPI_Comm A_New_MPI_World;
    int dim[2],period[2],reorder;
    int coord[2],id,the_rank;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    period[0]=TRUE; period[1]=FALSE;
    dim[0]=4; dim[1]=3;
#include "myshifts.h"
    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) {
        for (i=0;i<4;i++) {
            for (j=0;j<3;j++) {
                coord[0]=i; coord[1]=j;
                MPI_Cart_rank(A_New_MPI_World,coord,&the_rank);
                printf("Task: %i is at coordinates(%i,%i)\n", the_rank,coord[0],coord[1]);
                printf("   Up is: %i  ", up(coord));
                printf("   Down is: %i  ", down(coord));
                printf("   Left is: %i  ", left(coord));
                printf("   Right is: %i \n", right(coord));
            }
        }
    }

    MPI_Finalize();
}