File: xmpi_dtprint.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 (477 lines) | stat: -rw-r--r-- 9,527 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
/*
 * 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_dtprint.c,v 1.2 1999/11/08 06:20:24 bbarrett Exp $
 * 
 *	Function:	- print MPI datatype
 */

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

#include "lam.h"
#include "mpitrace.h"
#include "xmpi.h"

/*
 * constants and macros
 */
#define DISP(f, x)	((f) ? ((x) & 0xFFFF) : (x))

/*
 * global functions
 */
void			xmpi_dtypeprint();

/*
 * local functions
 */
static void		indent();
static void		print_basic();
static void		print_datatype();
static void		print_contig();
static void		print_hvector();
static void		print_hindexed();
static void		print_struct();

/*
 * local variables
 */
static int		colcount;		/* print column count */
static int		nlifconst;		/* newline if contructor */
static char		fmtbuf[80];		/* formatting buffer */
static char		*prefix;		/* prefix for each line */
static char		*obuf;			/* output buffer or NULL */
static int		identchar;		/* # chars per indent level */

/*
 * basic datatypes
 */
static char		*dtbasic[] = {
				"MPI_CONTIG", "MPI_VECTOR", "MPI_HVECTOR",
				"MPI_INDEX", "MPI_HINDEX", "MPI_STRUCT",
				"MPI_BYTE", "MPI_CHAR", "MPI_UNSIGNED_CHAR", 
				"MPI_SHORT", "MPI_UNSIGNED_SHORT", "MPI_INT",
				"MPI_UNSIGNED", "MPI_LOGICAL", "MPI_LONG",
				"MPI_UNSIGNED_LONG", "MPI_FLOAT","MPI_DOUBLE",
				"MPI_COMPLEX", "MPI_UB", "MPI_LB",
				"MPI_PACKED", "MPI_2INT", "MPI_2FLOAT",
				"MPI_2DOUBLE", "MPI_FLOAT_INT",
				"MPI_DOUBLE_INT", "MPI_LONG_INT",
				"MPI_SHORT_INT", "MPI_LONG_DOUBLE", 
				"MPI_LONG_DOUBLE_INT", "MPI_INTEGER",
				"MPI_CHARACTER", "MPI_REAL", 
				"MPI_DOUBLE_PRECISION",  "MPI_DOUBLE_COMPLEX",
				"MPI_2INTEGER", "MPI_2REAL",
				"MPI_2DOUBLE_PRECISION", "MPI_LONG_LONG_INT",
				"MPI_INTEGER1", "MPI_INTEGER2", "MPI_INTEGER4",
				"MPI_INTEGER8", "MPI_REAL4", "MPI_REAL8",
				"MPI_REAL16", 
			};

/*
 *	xmpi_dtypeprint
 *
 *	Function:	- print datatype trace
 *	Accepts:	- datatype index
 *			- trace datatype buffer (may be NULL if basic datatype)
 *			- number of chars to indent by
 *			- string prefix for each output line
 *			- output buffer (NULL means output to stdout)
 */
void
xmpi_dtypeprint(dtype, buf, indent, pfix, outbuf)

int4			dtype;
char			*buf;
int4			indent;			
char			*pfix;
char			*outbuf;

{
	struct trdtype	*p;			/* datatype trace */

	identchar = indent;
	prefix = pfix;
	obuf = outbuf;
/*
 * Recursively (depth-first) print datatype if trace buffer is non-NULL.
 */
	if (buf) {
		p = (struct trdtype *) buf;
		p++;
		colcount = 0;
		nlifconst = 0;
		if (obuf) *obuf = '\0';

		print_datatype(&p, 0);
	}
/*
 * Check for illegal datatype.
 */
	else if (dtype < 0) {
		if (obuf) {
			sprintf(obuf, "%sinvalid datatype: %d", prefix, dtype);
		} else {
			printf("%sinvalid datatype: %d\n", prefix, dtype);
		}
	}
/*
 * Handle basic datatypes.
 */
	else {
		if (obuf) {
			strcpy(obuf, prefix);
			strcat(obuf, dtbasic[dtype]);
		} else {
			printf("%s%s\n", prefix, dtbasic[dtype]);
		}
	}
}

/*
 *	print_datatype
 *
 *	Function:	- print current datatype
 *			- recursive function
 *	Accepts:	- trace record (inout)
 *			- nesting level
 */
static void
print_datatype(dtrbuf, level)

struct trdtype		**dtrbuf;
int			level;

{
	int		format;			/* datatype format */

	format = (*dtrbuf)->trd_dtype;

	switch(format) {

	case XMPI_BYTE:
	case XMPI_CHAR:
	case XMPI_UCHAR:
	case XMPI_SHORT:
	case XMPI_USHORT:
	case XMPI_INT:
	case XMPI_UINT:
	case XMPI_LOGICAL:
	case XMPI_LONG:
	case XMPI_ULONG:
	case XMPI_FLOAT:
	case XMPI_DOUBLE:
	case XMPI_COMPLEX:
	case XMPI_UB:
	case XMPI_LB:
	case XMPI_PACKED:
	case XMPI_2INT:
	case XMPI_2FLOAT:
	case XMPI_2DOUBLE:
	case XMPI_FLOAT_INT:
	case XMPI_DOUBLE_INT:
	case XMPI_LONG_INT:
	case XMPI_SHORT_INT:
	case XMPI_LONG_DOUBLE:
	case XMPI_LONG_DOUBLE_INT:
	case XMPI_INTEGER:
	case XMPI_CHARACTER:
	case XMPI_REAL:
	case XMPI_DOUBLE_PRECISION:
	case XMPI_DOUBLE_COMPLEX:
	case XMPI_2INTEGER:
	case XMPI_2REAL:
	case XMPI_2DOUBLE_PRECISION:
	case XMPI_LONG_LONG_INT:
	case XMPI_INTEGER1:
	case XMPI_INTEGER2:
	case XMPI_INTEGER4:
	case XMPI_INTEGER8:
	case XMPI_REAL4:
	case XMPI_REAL8:
	case XMPI_REAL16:
		print_basic(format, dtrbuf, level);
		break;

	case XMPI_CONTIG:
		print_contig(dtrbuf, level);
		break;

	case XMPI_VECTOR:
		print_hvector(format, dtrbuf, level, 1);
		break;

	case XMPI_HVECTOR:
		print_hvector(format, dtrbuf, level, 0);
		break;

	case XMPI_INDEXED:
		print_hindexed(format, dtrbuf, level, 1);
		break;

	case XMPI_HINDEXED:
		print_hindexed(format, dtrbuf, level, 0);
		break;

	case XMPI_STRUCT:
		print_struct(dtrbuf, level);
		break;

	default:
		break;
	}
}

/*
 *	print_basic
 *
 *	Function:	- print basic datatype record
 *	Accepts:	- datatype label
 *			- trace record (inout)
 *			- nesting level
 */
static void
print_basic(dtype, dtrace, nlev)

int			dtype;
struct trdtype		**dtrace;
int			nlev;

{
	nlifconst = 0;
	indent(nlev);
	if (obuf) {
		sprintf(fmtbuf, "%s\n", dtbasic[dtype]);
		strcat(obuf, fmtbuf);
	}
	else {
		printf("%s\n", dtbasic[dtype]);
	}
	colcount = 0;
	++(*dtrace);
}

/*
 *	print_contig
 *
 *	Function:	- print contiguous datatype record
 *	Accepts:	- trace record (inout)
 *			- nesting level
 */
static void
print_contig(dtrace, nlev)

struct trdtype		**dtrace;
int			nlev;

{
	indent(nlev);

	sprintf(fmtbuf, "%s (%d)", dtbasic[XMPI_CONTIG], (*dtrace)->trd_count);

	if (obuf) strcat(obuf, fmtbuf);
	else printf("%s", fmtbuf);

	colcount += strlen(fmtbuf);
	nlifconst = 1;

	++(*dtrace);

	print_datatype(dtrace, nlev + 1);
}

/*
 *	print_hvector
 *
 *	Function:	- print vector or hvector datatype record
 *	Accepts:	- datatype label
 *			- trace record (inout)
 *			- nesting level
 *			- vector flag
 */
static void
print_hvector(dtype, dtrace, nlev, fl_vec)

int			dtype;
struct trdtype		**dtrace;
int			nlev;
int			fl_vec;

{
	indent(nlev);

	sprintf(fmtbuf, "%s (%d x %d, %d)", dtbasic[dtype],
			(*dtrace)->trd_count, (*dtrace + 1)->trd_length,
			DISP(fl_vec, (*dtrace + 1)->trd_stride));

	if (obuf) strcat(obuf, fmtbuf);
	else printf("%s", fmtbuf);

	colcount += strlen(fmtbuf);
	nlifconst = 1;

	*dtrace += 2;

	print_datatype(dtrace, nlev + 1);
}

/*
 *	print_hindexed
 *
 *	Function:	- print indexed or hindexed datatype record
 *	Accepts:	- datatype label
 *			- trace record (inout)
 *			- nesting level
 *			- indexed flag
 */
static void
print_hindexed(dtype, dtrace, nlev, fl_idx)

int			dtype;
struct trdtype		**dtrace;
int			nlev;
int			fl_idx;

{
	int		i;			/* favourite index */
	int		count;			/* datatype count */

	indent(nlev);

	count = (*dtrace)->trd_count;
	++(*dtrace);

	sprintf(fmtbuf, "%s (%d)", dtbasic[dtype], count);
	
	if (obuf) strcat(obuf, fmtbuf);
	else printf("%s", fmtbuf);

	colcount += strlen(fmtbuf);

	for (i = 0; i < count; ++i) {
		sprintf(fmtbuf, " (%d, %d)", (*dtrace)->trd_length,
				DISP(fl_idx, (*dtrace)->trd_disp));

		if (obuf) strcat(obuf, fmtbuf);
		else printf("%s", fmtbuf);

		colcount += strlen(fmtbuf);
		++(*dtrace);
	}

	nlifconst = 1;

	print_datatype(dtrace, nlev + 1);
}

/*
 *	print_struct
 *
 *	Function:	- print struct datatype record
 *	Accepts:	- trace record (inout)
 *			- nesting level
 */
static void
print_struct(dtrace, nlev)

struct trdtype		**dtrace;
int			nlev;

{
	int		i;			/* favourite index */
	int		count;			/* datatype count */
 
	indent(nlev);

	count = (*dtrace)->trd_count;
	++(*dtrace);

	sprintf(fmtbuf, "%s (%d)\n", dtbasic[XMPI_STRUCT], count);

	if (obuf) strcat(obuf, fmtbuf);
	else printf("%s", fmtbuf);

	colcount = 0;
	nlifconst = 0;

	for (i = 0; i < count; ++i) {

		indent(nlev + 1);

		sprintf(fmtbuf, "(%d, %d)",
				(*dtrace)->trd_length, (*dtrace)->trd_disp);

		if (obuf) strcat(obuf, fmtbuf);
		else printf("%s", fmtbuf);

		colcount += strlen(fmtbuf);
		++(*dtrace);

		print_datatype(dtrace, nlev + 2);
	}
}

/*
 *	indent
 *
 *	Function:	- indent line according to level
 *	Accepts:	- indentation level
 */
static void
indent(lev)

int			lev;

{
	lev *= identchar;

	if (nlifconst) {
		if (obuf) strcat(obuf, "\n");
		else printf("\n");

		nlifconst = 0;
		colcount = 0;
	}

	if (obuf) {
		if (colcount == 0) strcat(obuf, prefix);
		if (colcount < lev) {
			for (; colcount < lev; ++colcount) strcat(obuf, " ");
		} else if (colcount > 0) {
			strcat(obuf, " ");
		}
	} else {
		if (colcount == 0) printf("%s", prefix);
		if (colcount < lev) {
			for (; colcount < lev; ++colcount) printf(" ");
		} else if (colcount > 0) {
			printf(" ");
		}
	}
}