21
# define sleep(x) Sleep(1000*(x))
24
#define MAXLENG 256*1024
28
#include <msgtypesc.h>
31
extern unsigned char CheckByte();
32
extern void Error(const char *, Integer);
36
* Process 0 sleeps for 20 seconds and then sends each
37
* process a message. The other processes sleep for periods
38
* of 2 seconds and probes until it gets a message. All processes
39
* respond to process 0 which recieves using a wildcard probe.
41
static void TestProbe()
46
long me = tcg_nodeid();
48
long lenbuf = sizeof buf;
52
(void) printf("Probe test ... processes should sleep for 20s only\n");
53
(void) printf("----------\n\n");
54
(void) fflush(stdout);
60
long nproc = tcg_nnodes();
65
(void) sleep((unsigned) 20);
67
for (node=1; node<nproc; node++) {
68
tcg_snd(type_msg, &buf, lenbuf, node, sync);
69
(void) printf(" Sent message to %ld\n", node);
70
(void) fflush(stdout);
73
while (ngot < (nproc-1)) {
74
if (tcg_probe(type_ack, anyone)) {
75
tcg_rcv(type_ack, &buf, lenbuf, &lenbuf, anyone, &node, sync);
76
(void) printf(" Got response from %ld\n", node);
77
(void) fflush(stdout);
84
while (!tcg_probe(type_msg, node)) {
85
(void) printf(" Node %ld sleeping\n", me);
86
(void) fflush(stdout);
87
(void) sleep((unsigned) 2);
89
tcg_rcv(type_msg, &buf, lenbuf, &lenbuf, node, &node, sync);
90
tcg_snd(type_ack, &buf, lenbuf, node, sync);
97
static void TestGlobals()
102
long me = tcg_nodeid(), nproc = tcg_nnodes(), from=tcg_nnodes()-1;
103
long itype=3+MSGINT, dtype=4+MSGDBL;
106
(void) printf("Global test ... test brodcast, igop and dgop\n----------\n\n");
107
(void) fflush(stdout);
110
if (!(dtest = (double *) malloc((unsigned) (MAXLENG*sizeof(double))))) {
111
Error("TestGlobals: failed to allocated dtest", (long) MAXLENG);
113
if (!(itest = (long *) malloc((unsigned) (MAXLENG*sizeof(long))))) {
114
Error("TestGlobals: failed to allocated itest", (long) MAXLENG);
117
for (len=1; len<MAXLENG; len*=2) {
118
long ilen = len*sizeof(long);
119
long dlen = len*sizeof(double);
123
printf("Test length = %ld ... ", len);
129
if (me == (nproc-1)) {
130
for (i=0; i<len; i++) {
132
dtest[i] = (double) itest[i];
136
for (i=0; i<len; i++) {
141
tcg_brdcst(itype, (void *) itest, ilen, from);
142
tcg_brdcst(dtype, (void *) dtest, dlen, from);
144
for (i=0; i<len; i++)
145
if (itest[i] != i || dtest[i] != (double) i)
146
Error("TestGlobal: broadcast failed", (long) i);
149
printf("broadcast OK ...");
153
/* Test global sum */
155
for (i=0; i<len; i++) {
157
dtest[i] = (double) itest[i];
160
tcg_igop(itype, itest, len, "+");
161
tcg_dgop(dtype, dtest, len, "+");
163
for (i=0; i<len; i++) {
164
long iresult = i*nproc*(nproc-1)/2;
165
if (itest[i] != iresult || dtest[i] != (double) iresult){
166
printf(" dt %f it %ld ir %ld \n",
167
dtest[i],itest[i],iresult);
168
Error("TestGlobals: global sum failed", (long) i);
173
printf("global sums OK\n");
178
free((char *) itest);
179
free((char *) dtest);
184
* Everyone says hi to everyone else
189
long lenbuf = sizeof buf;
190
long type=19 | MSGCHR;
191
long node, kode, nodefrom, lenmes;
194
if (tcg_nodeid() == 0) {
195
(void) printf("Hello test ... show network integrity\n----------\n\n");
196
(void) fflush(stdout);
199
for (node = 0; node<tcg_nnodes(); node++) {
200
if (node == tcg_nodeid()) {
201
for (kode = 0; kode<tcg_nnodes(); kode++) {
202
(void) sprintf(buf, "Hello to %ld from %ld",
205
tcg_snd(type, buf, lenbuf, kode, sync);
210
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
211
(void) printf("me=%ld, from=%ld: %s\n",
212
tcg_nodeid(), node, buf);
213
(void) fflush(stdout);
221
* Fill list with n random integers between lo & hi inclusively
223
static void RandList(long lo, long hi, long *list, long n)
228
for (i=0; i<n; i++) {
229
dran = tcg_drand48();
230
ran = lo + (long) (dran * (double) (hi-lo+1));
243
* Stress the system by passing messages between a ranomly selected
248
long me = tcg_nodeid();
249
long nproc = tcg_nnodes();
250
long type, lenbuf, node, lenmes, nodefrom, i, j, from, to;
251
long *list_i, *list_j, *list_n;
252
static long len[N_LEN] = {0,1,2,4,8,4095,4096,4097,16367,16368,16369};
258
lenbuf = sizeof(long);
261
(void) printf("Stress test ... randomly exchange messages\n---------");
262
(void) printf("\n\nInput no. of messages: ");
263
(void) fflush(stdout);
264
if (scanf("%ld",&n_stress) != 1) {
265
Error("Stress: error reading n_stress",(long) -1);
267
if ( (n_stress <= 0) || (n_stress > 100000) ) {
272
tcg_brdcst(type, (void *) &n_stress, lenbuf, from);
275
lenbuf = n_stress * sizeof(long);
278
list_i = (long *) memalign(sizeof(long), (unsigned) lenbuf);
280
list_i = (long *) malloc((unsigned) lenbuf);
282
if ( list_i == (long *) NULL ) {
283
Error("Stress: failed to allocate list_i",n_stress);
287
list_j = (long *) memalign(sizeof(long), (unsigned) lenbuf);
289
list_j = (long *) malloc((unsigned) lenbuf);
291
if ( list_j == (long *) NULL ) {
292
Error("Stress: failed to allocate list_j",n_stress);
296
list_n = (long *) memalign(sizeof(long), (unsigned) lenbuf);
298
list_n = (long *) malloc((unsigned) lenbuf);
300
if ( list_n == (long *) NULL ) {
301
Error("Stress: failed to allocate list_n",n_stress);
304
if ( (buf1 = malloc((unsigned) 16376)) == (char *) NULL ) {
305
Error("Stress: failed to allocate buf1", (long) 16376);
308
if ( (buf2 = malloc((unsigned) 16376)) == (char *) NULL ) {
309
Error("Stress: failed to allocate buf2", (long) 16376);
312
if (me == 0) { /* Make random list of node pairs and message lengths */
313
RandList((long) 0, (long) (tcg_nnodes()-1), list_i, n_stress);
314
RandList((long) 0, (long) (tcg_nnodes()-1), list_j, n_stress);
315
RandList((long) 0, (long) (N_LEN-1), list_n, n_stress);
316
for (i=0; i<n_stress; i++)
317
list_n[i] = len[list_n[i]];
321
tcg_brdcst(type, (void *) list_i, lenbuf, node);
323
tcg_brdcst(type, (void *) list_j, lenbuf, node);
325
tcg_brdcst(type, (void *) list_n, lenbuf, node);
330
for (j=0; j<16370; j++) {
331
buf1[j] = (char) (j%127);
335
mod = (n_stress-1)/10 + 1;
336
for (i=0; i < n_stress; i++) {
342
if ( (from < 0) || (from >= nproc) ) {
343
Error("Stress: from is out of range", from);
345
if ( (to < 0) || (to >= nproc) ) {
346
Error("Stress: to is out of range", to);
353
if ( (me == 0) && (j%mod == 0) ) {
354
(void) printf("Stress: test=%ld: from=%ld, to=%ld, len=%ld\n",
355
i, from, to, lenbuf);
356
(void) fflush(stdout);
362
tcg_snd(type, buf1, lenbuf, to, sync);
365
(void) bzero(buf2, (int) lenbuf); /* Initialize the rcv buffer */
368
tcg_rcv(type, buf2, lenbuf, &lenmes, from, &nodefrom, sync);
370
if (buf2[lenbuf] != '+') {
371
Error("Stress: overran buffer on receive",lenbuf);
373
if (CheckByte((unsigned char *) buf1, lenbuf) !=
374
CheckByte((unsigned char *) buf2, lenbuf)) {
375
Error("Stress: invalid checksum on receive",lenbuf);
377
if (lenmes != lenbuf) {
378
Error("Stress: invalid message length on receive",lenbuf);
385
(void) free((char *) list_n);
386
(void) free((char *) list_j);
387
(void) free((char *) list_i);
391
/** Time passing a message round a ring */
394
long me = tcg_nodeid();
396
long left = (me + tcg_nnodes() - 1) % tcg_nnodes();
397
long right = (me + 1) % tcg_nnodes();
398
char *buf=NULL, *buf2=NULL;
399
unsigned char sum, sum2;
400
long lenbuf, lenmes, nodefrom;
401
double start, used, rate;
407
lenbuf = sizeof(long);
410
(void) printf("Ring test ... time network performance\n---------\n\n");
411
(void) printf("Input maximum message size: ");
412
(void) fflush(stdout);
413
if (scanf("%ld", &max_len) != 1) {
414
Error("RingTest: error reading max_len",(long) -1);
416
if ( (max_len <= 0) || (max_len >= 4*1024*1024) ) {
421
tcg_brdcst(type, (void *) &max_len, lenbuf, i);
423
if ( (buf = malloc((unsigned) max_len)) == (char *) NULL) {
424
Error("failed to allocate buf",max_len);
428
if ( (buf2 = malloc((unsigned) max_len)) == (char *) NULL) {
429
Error("failed to allocate buf2",max_len);
432
for (i=0; i<max_len; i++) {
433
buf[i] = (char) (i%127);
439
while (lenbuf <= max_len) {
440
int nloops = 10 + 1000/lenbuf;
443
sum = CheckByte((unsigned char *) buf, lenbuf);
444
(void) bzero(buf2, (int) lenbuf);
447
tcg_snd(type, buf, lenbuf, left, sync);
448
tcg_rcv(type, buf2, lenbuf, &lenmes, right, &nodefrom, sync);
450
used = tcg_time() - start;
451
sum2 = CheckByte((unsigned char *) buf2, lenbuf);
453
rate = 1.0e-6 * (double) (tcg_nnodes() * lenbuf) / (double) used;
458
rate = rate * nloops;
459
printf("len=%ld bytes, nloop=%d, used=%8.4f s, rate=%8.4f Mb/s (0x%x, 0x%x)\n",
460
lenbuf, nloops, used, rate, sum, sum2);
461
(void) fflush(stdout);
465
tcg_rcv(type, buf, lenbuf, &lenmes, right, &nodefrom, sync);
466
tcg_snd(type, buf, lenbuf, left, sync);
480
/** Test receiveing a message from any node */
483
long me = tcg_nodeid();
484
long type = 337 | MSGINT;
486
long i, j, node, lenbuf, lenmes, nodefrom, receiver, n_msg;
489
lenbuf = sizeof(long);
492
(void) printf("RCV any test ... check is working!\n-----------\n\n");
493
(void) printf("Input node to receive : ");
494
(void) fflush(stdout);
495
if (scanf("%ld", &receiver) != 1) {
496
Error("RcvAnyTest: error reading receiver",(long) -1);
498
if ( (receiver < 0) || (receiver >= tcg_nnodes()) ) {
499
receiver = tcg_nnodes()-1;
501
(void) printf("Input number of messages : ");
502
(void) fflush(stdout);
503
if (scanf("%ld", &n_msg) != 1) {
504
Error("RcvAnyTest: error reading n_msg",(long) -1);
506
if ( (n_msg <= 0) || (n_msg > 10) ) {
512
tcg_brdcst(type, (void *) &receiver, lenbuf, node);
514
tcg_brdcst(type, (void *) &n_msg, lenbuf, node);
520
for (i=0; i<n_msg; i++) {
521
if (me == receiver) {
522
for (j = 0; j<tcg_nnodes(); j++) {
525
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
526
(void) printf("RcvAnyTest: message received from %ld\n",
528
(void) fflush(stdout);
533
tcg_snd(type, buf, lenbuf, receiver, sync);
539
/** Test the load balancing mechanism */
542
long nproc = tcg_nnodes();
543
long me = tcg_nodeid();
544
long type = 51 | MSGINT;
545
long i, node, lenbuf, n_val, next;
547
double start=0, used=0, rate=0;
549
lenbuf = sizeof(long);
552
(void) printf("Next value test ... time overhead!\n---------------\n\n");
553
(void) printf("Input iteration count : ");
554
(void) fflush(stdout);
555
if (scanf("%ld", &n_val) != 1) {
556
Error("NextValueTest: error reading n_val",(long) -1);
558
if ( (n_val < 0) || (n_val >= 10000) ) {
563
tcg_brdcst(type, (void *) &n_val, lenbuf, node);
565
/* Loop thru a few values to visually show it is working */
568
for (i=0; i<10; i++) {
570
next = tcg_nxtval(nproc);
574
(void) printf("node %ld got value %ld\n", me, i);
575
(void) fflush(stdout);
579
next = tcg_nxtval(nproc);
582
/* Now time it for real .. twice*/
584
for (ntimes=0; ntimes<2; ntimes++) {
592
for (i=0; i<n_val; i++) {
594
next = tcg_nxtval(nproc);
602
next = tcg_nxtval(nproc);
606
used = tcg_time() - start;
607
rate = ngot ? used / ngot: 0.;
608
printf("node 0: From %ld busy iters did %ld, used=%lfs per call\n",
622
long me = tcg_nodeid();
623
long type = 666 | MSGINT;
624
long lenbuf = sizeof(long);
629
(void) printf("\nInput node to debug (-1 = all) : ");
630
(void) fflush(stdout);
631
if (scanf("%ld", &node) != 1) {
632
Error("ToggleDebug: error reading node",(long) -1);
635
tcg_brdcst(type, (void *) &node, lenbuf, from);
637
if ((node < 0) || (node == me)) {
644
int main(int argc, char **argv)
650
tcg_alt_pbegin(&argc, &argv);
652
(void) printf("In process %ld\n", tcg_nodeid());
653
(void) fflush(stdout);
655
/* Read user input for action */
657
lenbuf = sizeof(long);
662
(void) fflush(stdout);
663
if (tcg_nodeid() == 0) {
670
if (tcg_nodeid() == 0) {
677
4=RcvAny 8=Probe\n\n\
678
Enter test number : ");
680
(void) fflush(stdout);
681
if (scanf("%ld", &opt) != 1) {
682
Error("test: input of option failed",(long) -1);
685
(void) fflush(stdout);
686
if ( (opt < 0) || (opt > 8) ) {
691
tcg_brdcst(type, (void *) &opt, lenbuf, node);
695
if (tcg_nodeid() == 0) {
734
Error("test: invalid option", opt);