/*
** Print the envelope information of a message
** Copyright Rolf Riesen 2008
** 
** 
*/
#include <stdio.h>
#include <string.h>     /* For memset() */
#include <mpi.h>


#define SEND_SIZE       (50)    /* ints */
#define RECV_SIZE       (2000)  /* ints */



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

int my_rank, nproc;
int i;
int tag, src;
int count;
MPI_Status status;
int send_buf[SEND_SIZE];
int recv_buf[RECV_SIZE];


    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nproc);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    /* Initialize some variables */
    tag= 12;
    memset(recv_buf, 0, RECV_SIZE * sizeof(int));
    for (i= 0; i < SEND_SIZE; i++)   {
        send_buf[i]= i;
    }


    if (my_rank == 0)   {
	MPI_Send(send_buf, SEND_SIZE, MPI_INT, 1, tag,
            MPI_COMM_WORLD);

    } else if (my_rank == 1)   {
	MPI_Recv(recv_buf, RECV_SIZE, MPI_INT, MPI_ANY_SOURCE,
            MPI_ANY_TAG, MPI_COMM_WORLD, &status);

        src= status.MPI_SOURCE;
        tag= status.MPI_TAG;
        MPI_Get_count(&status, MPI_INT, &count);

        printf("Rank %d: Received %d items from rank %d with tag %d.\n",
            my_rank, count, src, tag);

    } else   {
        /* Do nothing */
    }

    MPI_Finalize();
    return 0;

}  /* end of main() */
