~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/dist/pvm/src/master.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
#include <stdio.h>
 
33
#include <stdlib.h>
 
34
#include <unistd.h>
 
35
 
 
36
#include <signal.h>
 
37
 
 
38
#include "pvm3.h"
 
39
 
 
40
#define SLAVENAME "slave"
 
41
#define SLAVENAME_CKPT "slave_ckpt"
 
42
 
 
43
int main(int argc, char **argv)
 
44
{
 
45
   int mytid;                  /* my task id */
 
46
   int tids[32];                                /* slave task ids */
 
47
   int n, nproc, numt, i, who, msgtype, nhost, narch;
 
48
   float data[100], result[32];
 
49
   struct pvmhostinfo *hostp[32];
 
50
 
 
51
   printf("before pvm_mytid()\n"); fflush(stdout);
 
52
   /* enroll in pvm */
 
53
   mytid = pvm_mytid();
 
54
   printf("pvm_mytid() = 0x%x\n", mytid); fflush(stdout);
 
55
 
 
56
   /* Set number of slaves to start */
 
57
   /* Can not do stdin from spawned task */
 
58
   if( pvm_parent() == PvmNoParent ) {
 
59
      printf("no parents\n"); fflush(stdout);
 
60
      if (argc>1) {
 
61
         nproc = atoi(argv[1]);
 
62
      }
 
63
      else {
 
64
         puts("How many slave programs (1-32)?");
 
65
         scanf("%d", &nproc);
 
66
      }
 
67
   } else{
 
68
      pvm_config( &nhost, &narch, hostp );
 
69
      nproc = nhost;
 
70
      if( nproc > 32 ) 
 
71
         nproc = 32 ;
 
72
   }
 
73
 
 
74
   /* start up slave tasks */
 
75
   printf("Try to spawn %d slaves\n", nproc); fflush(stdout);
 
76
   numt=pvm_spawn(getenv("SGE_CKPT_ENV")?SLAVENAME_CKPT:SLAVENAME, 
 
77
      (char**)0, 0, "", nproc, tids);
 
78
   if( numt < nproc ) {
 
79
      printf("Trouble spawning slaves. Aborting. Error codes are:\n"); fflush(stdout);
 
80
      for( i=numt ; i<nproc ; i++ ) {
 
81
         printf("TID %d %d\n",i,tids[i]); fflush(stdout);
 
82
      }
 
83
      for( i=0 ; i<numt ; i++ ) {
 
84
         pvm_kill( tids[i] );
 
85
      }
 
86
      pvm_exit();
 
87
      exit(1);
 
88
   }
 
89
 
 
90
   printf("got %d tasks\n", numt); fflush(stdout);
 
91
 
 
92
   /* Begin User Program */
 
93
   n = 100;
 
94
   /* initialize_data( data, n ); */
 
95
   for( i=0 ; i<n ; i++ ) {
 
96
      data[i] = 1;
 
97
   }
 
98
 
 
99
   printf("broadcasting data to tasks\n"); fflush(stdout);
 
100
 
 
101
   /* Broadcast initial data to slave tasks */
 
102
   pvm_initsend(PvmDataDefault);
 
103
   pvm_pkint(&nproc, 1, 1);
 
104
   pvm_pkint(tids, nproc, 1);
 
105
   pvm_pkint(&n, 1, 1);
 
106
   pvm_pkfloat(data, n, 1);
 
107
   while (pvm_mcast(tids, nproc, 0)) {
 
108
      fprintf(stderr, "failure broadcasting data - retry\n");
 
109
      sleep(1);
 
110
   }
 
111
 
 
112
   printf("wait for results from slaves\n"); fflush(stdout);
 
113
 
 
114
   /* Wait for results from slaves */
 
115
   msgtype = 5;
 
116
   for( i=0 ; i<nproc ; i++ ) {
 
117
      pvm_recv( -1, msgtype );
 
118
      pvm_upkint( &who, 1, 1 );
 
119
      pvm_upkfloat( &result[who], 1, 1 );
 
120
      printf("I got %f from %d\n",result[who],who);
 
121
   }
 
122
   /* Program Finished exit PVM before stopping */
 
123
   pvm_exit();
 
124
   return 0;
 
125
}
 
126