/* AVE_SLAVE.C
*  
*  Slave program which does the actual work.
*/

#include <stdio.h>
#include "pvm3.h"

int main (int argc, char *argv[]) {
   /* Initialize some variables */
  char buf[100];
  int parent_id, average, bufid, my_index; 
    /* Place where the grades to be averaged go */
  int grades[7];

    /* Get the task id of the parent process */
  parent_id = pvm_parent();

    /* Recieve from the parent */
  bufid = pvm_recv(parent_id, 5);
    /* Get some info about the buffer we're going to use (actually */
    /* this isn't used, but I thought I should put it in           */
  pvm_bufinfo(bufid, (int*)0, (int*)0, (int*)0);
    /* Unpack the index of the student we're calculating */
  pvm_upkint(&my_index,  1, 1);
    /* Unpack the student's grades */
  pvm_upkint(grades,  7, 1);
  
  /* Where the real work is done */
  average = ((grades[0]+grades[1]+grades[2]+grades[3])/400.0)*40.0 +
    (grades[4]/100.0)*20.0 +
    (grades[5]/100.0)*20.0 +
    (grades[6]/100.0)*20.0;

    /* Initialize the send buffer */
  pvm_initsend(PvmDataDefault);
    /* Pack the index of the student */
  pvm_pkint(&my_index, 1, 1);
    /* Pack the average */
  pvm_pkint(&average, 1, 1);
    /* Send it on its merry way... */
  pvm_send(parent_id, 4);
    
    /* Quit PVM */
  pvm_exit();
  exit(0);
}    
