File: bwtest.c

package info (click to toggle)
pvm 3.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,236 kB
  • sloc: ansic: 72,074; makefile: 1,197; fortran: 631; sh: 512; csh: 74; asm: 37
file content (315 lines) | stat: -rw-r--r-- 7,404 bytes parent folder | download | duplicates (4)
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

static char rcsid[] =
	"$Id: bwtest.c,v 1.12 2009/01/23 01:12:48 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.
 */

/* bwtest.c - bandwidth tester
 * This is yet another bandwidth tester.
 * It measures user-space to user-space times.
 *
 * The measurement is a standard ping-pong with roundtrip time measured
 * from the originating sender.
 *
 * This is a PVM test code
 */

#include <stdio.h>
#ifdef HASSTDLIB
#include <stdlib.h>
#endif

#include "pvm3.h"

#ifndef SAMPLE
#define SAMPLE  20 	/* sample rate */
#endif
#ifndef MAXSIZE
#define MAXSIZE	100000	/* must be a power of 10 */
#endif

#define VTAG 10
#define MTAG 100

#ifndef ENCODE
#define ENCODE	PvmDataInPlace
#endif

#define GETTIME(_x,_y) pvmgetclock((_x)) 

#ifndef WIN32
#include <sys/time.h>
#else
#include <winsock.h>
#endif

struct timeval tv1, tv2;
#define TIMER_CLEAR     (tv1.tv_sec = tv1.tv_usec = tv2.tv_sec = tv2.tv_usec =0)
#define TIMER_START     GETTIME(&tv1, (struct timezone*)0)
#define TIMER_STOP      GETTIME(&tv2, (struct timezone*)0)
#define TIMER_ELAPSED \
	( ( tv2.tv_usec - tv1.tv_usec ) \
		+ ( ( tv2.tv_sec - tv1.tv_sec) * 1.E6 ) )


#define GNAME "bwtest"

void pingpong();	/* where all the work is done and measured */


main(argc, argv)
int argc;
char *argv[];
{
	int mytid;
	int myinst;
	int othertid;
	int otherinst;

	if ((mytid = pvm_mytid()) < 0)
		exit(-1);

	if((myinst = pvm_joingroup(GNAME)) < 0) {
		pvm_perror("Error joining bwtest group");
		exit(-1);
	}


	printf(" %x myinst is %d \n", mytid, myinst);
	switch (myinst % 2) {
	case 0: 

		otherinst = myinst + 1;
		while ((othertid = pvm_gettid(GNAME, otherinst)) < 0)
			pvmsleep(1);

		pingpong(mytid, othertid);
		break;
	case 1:
		otherinst = myinst - 1;
		while ((othertid = pvm_gettid(GNAME, otherinst)) < 0)
			pvmsleep(1);

		pingpong(othertid, mytid);
		break;
	}

	pvm_lvgroup(GNAME);
	pvm_exit();

}
void
validate(data, size)
	double data[];
	int size;
{
	int i;
	int mytid;

	mytid = pvm_mytid();

	for (i = 0; i < size; i++)
		if ((i*i - data[i]) > 0.01) {
			printf("error: data[%d] = %g\n", i, data[i]);
			break;
		}

	if (i == size)
		printf("t%x: %d doubles received correctly\n\n\n", mytid, i);
}


/* exchange messages and measure the transit time */
void
pingpong(mastertid, slavetid)
int mastertid;
int slavetid;
{
	int ismaster;
	int mytid;
	int n;
	int size;
	int t;

	static double data[MAXSIZE];

	char str[32];

	/* test node-to-node send */

	mytid = pvm_mytid();


	ismaster = ( mytid ==  mastertid );


	if (ismaster)
	{
#ifdef PACK
		print_header(ENCODE, MAXSIZE*sizeof(double), SAMPLE);
#else
		print_header(-1, MAXSIZE*sizeof(double), SAMPLE);
#endif
	}

	printf("%x -- I am the %s \n", mytid, (ismaster ? "master" : "slave"));


	/* first validate that all doubles are sent and returned correctly */
	if (ismaster)
	{

		for (n = 0; n < MAXSIZE; n++)
			data[n] = n*n;
#ifdef PACK
		pvm_initsend(ENCODE);
		pvm_pkdouble(data, MAXSIZE, 1);
		pvm_send(slavetid, VTAG); /* send the data */
		
		pvm_recv(slavetid, VTAG); /* recv it back and validate */
		pvm_upkdouble(data, MAXSIZE, 1);
#else
		pvm_psend(slavetid, VTAG, data, MAXSIZE, PVM_DOUBLE);
		pvm_precv(slavetid, VTAG, data, MAXSIZE, PVM_DOUBLE, (int*)0, 
			(int*)0, (int*)0);
#endif
		
	}
	else
	{
#ifdef PACK
		
		pvm_recv(mastertid, VTAG);	/* recv and unpack */ 
		pvm_upkdouble(data, MAXSIZE, 1);

		pvm_initsend(ENCODE);		/* echo */
		pvm_pkdouble(data, MAXSIZE, 1);
		pvm_send(mastertid, VTAG); /* send the data */
#else
		pvm_precv(mastertid, VTAG, data, MAXSIZE, PVM_DOUBLE, (int*)0, 
			(int*)0, (int*)0);
		pvm_psend(mastertid, VTAG, data, MAXSIZE, PVM_DOUBLE);
#endif
	}

	validate(data, MAXSIZE);
	sprintf(str, "%d doubles from t%x", MAXSIZE, slavetid);
	

	/* now do the ping-pong */

	for (size = 0; size <= MAXSIZE; size = ( size ? 10*size : 1) )
	{
		TIMER_CLEAR;
		TIMER_START;
		for (n = 0; n < SAMPLE; n++) 
		{
			if (ismaster)
			{
#ifdef PACK
				pvm_initsend(ENCODE);
				pvm_pkdouble(data, size, 1);
				pvm_send(slavetid, MTAG);
				pvm_recv(slavetid, MTAG);
				pvm_upkdouble(data, size, 1);
#else
				pvm_psend(slavetid, MTAG, data, size, PVM_DOUBLE);
				pvm_precv(slavetid, MTAG, data, size, PVM_DOUBLE, 
						(int*)0, (int*)0, (int*)0);
#endif /*PACK*/
			}
			else
			{
#ifdef PACK
				pvm_recv(mastertid, MTAG);
				pvm_upkdouble(data, size, 1);
				pvm_initsend(ENCODE);
				pvm_pkdouble(data, size, 1);
				pvm_send(mastertid, MTAG);
#else
				pvm_precv(mastertid, MTAG, data, size, PVM_DOUBLE, 
						(int*)0, (int*)0, (int*)0);
				pvm_psend(mastertid, MTAG, data, size, PVM_DOUBLE);
#endif /*PACK*/
			}
		}
		if (ismaster)
		{
			TIMER_STOP;
			t = (int) TIMER_ELAPSED / SAMPLE;
			printf("Roundtrip T = %d (us)  (%.4f MB/s)  Data size: %d\n",
				t, 2.0*8.0*(float)size/(float)t, ((int)sizeof(double))*size);
		}
	}
}


int
print_header(packtype, size, niter)
int packtype;
int size;
int niter;
{
	printf("--- Simple PVM Bandwidth Test ----\n");
	printf(" Using pack option: %s \n",
		(packtype == PvmDataRaw ? "PvmDataRaw" : 
		(packtype == PvmDataInPlace ? "PvmDataInPlace" :
		(packtype == PvmDataDefault ? "PvmDataDefault" :
		(packtype == -1 ? "Psend/Precv" : "Unknown")))));
	printf(" Max data size is: %d \n", size);
	printf(" Number of iterations/sample: %d \n", niter);
	printf(" \n\n");
	printf(" Roundtrip time is measured from user-space to user-space.\n");
	if ( packtype != -1)
	{
		printf(" For packed messages this includes the combined time of: \n"); 
		printf("    inst 0: pvm_initsend() \n"); 
		printf("    inst 0: pvm_pack() \n"); 
		printf("    inst 0: pvm_send() \n"); 
		printf("    inst 1: pvm_recv() \n");
		printf("    inst 1: pvm_unpack() \n");
		printf("    inst 1: pvm_initsend() \n");
		printf("    inst 1: pvm_pack() \n");
		printf("    inst 1: pvm_send() \n");
		printf("    inst 0: pvm_recv() \n");
		printf("    inst 0: pvm_unpack() \n");
	}
	else
	{
		printf(" For pvm_psend/precv this includes the combined time of: \n"); 
		printf("    inst 0: pvm_psend() \n"); 
		printf("    inst 1: pvm_precv() \n"); 
		printf("    inst 1: pvm_psend() \n"); 
		printf("    inst 0: pvm_precv() \n");
	}
	
	printf("\n\n---------------------------------------\n");
	
	return 0;
}