#include <stdio.h>

#include "localmpi.h"
#include "extern.h"

int child_proc()
{
    // Allocate a string for unique specifier for the actual node

    char    processor_name[MPI_MAX_PROCESSOR_NAME];
    int     name_length;

    // Message parameters

    char    message[MAX_MSG_LEN + 1];
    int     destination;
    int     tag = 0;            // Message ID

    // Get the name of processor

    mpi_err = MPI_Get_processor_name ( processor_name, &name_length ); 
    if ( mpi_err != MPI_SUCCESS )
    {
    handle_err ( "child_proc" );
        fprintf ( stderr, "Error in getting name of processor\n" );
    return ( 1 );
    }
    
    sprintf ( message, "Greetings from process # %d running on %s", my_rank, processor_name );
    
    destination = MASTER_RANK;

    // Send a basic message to master process.

    mpi_err = MPI_Send ( message, strlen ( message ) + 1, MPI_CHAR, destination, tag, MPI_COMM_WORLD );
    if ( mpi_err != MPI_SUCCESS )
    {
        handle_err ( "child_proc" );
    return ( 1 );
    }

    return ( 0 );
}