#include <stdlib.h>
#include <stdio.h>
#include <mpi.h>

/* #define ndata 1000 */
#define ndata 1000000 /* e cosÃ, funziona! */


int main(int argc, char* argv[]){

    int ierr, me, nprocs, i=0, left, right, req;
    MPI_Status status;
    
    float a[ndata];
    float b[ndata];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &me);

    	
    for(i=0;i<ndata;++i){
	a[i] = me;
	b[i] = -1;
    } 
    
    right = (me+1)%nprocs;
    left = ((me-1)+nprocs)%nprocs;
 
    MPI_Isend(a, ndata, MPI_REAL, right, 0, MPI_COMM_WORLD, &req);
    MPI_Recv(b, ndata, MPI_REAL, left, 0, MPI_COMM_WORLD, &status);	    

/*    MPI_Sendrecv(a, ndata, MPI_REAL, right, 0, b, ndata, MPI_REAL, left, 0, MPI_COMM_WORLD, &status);
*/
    printf("\n\tI am task %d and I have received b(0) = %1.2f \n", me, b[0]);
  
    MPI_Finalize();

}

	
