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

#include "extern.h"

void handle_err ( char * fn_name )
{
    fprintf ( stderr, "%s: Error in function %s\n", prog_name, fn_name );

    switch ( mpi_err )
    {
    case MPI_ERR_ARG:
    fprintf ( stderr, "Invalid argument; some argument is invalid and is not identified by a specific error class\n" );
    break;

    case MPI_ERR_COMM:
    fprintf ( stderr, "Invalid communicator; Check for NULL communicator in call\n" );
    break;

    case MPI_ERR_COUNT:
        fprintf ( stderr, "Invalid count argument.  Count arguments must be non-negative; a count of zero is often valid\n" );
    break;

    case MPI_ERR_OTHER:
    fprintf ( stderr, "Attempt to call MPI_Init a second time\n" );
    break;

    case MPI_ERR_RANK:
    fprintf ( stderr, "Invalid source or destination rank\n");
    fprintf ( stderr, "Ranks must be between 0 and size of communicator minus 1\n");
    fprintf ( stderr, "Tags in a receive may also be MPI_ANY_SOURCE\n");
    break;

    case MPI_ERR_TAG:
    fprintf ( stderr, "Invalid tag argument;  Tags must be non-negative\n");
    fprintf ( stderr, "Tags in a receive may also be MPI_ANY_TAG\n");
    break;

    case MPI_ERR_TYPE:
    fprintf ( stderr, "Invalid datatype argument; May be an uncommitted datatype\n" );
    break;

    default:
    fprintf ( stderr, "Unrecognized error\n" );
    break;
    }
}