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

#define PROC_NUM 3

int main()
{
  int myTID;
  int children[PROC_NUM];
  int res, i;

  myTID = pvm_mytid();
  printf("Master: TID is %d\n", myTID);

  res = pvm_spawn("ring-slave", NULL, PvmTaskDefault, "", PROC_NUM, children);
  if (res < 1)
  {
    printf("Master: pvm_spawn error (res=%d)\n", res);
    pvm_exit();
    exit(1);
  }

  // send neighbors' TIDs
  for(i=0; i<PROC_NUM; i++)
  {
    pvm_initsend(PvmDataDefault);
    pvm_pkint(&children[(i-1+PROC_NUM)%PROC_NUM], 1, 1);
    pvm_pkint(&children[(i+1)%PROC_NUM], 1, 1);
    pvm_send(children[i], 1);
  }

  // test the ring
  i=1;
  pvm_initsend(PvmDataDefault);
  pvm_pkint(&i, 1, 1);
  pvm_send(children[0], 1);

  pvm_exit();

  return 0;
}

