#include <mpi.h>
#include "main.h"
#include "slave.h"

void slave(int items_per_task) {
    for(;;) {
        unit_work_t work;
        MPI_Status status;

        /* Receive a message from the master */
        MPI_Recv(&work, items_per_task, MPI_DOUBLE, 0, MPI_ANY_TAG,
                MPI_COMM_WORLD, &status);

        /* Check the tag of the received message. */
        if(status.MPI_TAG == DIE_TAG)
            return;

        /* Do the work */
        unit_result_t result = do_work(&work, items_per_task);

        /* Send the result back */
        MPI_Send(&result, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD);
    }
}

unit_result_t do_work(unit_work_t *work, int items_per_task) {
    // Fill in with whatever is necessary to process the work and generate a
    // result.
    return .0;
}

