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

« back to all changes in this revision

Viewing changes to source/dist/pvm/src/start_pvm.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 <sys/types.h>
 
35
#include <unistd.h>
 
36
#include <string.h>
 
37
#include "pvm3.h"
 
38
 
 
39
#if defined(__STDC__) || defined(__cplusplus)
 
40
#define __PR__(x) x
 
41
#else
 
42
#define __PR__(x) ()
 
43
#endif
 
44
 
 
45
#define uid_t_fmt "%ld"
 
46
 
 
47
#define SLEEPTIME 5
 
48
#define RETRIES   10
 
49
 
 
50
static void delete_hanging_socket __PR__((void));
 
51
static int wait_until_pvm_runs __PR__((int numhosts));
 
52
static void usage __PR__((FILE *out));
 
53
 
 
54
int main __PR__(( int argc, char *argv[]));
 
55
 
 
56
/* 
 
57
 * start pvm and return when pvm is started
 
58
 * arguments are the number of nodes to be
 
59
 * controlled by start_pvm
 
60
 *
 
61
 */
 
62
 
 
63
/*-------------------------------------------------------------------------*/
 
64
static void delete_hanging_socket()
 
65
{
 
66
   char socknam[256];
 
67
 
 
68
   sprintf(socknam, "/tmp/pvmd.%ld", (u_long)getuid());
 
69
   unlink(socknam);
 
70
}
 
71
 
 
72
/*-------------------------------------------------------------------------*/
 
73
static int wait_until_pvm_runs(numhosts)
 
74
int numhosts;
 
75
{
 
76
   int nh, na;
 
77
   struct pvmhostinfo *hinfo = NULL;
 
78
   int retry = RETRIES;
 
79
   int rc;
 
80
   int tid;
 
81
 
 
82
   sleep(SLEEPTIME);            /* give pvm time to enroll local daemon */
 
83
 
 
84
   /* first enroll */
 
85
   while (retry--)
 
86
      if ((tid = pvm_mytid()) < 0)
 
87
         sleep(SLEEPTIME);
 
88
      else
 
89
         break;
 
90
   if (tid < 0) {
 
91
      fprintf(stderr, "start_pvm: Couldn't enroll to pvm\n");
 
92
      return 1;
 
93
   }
 
94
 
 
95
   printf("start_pvm: enrolled to local pvmd\n");
 
96
   
 
97
   if (!numhosts) {
 
98
      pvm_exit();
 
99
      return 0;
 
100
   }
 
101
 
 
102
   sleep(numhosts * SLEEPTIME); /* give pvm time to enroll remote daemons */
 
103
   while (retry--) {
 
104
      if (!(rc = pvm_config(&nh, &na, &hinfo))) {
 
105
         if (nh == numhosts) {
 
106
            printf("start_pvm: got %d hosts\n", numhosts);
 
107
            pvm_exit();
 
108
            return 0;
 
109
         }
 
110
 
 
111
/* may be this is useful if problems occur */
 
112
#if 1
 
113
{
 
114
   int i;
 
115
   printf("start_pvm: got %d of %d hosts\n", nh, numhosts);
 
116
   for (i=0; i<nh; i++) {
 
117
      printf("start_pvm: %d %s %s %d\n", 
 
118
      hinfo->hi_tid, 
 
119
      hinfo->hi_name, 
 
120
      hinfo->hi_arch, 
 
121
      hinfo->hi_speed); 
 
122
   }
 
123
}   
 
124
#endif
 
125
 
 
126
      }
 
127
      sleep(SLEEPTIME);
 
128
   }
 
129
 
 
130
   fprintf(stderr, "startpvm: Couldn't get all of the %d requested hosts\n",
 
131
           numhosts);
 
132
   return 1;
 
133
}
 
134
 
 
135
/* start_pvm is not responsible for converting hostfiles   */
 
136
/* so the hostfile is nothing more than a simple parameter */ 
 
137
/* that gets passed to pvmd                                */ 
 
138
static void usage(out)
 
139
FILE *out;
 
140
{
 
141
   fprintf(out, "usage: start_pvm [-h numhosts] pvmd-path [pvmd-parameters ..]\n");
 
142
}
 
143
 
 
144
/*-------------------------------------------------------------------------*/
 
145
int main(argc, argv)
 
146
int argc;
 
147
char *argv[];
 
148
{
 
149
   int numhosts = 0;
 
150
   char *s=NULL;
 
151
 
 
152
   if (argc < 2) {
 
153
      usage(stderr);
 
154
      return 1;
 
155
   }
 
156
 
 
157
   if (!strcmp(argv[1], "-h")) {
 
158
      argc--;
 
159
      argv++;
 
160
 
 
161
      numhosts = strtol(argv[1], &s, 10);
 
162
      if (*s) {
 
163
         usage(stderr);
 
164
         return 1;
 
165
      }
 
166
 
 
167
      argc--;
 
168
      argv++;
 
169
   }
 
170
 
 
171
   delete_hanging_socket();
 
172
 
 
173
   if (fork())
 
174
      _exit(wait_until_pvm_runs(numhosts));
 
175
 
 
176
   execvp(argv[1], &argv[1]);
 
177
   fprintf(stderr, "exec %s failed\n", argv[1]);
 
178
   exit(1);
 
179
}