LJ Archive

Listing 1. PVM Timing Master Program

/***********************************************
* PVM Timing - Master Program, File: master_tim.c
* PVM Version used: 3.3.x
* Comment: This file is an adaptation of one
* packaged with the PVM source.
****************************************************/

#include <time.h> /* include file for timing */
#include "pvm3.h"   /* PVM version 3.0
               include file */

main() {
   int mytid;  /* PVM task id for master */
   int wtid;   /* PVM task id for worker */
   int rtid, rtag, rlen;   /* parameters needed
               by pvm_precv */
   struct timeval tv1, tv2; /* for timing */
   int delta_t;   /* time difference */
   int i;   /* loop index */
   int int_array[10];   /* int for message */

   /* initialize and print array */
   for (i=0; i<10; i++){
     int_array[i] = 1;
     printf("int_array[%d] = %d\n",
      i, int_array[i]);
   }

   /* enroll this task in PVM */
   mytid = pvm_mytid();

   /* spawn slave */
      pvm_spawn("slave_tim", NULL,
      PvmTaskDefault, "", 1, &wtid);


   /* get initial time */
   /* before time */
   gettimeofday(&tv1, (struct timezone*)0);

   /* send array to slave */
   pvm_psend(wtid, 1, int_array, 10, PVM_INT);

   /* receive return array */
   pvm_precv(wtid, 2, int_array, 10, PVM_INT,
      &rtid, &rtag, &rlen);

   /* get final time */
   /* after time */
   gettimeofday(&tv2, (struct timezone*)0);

   /* calculate round trip delta_t and print */
   delta_t = (tv2.tv_sec - tv1.tv_sec) * 1000000
      + tv2.tv_usec - tv1.tv_usec;
   printf("Array's round trip in uSec = %8d\n",
       delta_t);

   /* print final array to show that slave
    * has changed it */
   for (i=0; i<10; i++)
     printf("int_array[%d] = %d\n",
      i, int_array[i]);

   /* exit from PVM */
   pvm_exit();
   exit(0);
}
LJ Archive