
// This slave process will receive an integer, and send back the reciprocal

#include <stdio.h>
#include "/usr/local/pvm3/include/pvm3.h"

main()
 { int mytid, nproc;
   int master, msgtype;
   float reciprocal;
   int num;

/* Enroll in pvm */
   mytid = pvm_mytid();    // Get my processor ID

/* Receive data from master */
   msgtype = 99;                // This was arbitrarily set in master.c
   pvm_recv( -1, msgtype );     // Get ready to receive initial data
   pvm_upkint(&num,1, 1);       // Unpack Number sent by master 

if (num==0)
    {reciprocal = 0.0;}
else
    {reciprocal = 1.0 / num;}

/* Send data back to master */
   pvm_initsend( PvmDataDefault );      // Get Buffer ready to send data
   pvm_pkint( &mytid, 1, 1 );           // Pack which processor I am
   pvm_pkfloat( &reciprocal, 1, 1);     // Pack Reciprocal of number 
   msgtype = 55;                        // Identify message type
   master = pvm_parent();              // Find out where I came from
   pvm_send( master, msgtype );        // Send message back to parent process

/* Program finished. Exit PVM before stopping */
   pvm_exit();

}  



