23
#include "msgtypesc.h"
26
extern unsigned char CheckByte();
27
extern void Error(const char *, Integer);
31
* Process 0 sleeps for 20 seconds and then sends each
32
* process a message. The other processes sleep for periods
33
* of 2 seconds and probes until it gets a message. All processes
34
* respond to process 0 which recieves using a wildcard probe.
36
static void TestProbe()
41
long me = tcg_nodeid();
43
long lenbuf = sizeof buf;
47
(void) printf("Probe test ... processes should sleep for 20s only\n");
48
(void) printf("----------\n\n");
49
(void) fflush(stdout);
55
long nproc = tcg_nnodes();
60
(void) sleep((unsigned) 20);
62
for (node=1; node<nproc; node++) {
63
tcg_snd(type_msg, &buf, lenbuf, node, sync);
64
(void) printf(" Sent message to %ld\n", node);
65
(void) fflush(stdout);
68
while (ngot < (nproc-1)) {
69
if (tcg_probe(type_ack, anyone)) {
70
tcg_rcv(type_ack, &buf, lenbuf, &lenbuf, anyone, &node, sync);
71
(void) printf(" Got response from %ld\n", node);
72
(void) fflush(stdout);
79
while (!tcg_probe(type_msg, node)) {
80
(void) printf(" Node %ld sleeping\n", me);
81
(void) fflush(stdout);
82
(void) sleep((unsigned) 2);
84
tcg_rcv(type_msg, &buf, lenbuf, &lenbuf, node, &node, sync);
85
tcg_snd(type_ack, &buf, lenbuf, node, sync);
92
static void TestGlobals()
94
#define MAXLENG 256*1024
95
DoublePrecision *dtest;
98
long me = tcg_nodeid(), nproc = tcg_nnodes(), from=tcg_nnodes()-1;
99
long itype=3+MSGINT, dtype=4+MSGDBL;
102
(void) printf("Global test ... test brodcast, igop and dgop\n----------\n\n");
103
(void) fflush(stdout);
106
if (!(dtest = (DoublePrecision *) malloc((unsigned) (MAXLENG*sizeof(DoublePrecision))))) {
107
Error("TestGlobals: failed to allocated dtest", (long) MAXLENG);
109
if (!(itest = (long *) malloc((unsigned) (MAXLENG*sizeof(long))))) {
110
Error("TestGlobals: failed to allocated itest", (long) MAXLENG);
113
for (len=1; len<MAXLENG; len*=2) {
114
long ilen = len*sizeof(long);
115
long dlen = len*sizeof(DoublePrecision);
119
printf("Test length = %ld ... ", len);
125
if (me == (nproc-1)) {
126
for (i=0; i<len; i++) {
128
dtest[i] = (DoublePrecision) itest[i];
132
for (i=0; i<len; i++) {
137
tcg_brdcst(itype, (void*)itest, ilen, from);
138
tcg_brdcst(dtype, (void*)dtest, dlen, from);
140
for (i=0; i<len; i++) {
141
if (itest[i] != i || dtest[i] != (DoublePrecision) i) {
142
Error("TestGlobal: broadcast failed", (long) i);
147
printf("broadcast OK ...");
151
/* Test global sum */
153
for (i=0; i<len; i++) {
155
dtest[i] = (DoublePrecision) itest[i];
158
tcg_igop(itype, itest, len, "+");
159
tcg_dgop(dtype, dtest, len, "+");
161
for (i=0; i<len; i++) {
162
long iresult = i*nproc*(nproc-1)/2;
163
if (itest[i] != iresult || dtest[i] != (DoublePrecision) iresult) {
164
Error("TestGlobals: global sum failed", (long) i);
169
printf("global sums OK\n");
174
free((char *) itest);
175
free((char *) dtest);
181
* Everyone says hi to everyone else.
186
long lenbuf = sizeof buf;
187
long type=19 | MSGCHR;
188
long node, kode, nodefrom, lenmes;
191
if (tcg_nodeid() == 0) {
192
(void) printf("Hello test ... show network integrity\n----------\n\n");
193
(void) fflush(stdout);
196
for (node = 0; node<tcg_nnodes(); node++) {
197
if (node == tcg_nodeid()) {
198
for (kode = 0; kode<tcg_nnodes(); kode++) {
199
(void) sprintf(buf, "Hello to %ld from %ld",
202
tcg_snd(type, buf, lenbuf, kode, sync);
207
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
208
(void) printf("me=%ld, from=%ld: %s\n", tcg_nodeid(), node, buf);
209
(void) fflush(stdout);
216
* Fill list with n random integers between lo & hi inclusively.
218
static void RandList(long lo, long hi, long *list, long n)
221
DoublePrecision dran;
223
for (i=0; i<n; i++) {
224
dran = tcg_drand48();
225
ran = lo + (long) (dran * (DoublePrecision) (hi-lo+1));
238
* Stress the system by passing messages between a ranomly selected
243
long me = tcg_nodeid();
244
long nproc = tcg_nnodes();
245
long type, lenbuf, node, lenmes, nodefrom, i, j, from, to;
246
long *list_i, *list_j, *list_n;
248
static long len[N_LEN] = {0,1,2,4,8,4095,4096,4097,16367,16368,16369};
254
lenbuf = sizeof(long);
257
(void) printf("Stress test ... randomly exchange messages\n-----------");
258
(void) printf("\n\nInput no. of messages: ");
259
(void) fflush(stdout);
260
if (scanf("%ld",&n_stress) != 1) {
261
Error("Stress: error reading n_stress",(long) -1);
263
if ( (n_stress <= 0) || (n_stress > 100000) ) {
268
tcg_brdcst(type, (void *) &n_stress, lenbuf, from);
271
lenbuf = n_stress * sizeof(long);
274
list_i = (long *) memalign(sizeof(long), (unsigned) lenbuf);
276
list_i = (long *) malloc((unsigned) lenbuf);
278
if ( list_i == (long *) NULL ) {
279
Error("Stress: failed to allocate list_i",n_stress);
283
list_j = (long *) memalign(sizeof(long), (unsigned) lenbuf);
285
list_j = (long *) malloc((unsigned) lenbuf);
287
if ( list_j == (long *) NULL ) {
288
Error("Stress: failed to allocate list_j",n_stress);
292
list_n = (long *) memalign(sizeof(long), (unsigned) lenbuf);
294
list_n = (long *) malloc((unsigned) lenbuf);
296
if ( list_n == (long *) NULL ) {
297
Error("Stress: failed to allocate list_n",n_stress);
300
if ( (buf1 = malloc((unsigned) 16376)) == (char *) NULL ) {
301
Error("Stress: failed to allocate buf1", (long) 16376);
304
if ( (buf2 = malloc((unsigned) 16376)) == (char *) NULL ) {
305
Error("Stress: failed to allocate buf2", (long) 16376);
308
if (me == 0) { /* Make random list of node pairs and message lengths */
310
RandList((long) 0, (long) (tcg_nnodes()-1), list_i, n_stress);
311
RandList((long) 0, (long) (tcg_nnodes()-1), list_j, n_stress);
312
RandList((long) 0, (long) (N_LEN-1), list_n, n_stress);
313
for (i=0; i<n_stress; i++)
314
list_n[i] = len[list_n[i]];
318
tcg_brdcst(type, (void *) list_i, lenbuf, node);
320
tcg_brdcst(type, (void *) list_j, lenbuf, node);
322
tcg_brdcst(type, (void *) list_n, lenbuf, node);
327
for (j=0; j<16370; j++) {
328
buf1[j] = (char) (j%127);
332
mod = (n_stress-1)/10 + 1;
333
for (i=0; i < n_stress; i++) {
340
if ( (from < 0) || (from >= nproc) ) {
341
Error("Stress: from is out of range", from);
343
if ( (to < 0) || (to >= nproc) ) {
344
Error("Stress: to is out of range", to);
351
if ( (me == 0) && (j%mod == 0) ) {
352
(void) printf("Stress: test=%ld: from=%ld, to=%ld, len=%ld\n",
353
i, from, to, lenbuf);
354
(void) fflush(stdout);
360
tcg_snd(type, buf1, lenbuf, to, sync);
363
(void) bzero(buf2, (int) lenbuf); /* Initialize the receive buffer */
366
tcg_rcv(type, buf2, lenbuf, &lenmes, from, &nodefrom, sync);
368
if (buf2[lenbuf] != '+') {
369
Error("Stress: overran buffer on receive",lenbuf);
371
if (CheckByte((unsigned char *) buf1, lenbuf) !=
372
CheckByte((unsigned char *) buf2, lenbuf)) {
373
Error("Stress: invalid checksum on receive",lenbuf);
375
if (lenmes != lenbuf) {
376
Error("Stress: invalid message length on receive",lenbuf);
383
(void) free((char *) list_n);
384
(void) free((char *) list_j);
385
(void) free((char *) list_i);
390
/** Time passing a message round a ring. */
393
long me = tcg_nodeid();
395
long left = (me + tcg_nnodes() - 1) % tcg_nnodes();
396
long right = (me + 1) % tcg_nnodes();
397
char *buf, *buf2=NULL;
398
unsigned char sum, sum2;
399
long lenbuf, lenmes, nodefrom;
400
DoublePrecision start, used, rate;
406
lenbuf = sizeof(long);
409
(void) printf("Ring test ... time network performance\n---------\n\n");
410
(void) printf("Input maximum message size: ");
411
(void) fflush(stdout);
412
if (scanf("%ld", &max_len) != 1) {
413
Error("RingTest: error reading max_len",(long) -1);
415
if ( (max_len <= 0) || (max_len >= 4*1024*1024) ) {
420
tcg_brdcst(type, (void *) &max_len, lenbuf, i);
422
if ( (buf = malloc((unsigned) max_len)) == (char *) NULL) {
423
Error("failed to allocate buf",max_len);
427
if ( (buf2 = malloc((unsigned) max_len)) == (char *) NULL) {
428
Error("failed to allocate buf2",max_len);
431
for (i=0; i<max_len; i++) {
432
buf[i] = (char) (i%127);
438
while (lenbuf <= max_len) {
439
int nloops = 10 + 1000/((lenbuf>0)?lenbuf:1);
442
sum = CheckByte((unsigned char *) buf, lenbuf);
443
if (lenbuf) (void) bzero(buf2, (int) lenbuf);
446
tcg_snd(type, buf, lenbuf, left, sync);
447
tcg_rcv(type, buf2, lenbuf, &lenmes, right, &nodefrom, sync);
449
used = tcg_time() - start;
450
sum2 = CheckByte((unsigned char *) buf2, lenbuf);
453
rate = 1.0e-6 * (DoublePrecision) (tcg_nnodes() * lenbuf) / (DoublePrecision) used;
457
rate = rate * nloops;
458
printf("len=%6ld bytes, nloop=%4d, used=%8.4f s, rate=%8.4f Mb/s (0x%x, 0x%x)\n",
459
lenbuf, nloops, used, rate, sum, sum2);
460
(void) fflush(stdout);
464
tcg_rcv(type, buf, lenbuf, &lenmes, right, &nodefrom, sync);
465
tcg_snd(type, buf, lenbuf, left, sync);
473
(void) fflush(stdout);
484
/** Test receiveing a message from any node. */
487
long me = tcg_nodeid();
488
long type = 337 | MSGINT;
490
long i, j, node, lenbuf, lenmes, nodefrom, receiver, n_msg;
493
lenbuf = sizeof(long);
496
(void) printf("RCV any test ... check is working!\n-----------\n\n");
497
(void) printf("Input node to receive : ");
498
(void) fflush(stdout);
499
if (scanf("%ld", &receiver) != 1) {
500
Error("RcvAnyTest: error reading receiver",(long) -1);
502
if ( (receiver < 0) || (receiver >= tcg_nnodes()) ) {
503
receiver = tcg_nnodes()-1;
505
(void) printf("Input number of messages : ");
506
(void) fflush(stdout);
507
if (scanf("%ld", &n_msg) != 1) {
508
Error("RcvAnyTest: error reading n_msg",(long) -1);
510
if ( (n_msg <= 0) || (n_msg > 10) ) {
516
tcg_brdcst(type, (void *) &receiver, lenbuf, node);
518
tcg_brdcst(type, (void *) &n_msg, lenbuf, node);
524
for (i=0; i<n_msg; i++) {
526
if (me == receiver) {
527
for (j = 0; j<tcg_nnodes(); j++) {
530
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
531
(void) printf("RcvAnyTest: message received from %ld\n",
533
(void) fflush(stdout);
538
tcg_snd(type, buf, lenbuf, receiver, sync);
544
/** Test the load balancing mechanism. */
547
long nproc = tcg_nnodes();
548
long me = tcg_nodeid();
549
long type = 51 | MSGINT;
550
long i, node, lenbuf, n_val, next;
552
DoublePrecision start=0.0, used, rate;
554
lenbuf = sizeof(long);
557
(void) printf("Next value test ... time overhead!\n---------------\n\n");
558
(void) printf("Input iteration count : ");
559
(void) fflush(stdout);
560
if (scanf("%ld", &n_val) != 1) {
561
Error("NextValueTest: error reading n_val",(long) -1);
563
if ( (n_val < 0) || (n_val >= 10000) ) {
568
tcg_brdcst(type, (void *) &n_val, lenbuf, node);
570
/* Loop thru a few values to visually show it is working */
573
for (i=0; i<10; i++) {
576
next = tcg_nxtval(nproc);
580
(void) printf("node %ld got value %ld\n",me, i);
581
(void) fflush(stdout);
585
next = tcg_nxtval(nproc);
588
/* Now time it for real .. twice*/
590
for (ntimes=0; ntimes<2; ntimes++) {
598
for (i=0; i<n_val; i++) {
600
next = tcg_nxtval(nproc);
608
next = tcg_nxtval(nproc);
612
used = tcg_time() - start;
614
(void) printf("node 0: From %ld busy iters did %ld, used=%fs per call\n",
616
(void) fflush(stdout);
628
long me = tcg_nodeid();
629
long type = 666 | MSGINT;
630
long lenbuf = sizeof(long);
635
(void) printf("\nInput node to debug (-1 = all) : ");
636
(void) fflush(stdout);
637
if (scanf("%ld", &node) != 1) {
638
Error("ToggleDebug: error reading node",(long) -1);
641
tcg_brdcst(type, (void*) &node, lenbuf, from);
643
if ((node < 0) || (node == me)) {
650
int main(int argc, char **argv)
657
tcg_pbegin(argc, argv);
659
tcg_alt_pbegin(&argc, &argv);
662
(void) printf("In process %ld\n", tcg_nodeid());
663
(void) fflush(stdout);
665
/* Read user input for action */
667
lenbuf = sizeof(long);
672
(void) fflush(stdout);
673
if (tcg_nodeid() == 0) {
680
if (tcg_nodeid() == 0) {
687
4=RcvAny 8=Probe\n\n\
688
Enter test number : ");
690
(void) fflush(stdout);
691
if (scanf("%ld", &opt) != 1) {
692
Error("test: input of option failed",(long) -1);
695
(void) fflush(stdout);
696
if ( (opt < 0) || (opt > 8) ) {
701
tcg_brdcst(type, (void*) &opt, lenbuf, node);
705
if (tcg_nodeid() == 0) {
744
Error("test: invalid option", opt);