File: hostc.c

package info (click to toggle)
pvm 3.4beta7-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 5,256 kB
  • ctags: 5,938
  • sloc: ansic: 66,147; makefile: 1,446; fortran: 631; sh: 424; csh: 70; asm: 37
file content (320 lines) | stat: -rw-r--r-- 6,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320

static char rcsid[] =
	"$Id: hostc.c,v 1.4 1998/01/28 19:15:14 pvmsrc Exp $";

/*
 *         PVM version 3.4:  Parallel Virtual Machine System
 *               University of Tennessee, Knoxville TN.
 *           Oak Ridge National Laboratory, Oak Ridge TN.
 *                   Emory University, Atlanta GA.
 *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
 *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
 *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
 *                   (C) 1997 All Rights Reserved
 *
 *                              NOTICE
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby granted
 * provided that the above copyright notice appear in all copies and
 * that both the copyright notice and this permission notice appear in
 * supporting documentation.
 *
 * Neither the Institutions (Emory University, Oak Ridge National
 * Laboratory, and University of Tennessee) nor the Authors make any
 * representations about the suitability of this software for any
 * purpose.  This software is provided ``as is'' without express or
 * implied warranty.
 *
 * PVM version 3 was funded in part by the U.S. Department of Energy,
 * the National Science Foundation and the State of Tennessee.
 */

/*
 *	hostc.c
 *
 *	Local host table cache functions.
 *
$Log: hostc.c,v $
 * Revision 1.4  1998/01/28  19:15:14  pvmsrc
 * Commented out ancient #include <linux/time.h>...
 * (Spanker=kohl)
 *
 * Revision 1.3  1997/08/07  21:58:09  pvmsrc
 * Fixed stupid bugs...
 *
 * Revision 1.2  1997/07/09  13:56:50  pvmsrc
 * Fixed Author Header.
 *
 * Revision 1.1  1996/09/23  22:52:48  pvmsrc
 * Initial revision
 *
 */


#include <stdio.h>
#ifdef	SYSVSTR
#include <string.h>
#else
#include <strings.h>
#endif
#include <sys/types.h>
#include <sys/time.h>
/* #ifdef IMA_LINUX */
/* #include <linux/time.h> */
/* #endif */
#include <pvm3.h>
#include <../src/bfunc.h>
#include <../src/listmac.h>
#include "myalloc.h"
#include "hostc.h"


static struct hostc *curhosts = 0;
static int addtag = -1;
static int deltag = -1;
static int (*addcallback)() = 0;
static int (*delcallback)() = 0;


static struct hostc *
hc_new()
{
	struct hostc *hp;

	if (hp = TALLOC(1, struct hostc, "hd"))
		BZERO(hp, sizeof(struct hostc));
	return hp;
}


static int
hc_init()
{
	if (curhosts = hc_new())
		curhosts->link = curhosts->rlink = curhosts;

	else
		fprintf(stderr, "hc_init() out of memory\n");
	return 0;
}


static struct hostc *
hc_add(hip)
	struct pvmhostinfo *hip;
{
	struct hostc *hp, *hp2;

	/*
	* if we have a delete message tag and it's not this host, notify
	*/

	if (deltag != -1 && hip->hi_tid != pvm_tidtohost(pvm_mytid()))
		pvm_notify(PvmHostDelete, deltag, 1, &hip->hi_tid);

	if (hp = hc_new()) {
		hp->pvmd_tid = hip->hi_tid;
		hp->name = STRALLOC(hip->hi_name);
		hp->alias = STRALLOC(hip->hi_name);
		hp->arch = STRALLOC(hip->hi_arch);
		hp->speed = hip->hi_speed;
		pvm_hostsync(hp->pvmd_tid, (struct timeval *)0, &(hp->delta));
	}

	for (hp2 = curhosts->link; hp2 != curhosts; hp2 = hp2->link)
		if (hp->pvmd_tid < hp2->pvmd_tid)
			break;
	LISTPUTBEFORE(hp2, hp, link, rlink);

	return hp;
}


static int
hc_delete(hp)
	struct hostc *hp;
{
	LISTDELETE(hp, link, rlink);
	if (hp->name)
		MY_FREE(hp->name);
	if (hp->arch)
		MY_FREE(hp->arch);
	if (hp->alias)
		MY_FREE(hp->alias);
	MY_FREE(hp);
	return 0;
}


static struct hostc *
hc_find(tid)
{
	struct hostc *hp;

	for (hp = curhosts->link; hp != curhosts; hp = hp->link)
		if (tid <= hp->pvmd_tid)
			break;
	return (tid == hp->pvmd_tid) ? hp : (struct hostc *)0;
}


/*	host_init()
*
*	Initialize host cache.  Called once at beginning of time.
*	Synchronize to current configuration.
*	Specify message tags to be used for HostAdd and HostDelete notify.
*/

host_init(atag, dtag, acb, dcb)
	int atag;			/* message tag to use for HostAdd notify or -1 */
	int dtag;			/* tag to use for HostDelete notify or -1 */
	int (*acb)();		/* callback for each host added */
	int (*dcb)();		/* callback for each host deleted */
{
	struct pvmhostinfo *hip;
	int nh;

	addtag = atag;
	deltag = dtag;
	addcallback = acb;
	delcallback = dcb;

	hc_init();

	if (addtag != -1)
		pvm_notify(PvmHostAdd, addtag, -1, (int *)0);

	if (!pvm_config(&nh, (int *)0, &hip)) {
		while (nh > 0) {
			nh--;
			hc_add(&hip[nh]);
		}
	}
	return 0;
}


/*	host_add()
*
*	Called when a HostAdd notify message has been received.
*	The message is in the current receive buffer.
*/

host_add()
{
	int d = 0;
	int n;
	int *dtids;
	int i, j;
	struct pvmhostinfo *hip;
	int nh;

	pvm_upkint(&n, 1, 1);
	if (n < 1 || n > 4096)
		return 0;
	dtids = TALLOC(n, int, "dtid");
	pvm_upkint(dtids, n, 1);
	pvm_freebuf(pvm_getrbuf());
	if (!pvm_config(&nh, (int *)0, &hip)) {
		for (j = n; j-- > 0; )
			for (i = nh; i-- > 0; ) {
				if (dtids[j] == hip[i].hi_tid) {
					hc_add(&hip[i]);
					if (addcallback)
						addcallback(dtids[j]);
					d++;
					break;
				}
			}
	}
	MY_FREE(dtids);
	return d;
}


/*	host_delete()
*
*	Called when a HostDelete notify message has been received.
*	The message is in the current receive buffer.
*/

host_delete()
{
	int tid;
	struct hostc *hp;
	int d = 0;

	pvm_upkint(&tid, 1, 1);
	if (tid == pvm_tidtohost(tid) && (hp = hc_find(tid))) {
		if (delcallback)
			delcallback(tid);
		hc_delete(hp);
		d++;
	}
	return d;
}


struct hostc *
host_findtid(tid)
	int tid;
{
	return hc_find(tid);
}


struct hostc *
host_findname(name)
	char *name;
{
	struct hostc *hp;

	for (hp = curhosts->link; hp != curhosts; hp = hp->link)
		if (!strcmp(name, hp->name))
			return hp;
	return (struct hostc *)0;
}


struct hostc *
host_next(hp)
	struct hostc *hp;
{
	hp = hp ? hp->link : curhosts->link;
	return (hp == curhosts) ? 0 : hp;
}


int
host_show()
{
	struct hostc *hp;
	int nh = 0;
	int na = 0;
	int a;
	long mask = 0;

	for (hp = 0; hp = host_next(hp); ) {
		nh++;
		a = pvm_archcode(hp->arch);
		if (!(mask & (1 << a))) {
			na++;
			mask |= (1 << a);
		}
	}
	printf("Configuration: %d host%s, %d data format%s\n",
			nh, (nh == 1 ? "" : "s"),
			na, (na == 1 ? "" : "s"));
	printf("     TID       ARCH   SPEED HOSTNAME\n");
	for (hp = 0; hp = host_next(hp); ) {
		printf("%8x %10s %7d %-24s\n",
				hp->pvmd_tid,
				hp->arch,
				hp->speed,
				hp->name);
	}
	return 0;
}