File: xmpi.c

package info (click to toggle)
xmpi 2.2-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,232 kB
  • ctags: 1,656
  • sloc: ansic: 13,738; sh: 1,799; makefile: 233
file content (545 lines) | stat: -rw-r--r-- 10,670 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
/*
 * Copyright 1998-1999, University of Notre Dame.
 * Authors: Brian W. Barrett, Arun F. Rodrigues, Jeffrey M. Squyres,
 * 	 and Andrew Lumsdaine
 *
 * This file is part of XMPI
 *
 * You should have received a copy of the License Agreement for XMPI 
 * along with the software; see the file LICENSE.  If not, contact 
 * Office of Research, University of Notre Dame, Notre Dame, IN 46556.
 *
 * Permission to modify the code and to distribute modified code is
 * granted, provided the text of this NOTICE is retained, a notice that
 * the code was modified is included with the above COPYRIGHT NOTICE and
 * with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
 * file is distributed with the modified code.
 *
 * LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
 * By way of example, but not limitation, Licensor MAKES NO
 * REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
 * PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
 * OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
 * OR OTHER RIGHTS.
 *
 * Additional copyrights may follow.

 *
 *	$Id: xmpi.c,v 1.3 1999/11/08 06:20:21 bbarrett Exp $
 *
 *	Function:	- MPI GUI
 *			- Motif
 */

#define _NO_PROTO

#include <X11/StringDefs.h>
#include <Xm/MessageB.h>
#include <Xm/Form.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "xmpi.h"

/*
 * global functions
 */
void			xmpi_bail();
void			xmpi_busy();
void			xmpi_cleanup();
void			xmpi_unbusy();
void			xmpi_setsize();
void			xmpi_setminmax();
Widget			xmpi_wmshell();

/*
 * external functions
 */
extern void 		_XEditResCheckMessages();
extern void		_lam_atexit();
extern char *		_path_find();

/*
 * local functions
 */
static void		help();

/*
 * global variables
 */
XtAppContext		app;			/* application context */
AppData			app_res;		/* application resources */
Widget			xmpi_shell;		/* toplevel shell */
char			xmpi_info[XMPI_PATHMAX]; /* information string */

/*
 * local variables
 */
static Widget		xmpitop;		/* toplevel manager */
static int		hinitmin = -1;		/* ini. drawable min height */
static int		winitmin = -1;		/* init. drawable min width */
static int		hinitmax = -1;		/* init. drawable max height */
static int		winitmax = -1;		/* init. drawable max width */
static int		hsetup = -1;		/* height setup overhead */
static int		wsetup = -1;		/* width setup overhead */

static XrmOptionDescRec	cmdoptions[] = {
	{"-h", "*help", XrmoptionNoArg, "TRUE"},
};

static XtResource	resources[] = {
	{
		XtNhelp,
		XtCHelp,
		XmRBoolean,
		sizeof(Boolean),
		XtOffset(AppDataPtr, ap_help),
		XmRImmediate,
		(caddr_t) False
	},
	{
		XtNrankFont,
		XtCRankFont,
		XmRFontStruct,
		sizeof(XFontStruct *),
		XtOffset(AppDataPtr, ap_rankfont),
		XmRString,
		XMPI_RANKFONT
	},
	{
		XtNmsgFont,
		XtCMsgFont,
		XmRFontStruct,
		sizeof(XFontStruct *),
		XtOffset(AppDataPtr, ap_msgfont),
		XmRString,
		XMPI_MSGFONT
	},
	{
		XtNlcomCol,
		XtCLcomCol,
		XtRPixel,
		sizeof(Pixel),
		XtOffset(AppDataPtr, ap_lcomcol),
		XmRString,
		XMPI_LCOMCOLOUR
	},
	{
		XtNrcomCol,
		XtCRcomCol,
		XtRPixel,
		sizeof(Pixel),
		XtOffset(AppDataPtr, ap_rcomcol),
		XmRString,
		XMPI_RCOMCOLOUR
	},
	{
		XtNbandCol,
		XtCBandCol,
		XtRPixel,
		sizeof(Pixel),
		XtOffset(AppDataPtr, ap_bandcol),
		XmRString,
		XMPI_BANDCOLOUR
	},
	{
		XtNbandDash,
		XtCBandDash,
		XtRBoolean,
		sizeof(Boolean),
		XtOffset(AppDataPtr, ap_banddash),
		XmRImmediate,
		(caddr_t) XMPI_BANDDASH
	},
	{
		XtNbandWidth,
		XtCBandWidth,
		XtRInt,
		sizeof(int),
		XtOffset(AppDataPtr, ap_bandwidth),
		XmRImmediate,
		(caddr_t) XMPI_BANDWIDTH
	},
	{
		XtNhelpCmd,
		XtCHelpCmd,
		XtRString,
		sizeof(String),
		XtOffset(AppDataPtr, ap_helpcmd),
		XmRString,
		XMPI_HELPCMD
	},
	{
		XtNinfoLabel,
		XtCInfoLabel,
		XtRString,
		sizeof(String),
		XtOffset(AppDataPtr, ap_infolbl),
		XmRString,
		XMPI_INFOLABEL
	},
};

static XtActionsRec	actions[] = {
	{
		"xmpi_run_delete",
		(XtActionProc) xmpi_run_delete
	}
};

/*
 * fallback resources
 */
static String fallbacks[] = {
	"*Title: XMPI",
	"*IconName: XMPI",
	"*multiClickTime: 500",
	"*background: gray",
	"*fontList: -*-helvetica-bold-r-normal--*-120-*-*-*-*-*-*",
	"*fo_func.fontList: -*-helvetica-bold-o-normal--*-120-*-*-*-*-*-*",
	"*dt_dtype.fontList: -*-helvetica-medium-r-normal--*-100-*-*-*-*-*-*",
	"*ctl_bar.topShadowColor: lightslateblue",
	"*ctl_bar.bottomShadowColor: darkslateblue",
	"*ctl_bar.background: slateblue",
	"*ctl_bar.foreground: white",
	"*banner.background: slateblue",
	"*banner.foreground: white",
	"*trace_banner.background: white",
	"*trace_banner.foreground: slateblue",
	"*app_list.visibleItemCount: 8",
	"*aschema_list.visibleItemCount: 20",
	"*aschema_text.columns: 24",
	"*prog_mgr*columns: 16",
	"*label_frame.XmLabel.background: #D3B5B5",
	"*XmToggleButtonGadget.selectColor: red",
	"*XmToggleButton.selectColor: red",
	"*trace_selector.dirMask: *.lamtr",
	"*popup_help.background: white",
	"*popup_help.foreground: black",
/*
 * Workaround for problem with HP-VUE.
 */
#ifdef HPUX
	"*view_draw.background: gray",
	"*view_draw.foreground: black",
	"*trace_draw.background: gray",
	"*trace_draw.foreground: black",
	"*kiviat_draw.background: gray",
	"*kiviat_draw.foreground: black",
	"*matrix_draw.background: gray",
	"*matrix_draw.foreground: black",
#endif
	NULL
};

/*
 *	main
 */
int
main(argc, argv)

int			argc;
char			*argv[];

{
	Widget		w1, w2;
	char		*info = 0;
	int		i;

	xmpi_shell = XtVaAppInitialize(&app, "XMPI", cmdoptions,
			XtNumber(cmdoptions), &argc, argv, fallbacks, NULL);
/*
 * Enabling this lets "editres" work with XMPI.  Might have to link with
 * -lXmu as well.
 */
#ifdef DEBUG
	XtAddEventHandler(xmpi_shell, (EventMask) 0, True,
			_XEditResCheckMessages, NULL);
#endif
/*
 * Read in and check resources.
 */
	XtGetApplicationResources(xmpi_shell,
			&app_res, resources, XtNumber(resources), NULL, 0);

	if (app_res.ap_help) {
		help();
		exit(0);
	}

	if (app_res.ap_bandwidth < 0) {
		app_res.ap_bandwidth = XMPI_BANDWIDTH;
	}
/*
 * Look for information string.
 */
	for (i = 1; i < argc; ++i) {

		if ((*argv[i] == '-') || (info)) {
			fprintf(stderr,
				"xmpi (usage): xmpi [-h] [<info>]\n");
			exit(EUSAGE);
		} else {
			info = argv[i];
		}
	}

	if (info) {
		strncpy(xmpi_info, info, XMPI_PATHMAX);
	} else {
		xmpi_info[0] = 0;
	}

	XtAppAddActions(app, actions, XtNumber(actions));

	xmpitop = XtVaCreateWidget("top_mgr",
		xmFormWidgetClass, xmpi_shell,
		XmNmarginHeight, 2,
		XmNmarginWidth, 2,
		NULL);
/*
 * Create main application view.
 */
	w1 = xmpi_ctl_build(xmpitop);
	XtVaSetValues(w1,
		XmNtopAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_FORM,
		NULL);

	w2 = xmpi_vw_create(xmpitop);
	XtVaSetValues(w2,
		XmNtopAttachment, XmATTACH_WIDGET,
		XmNtopWidget, w1,
		XmNbottomAttachment, XmATTACH_FORM,
		XmNleftAttachment, XmATTACH_FORM,
		XmNrightAttachment, XmATTACH_FORM,
		NULL);

	XtManageChild(xmpitop);
	XSetIOErrorHandler((XIOErrorHandler) xmpi_bail);
	xmpi_atexit(xmpi_cleanup);
	XtRealizeWidget(xmpi_shell);

	if (xmpi_sys_init(info)) {
		perror("xmpi: system specific initialization");
		exit(errno);
	}

	xmpi_setminmax(winitmin, hinitmin, winitmax, hinitmax);

	XtAppMainLoop(app);
	return(0);
}

/*
 *	xmpi_cleanup
 *
 *	Function:	- calls cleanup routines from all modules
 */
void
xmpi_cleanup()

{
	xmpi_run_cleanup();
	xmpi_tr_cleanup();
	xmpi_sys_finalize();
}

/*
 *	xmpi_bail
 *
 *	Function:	- exits gracefully with 0 status
 */
void
xmpi_bail()

{
	xmpi_cleanup();
	_exit(0);
}

/*
 *	xmpi_busy
 *
 *	Function:	- make all windows in XMPI app. have busy cursors
 */
void
xmpi_busy()

{
	xmpi_busy_widget(xmpi_shell);
	xmpi_aschema_busy();
	xmpi_run_busy();
	xmpi_fo_busy();
	xmpi_kv_busy();
	xmpi_dt_busy();
	xmpi_tr_busy();
	xmpi_options_busy();
}

/*
 *	xmpi_unbusy
 *
 *	Function:	- make all windows in XMPI app. have normal cursors
 */
void
xmpi_unbusy()

{
	xmpi_unbusy_widget(xmpi_shell);
	xmpi_aschema_unbusy();
	xmpi_run_unbusy();
	xmpi_fo_unbusy();
	xmpi_kv_unbusy();
	xmpi_dt_unbusy();
	xmpi_tr_unbusy();
	xmpi_options_unbusy();
}

/*
 *        help
 *
 *        Function:     - prints helpful information on this command
 */
static void
help()

{
    printf("\nSynopsis:\txmpi [<options>] [<info>]\n");
    printf("\nDescription:\tRun and monitor MPI programs.\n");
    printf("\nOptions:        -h\tPrint this help message.\n");
}

/*
 *	xmpi_wmshell
 *
 *	Function:	- returns the first WMShell ancestor
 *	Accepts:	- widget
 *	Returns:	- window manager shell
 */
Widget
xmpi_wmshell(w)

Widget			w;

{
	while ((w) && ( ! XtIsWMShell(w))) {
		w = XtParent(w);
	}

	return(w);
}

/*
 *	xmpi_setminmax
 *
 *	Function:	- set min/max toplevel shell size
 *	Accepts:	- min width
 *			- min height
 *			- max width
 *			- max height
 */
void
xmpi_setminmax(wmin, hmin, wmax, hmax)

int			wmin;
int			hmin;
int			wmax;
int			hmax;

{
	Dimension	height;
	Dimension	width;
/*
 * The first time around, just store the drawable sizes.
 */
	if (winitmin < 0) {
		winitmin = wmin;
		hinitmin = hmin;
		winitmax = wmax;
		hinitmax = hmax;
	}
	else {
/*
 * The second time around, compute the width/height window overhead.
 */
		if (wsetup < 0) {
			XtVaGetValues(xmpi_shell, XmNwidth, &width,
					XmNheight, &height, NULL);

			wsetup = width - wmax;
			hsetup = height - hmax;
		}
/*
 * Set the size boundaries.
 */
		XtVaSetValues(xmpi_shell,
			XmNminWidth, wsetup + wmin,
			XmNminHeight, hsetup + hmin,
			XmNmaxWidth, wsetup + wmax,
			XmNmaxHeight, hsetup + hmax,
			NULL);
	}
}

/*
 *	xmpi_setsize
 *
 *	Function:	- set toplevel shell size
 *	Accepts:	- width
 *			- height
 */
void
xmpi_setsize(width, height)

int			width;
int			height;

{
	XResizeWindow(XtDisplay(xmpi_shell), XtWindow(xmpi_shell),
		(unsigned) wsetup + width, (unsigned) hsetup + height);
}

/*
 *	xmpi_seticon
 *
 *	Function:	- set the tool icon
 *	Accepts:	- icon pixmap
 */
void
xmpi_seticon(iconpix)

Pixmap			iconpix;

{
	Window		win;
	Window		root;
	Display		*disp;
	int		x, y;
	unsigned int	width, height, bwidth, depth;

	disp = XtDisplay(xmpi_shell);
	XtVaGetValues(xmpi_shell, XmNiconWindow, &win, NULL);

	if (!win) {
		if (! XGetGeometry(disp, iconpix, &root, &x, &y,
				&width, &height, &bwidth, &depth) ||
			!(win = XCreateSimpleWindow(disp, root, 0, 0,
				width, height, (unsigned int) 0,
				CopyFromParent, CopyFromParent))) {

			XtVaSetValues(xmpi_shell, XmNiconPixmap, iconpix,
					NULL);
			return;
		}

		XtVaSetValues(xmpi_shell, XmNiconWindow, win, NULL);
	}

	XSetWindowBackgroundPixmap(disp, win, iconpix);
	XClearWindow(disp, win);
}