home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adaptor.zip / adapt.zip / adaptor / dalib / pvm3 / mhost.c < prev    next >
Text File  |  1993-11-30  |  5KB  |  153 lines

  1. /*******************************************************************
  2. *                                                                  *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                    *
  4. *  Copyright   : GMD St. Augustin, Germany                         *
  5. *  Date        : Feb 92                                            *
  6. *  Last Update : Aug 92                                            *
  7. *                                                                  *
  8. *  This Module is part of the DALIB                                *
  9. *                                                                  *
  10. *  MAIN of HOST PROGRAM (for PVM)                                  *
  11. *                                                                  *
  12. *  MODULE : mhost.c                                                *
  13. *                                                                  *
  14. *  Function: Realization of System Dependent Operations            *
  15. *                                                                  *
  16. *  - enrolls host in PVM                                           *
  17. *  - initiates node processes                                      *
  18. *  - calls hostmodule ()                                           *
  19. *                                                                  *
  20. *******************************************************************/
  21.  
  22. /*******************************************************************
  23. *                                                                  *
  24. *  Interface to Adaptor:                                           *
  25. *                                                                  *
  26. *    dalib_pid ()                                                  *
  27. *    dalib_nproc ()                                                *
  28. *                                                                  *
  29. *******************************************************************/
  30.  
  31. /* not needed: #include <machine/param.h> */
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include "system.h"
  35. #include "pvm3.h"
  36.  
  37. int NP;          /* number of node processes */
  38. int my_id;       /* number of my process: 0 (host), 1 .. NP */
  39.  
  40. #define INIT_MSGID 9999
  41.  
  42. #if defined(IBM)
  43. void hostmodule ();
  44. #else
  45. void hostmodule_ ();
  46. #endif
  47.  
  48. int MAIN__ (argc, argv)
  49. int argc;
  50. char **argv;
  51.  
  52. { int i, j;
  53.   int ntasks;
  54.   int me;
  55.  
  56.   unsigned long startt;   /* start timer value */
  57.   int htrace_flag;
  58.  
  59.   /* evaluation of parameters */
  60.  
  61.   my_id = 0;
  62.  
  63.   target_model = 0;   /* with host */
  64.  
  65.   /* enroll in PVM */
  66.  
  67.   tids[0] = pvm_mytid();
  68.  
  69.   if (tids[0] < 0)
  70.       { /* there is an error , illegal tid */
  71.         if (tids[0] == PvmSysErr)
  72.             printf ("pvmd not responding\n");
  73.           else
  74.             printf ("illegal tid\n");
  75.         exit (-1);
  76.       }
  77.  
  78.   /* Get number of hosts in configuartion */
  79.  
  80.   pvm_config (&NP, (int*) 0, (struct hostinfo**) 0);
  81.   eval_arg (NP, MAXP, &NP, &trace_flag);
  82.   trace_flag = 0;   /* not realized yet */
  83.  
  84.   /* create node processes */
  85.  
  86.   ntasks = pvm_spawn ("node.exe", (char**)0, PvmTaskDefault, "", NP, tids+1);
  87.  
  88.   if (ntasks != NP)
  89.      { if (ntasks < 0)
  90.            printf ("host: pvm_spawn has error code %d\n", ntasks);
  91.          else
  92.            printf ("host: pvm_spawn creates only %d tasks\n", ntasks);
  93.        exit(-1);
  94.      }
  95.  
  96.   printf ("host has spawn %d node processes\n", NP);
  97.  
  98.   for (i=1; i<=NP; i++)
  99.     if (tids[i] < 0)
  100.       { pvm_perror ("spawn failure");
  101.         pvm_exit ();
  102.         exit(-1);
  103.       }
  104.  
  105.   /* make initial message */
  106.  
  107.   pvm_initsend (PvmDataRaw);
  108.   pvm_pkbyte (&NP, 4, 1);
  109.   pvm_pkbyte (tids, (NP+1)*4, 1);
  110.   pvm_mcast  (tids+1, NP, INIT_MSGID);
  111.  
  112.   printf ("host has send initial message\n");
  113.  
  114.   /* wait for response of nodes */
  115.  
  116.   for (i=1; i<=NP; i++)
  117.     { pvm_recv (-1, INIT_MSGID - 1);
  118.       pvm_upkbyte (&me, 4, 1);
  119.       printf ("Node process %d responded\n", me);
  120.     }
  121.  
  122.   /* definition of the process control block */
  123.  
  124.   pcb.i       = my_id;
  125.   pcb.p       = NP;
  126.  
  127.   random_block_init ();
  128.   dalib_init_walltime ();
  129.  
  130.   /* initialization of tracing */
  131.  
  132. #if defined(IBM)
  133.   hostmodule ();
  134. #else
  135.   hostmodule_ ();
  136. #endif
  137.   pvm_exit ();
  138. }
  139.  
  140. /*******************************************************************
  141. *                                                                  *
  142. *  number and ids of processes                                     *
  143. *                                                                  *
  144. *******************************************************************/
  145.  
  146. int dalib_pid_ ()
  147. {
  148.    return (my_id);
  149. }
  150.  
  151. int dalib_nproc_ ()
  152. { return (NP); }
  153.