/*
** Send a message that is too large
** Copyright Rolf Riesen 2008
** 
** 
*/
#include <stdio.h>
#include <string.h>     /* For memset() */
#include <mpi.h>


#define SEND_SIZE       (100000)
#define RECV_SIZE       (2000)



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

int my_rank, nproc;
int tag;
int count;
MPI_Status status;
char send_buf[SEND_SIZE];
char 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= 0;
    memset(send_buf, 0, SEND_SIZE);
    memset(recv_buf, 0, RECV_SIZE);


    if (my_rank == 0)   {
        printf("Rank %d is sending %d bytes to rank 1\n",
            my_rank, SEND_SIZE);
	MPI_Send(send_buf, SEND_SIZE, MPI_CHAR, 1, tag,
            MPI_COMM_WORLD);
        printf("Rank %d: Sent %d bytes.\n", my_rank, SEND_SIZE);
    } else if (my_rank == 1)   {
        printf("Rank %d is accepting %d bytes from rank 0\n",
            my_rank, RECV_SIZE);
	MPI_Recv(recv_buf, RECV_SIZE, MPI_CHAR, 0, tag,
            MPI_COMM_WORLD, &status);
        MPI_Get_count(&status, MPI_CHAR, &count);
        printf("Rank %d: Received %d bytes.\n", my_rank, count);
    } else   {
        /* Do nothing */
    }

    printf("Rank %d: Done sending and receiving.\n", my_rank);
    MPI_Finalize();
    return 0;

}  /* end of main() */
