~ubuntu-branches/ubuntu/saucy/nwchem/saucy

« back to all changes in this revision

Viewing changes to src/tools/ga-5-1/armci/tcgmsg/ipcv4.0/test.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2012-02-09 20:02:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120209200241-jgk03qfsphal4ug2
Tags: 6.1-1
* New upstream release.

[ Michael Banck ]
* debian/patches/02_makefile_flags.patch: Updated.
* debian/patches/02_makefile_flags.patch: Use internal blas and lapack code.
* debian/patches/02_makefile_flags.patch: Define GCC4 for LINUX and LINUX64
  (Closes: #632611 and LP: #791308).
* debian/control (Build-Depends): Added openssh-client.
* debian/rules (USE_SCALAPACK, SCALAPACK): Removed variables (Closes:
  #654658).
* debian/rules (LIBDIR, USE_MPIF4, ARMCI_NETWORK): New variables.
* debian/TODO: New file.
* debian/control (Build-Depends): Removed libblas-dev, liblapack-dev and
  libscalapack-mpi-dev.
* debian/patches/04_show_testsuite_diff_output.patch: New patch, shows the
  diff output for failed tests.
* debian/patches/series: Adjusted.
* debian/testsuite: Optionally run all tests if "all" is passed as option.
* debian/rules: Run debian/testsuite with "all" if DEB_BUILD_OPTIONS
  contains "checkall".

[ Daniel Leidert ]
* debian/control: Used wrap-and-sort. Added Vcs-Svn and Vcs-Browser fields.
  (Priority): Moved to extra according to policy section 2.5.
  (Standards-Version): Bumped to 3.9.2.
  (Description): Fixed a typo.
* debian/watch: Added.
* debian/patches/03_hurd-i386_define_path_max.patch: Added.
  - Define MAX_PATH if not defines to fix FTBFS on hurd.
* debian/patches/series: Adjusted.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if HAVE_CONFIG_H
 
2
#   include "config.h"
 
3
#endif
 
4
 
 
5
#if HAVE_STDIO_H
 
6
#   include <stdio.h>
 
7
#endif
 
8
#if HAVE_UNISTD_H
 
9
#   include <unistd.h>
 
10
#endif
 
11
#if HAVE_MEMORY_H
 
12
#   include <memory.h>
 
13
#endif
 
14
#if HAVE_STDLIB_H
 
15
#   include <stdlib.h>
 
16
#endif
 
17
#if HAVE_MALLOC_H
 
18
#   include <malloc.h>
 
19
#endif
 
20
 
 
21
#include "evlog.h"
 
22
#include "typesf2c.h"
 
23
#include "msgtypesc.h"
 
24
#include "tcgmsg.h"
 
25
 
 
26
extern unsigned char CheckByte();
 
27
extern void Error(const char *, Integer);
 
28
 
 
29
 
 
30
/**
 
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.
 
35
 */
 
36
static void TestProbe()
 
37
{
 
38
    long type_syn = 32;
 
39
    long type_msg = 33;
 
40
    long type_ack = 34;
 
41
    long me = tcg_nodeid();
 
42
    char buf;
 
43
    long lenbuf = sizeof buf;
 
44
    long sync = 1;
 
45
 
 
46
    if (me == 0) {
 
47
        (void) printf("Probe test ... processes should sleep for 20s only\n");
 
48
        (void) printf("----------\n\n");
 
49
        (void) fflush(stdout);
 
50
    }
 
51
 
 
52
    tcg_synch(type_syn);
 
53
 
 
54
    if (me == 0) {
 
55
        long nproc = tcg_nnodes();
 
56
        long anyone = -1;
 
57
        long ngot = 0;
 
58
        long node;
 
59
 
 
60
        (void) sleep((unsigned) 20);
 
61
 
 
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);
 
66
        }
 
67
 
 
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);
 
73
                ngot++;
 
74
            }
 
75
        }
 
76
    }
 
77
    else {
 
78
        long node = 0;
 
79
        while (!tcg_probe(type_msg, node)) {
 
80
            (void) printf("    Node %ld sleeping\n", me);
 
81
            (void) fflush(stdout);
 
82
            (void) sleep((unsigned) 2);
 
83
        }
 
84
        tcg_rcv(type_msg, &buf, lenbuf, &lenbuf, node, &node, sync);
 
85
        tcg_snd(type_ack, &buf, lenbuf, node, sync);
 
86
    }
 
87
 
 
88
    tcg_synch(type_syn);
 
89
}
 
90
    
 
91
 
 
92
static void TestGlobals()
 
93
{
 
94
#define MAXLENG 256*1024
 
95
    DoublePrecision *dtest;
 
96
    long *itest;
 
97
    long len;
 
98
    long me = tcg_nodeid(), nproc = tcg_nnodes(), from=tcg_nnodes()-1;
 
99
    long itype=3+MSGINT, dtype=4+MSGDBL;
 
100
 
 
101
    if (me == 0) {
 
102
        (void) printf("Global test ... test brodcast, igop and dgop\n----------\n\n");
 
103
        (void) fflush(stdout);
 
104
    }
 
105
 
 
106
    if (!(dtest = (DoublePrecision *) malloc((unsigned) (MAXLENG*sizeof(DoublePrecision))))) {
 
107
        Error("TestGlobals: failed to allocated dtest", (long) MAXLENG);
 
108
    }
 
109
    if (!(itest = (long *) malloc((unsigned) (MAXLENG*sizeof(long))))) {
 
110
        Error("TestGlobals: failed to allocated itest", (long) MAXLENG);
 
111
    }
 
112
 
 
113
    for (len=1; len<MAXLENG; len*=2) {
 
114
        long ilen = len*sizeof(long);
 
115
        long dlen = len*sizeof(DoublePrecision);
 
116
        long i;
 
117
 
 
118
        if (me == 0) {
 
119
            printf("Test length = %ld ... ", len);
 
120
            fflush(stdout);
 
121
        }
 
122
 
 
123
        /* Test broadcast */
 
124
 
 
125
        if (me == (nproc-1)) {
 
126
            for (i=0; i<len; i++) {
 
127
                itest[i] = i;
 
128
                dtest[i] = (DoublePrecision) itest[i];
 
129
            }
 
130
        }
 
131
        else {
 
132
            for (i=0; i<len; i++) {
 
133
                itest[i] = 0;
 
134
                dtest[i] = 0.0;
 
135
            }
 
136
        }
 
137
        tcg_brdcst(itype, (void*)itest, ilen, from);
 
138
        tcg_brdcst(dtype, (void*)dtest, dlen, from);
 
139
 
 
140
        for (i=0; i<len; i++) {
 
141
            if (itest[i] != i || dtest[i] != (DoublePrecision) i) {
 
142
                Error("TestGlobal: broadcast failed", (long) i);
 
143
            }
 
144
        }
 
145
 
 
146
        if (me == 0) {
 
147
            printf("broadcast OK ...");
 
148
            fflush(stdout);
 
149
        }
 
150
 
 
151
        /* Test global sum */
 
152
 
 
153
        for (i=0; i<len; i++) {
 
154
            itest[i] = i*me;
 
155
            dtest[i] = (DoublePrecision) itest[i];
 
156
        }
 
157
 
 
158
        tcg_igop(itype, itest, len, "+");
 
159
        tcg_dgop(dtype, dtest, len, "+");
 
160
 
 
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);
 
165
            }
 
166
        }
 
167
 
 
168
        if (me == 0) {
 
169
            printf("global sums OK\n");
 
170
            fflush(stdout);
 
171
        }
 
172
    }
 
173
 
 
174
    free((char *) itest);
 
175
    free((char *) dtest);
 
176
#undef MAXLENG
 
177
}
 
178
  
 
179
 
 
180
/**
 
181
 * Everyone says hi to everyone else.
 
182
 */
 
183
static void Hello()
 
184
{
 
185
    char buf[30];
 
186
    long lenbuf = sizeof buf;
 
187
    long type=19 | MSGCHR;
 
188
    long node, kode, nodefrom, lenmes;
 
189
    long sync = 1;
 
190
 
 
191
    if (tcg_nodeid() == 0) {
 
192
        (void) printf("Hello test ... show network integrity\n----------\n\n");
 
193
        (void) fflush(stdout);
 
194
    }
 
195
 
 
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",
 
200
                               kode, tcg_nodeid());
 
201
                if (node != kode) {
 
202
                    tcg_snd(type, buf, lenbuf, kode, sync);
 
203
                }
 
204
            }
 
205
        }
 
206
        else {
 
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);
 
210
        }
 
211
    }
 
212
}
 
213
 
 
214
 
 
215
/**
 
216
 * Fill list with n random integers between lo & hi inclusively.
 
217
 */
 
218
static void RandList(long lo, long hi, long *list, long n)
 
219
{
 
220
    long i, ran;
 
221
    DoublePrecision dran;
 
222
 
 
223
    for (i=0; i<n; i++) {
 
224
        dran = tcg_drand48();
 
225
        ran = lo + (long) (dran * (DoublePrecision) (hi-lo+1));
 
226
        if (ran < lo) {
 
227
            ran = lo;
 
228
        }
 
229
        if (ran > hi) {
 
230
            ran = hi;
 
231
        }
 
232
        list[i] = ran;
 
233
    }
 
234
}
 
235
 
 
236
 
 
237
/**
 
238
 * Stress the system by passing messages between a ranomly selected
 
239
 * list of nodes
 
240
 */
 
241
void Stress()
 
242
{
 
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;
 
247
#define N_LEN 11
 
248
    static long len[N_LEN] = {0,1,2,4,8,4095,4096,4097,16367,16368,16369};
 
249
    char *buf1, *buf2;
 
250
    long n_stress, mod;
 
251
    long sync = 1;
 
252
 
 
253
    from = 0;
 
254
    lenbuf = sizeof(long);
 
255
 
 
256
    if (me == 0) {
 
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);
 
262
        }
 
263
        if ( (n_stress <= 0) || (n_stress > 100000) ) {
 
264
            n_stress = 100;
 
265
        }
 
266
    }
 
267
    type = 13 | MSGINT;
 
268
    tcg_brdcst(type, (void *) &n_stress, lenbuf, from);
 
269
    type++;
 
270
 
 
271
    lenbuf = n_stress * sizeof(long);
 
272
 
 
273
#if HAVE_MEMALIGN
 
274
    list_i = (long *) memalign(sizeof(long), (unsigned) lenbuf);
 
275
#else
 
276
    list_i = (long *) malloc((unsigned) lenbuf);
 
277
#endif
 
278
    if ( list_i == (long *) NULL ) {
 
279
        Error("Stress: failed to allocate list_i",n_stress);
 
280
    }
 
281
 
 
282
#if HAVE_MEMALIGN
 
283
    list_j = (long *) memalign(sizeof(long), (unsigned) lenbuf);
 
284
#else
 
285
    list_j = (long *) malloc((unsigned) lenbuf);
 
286
#endif
 
287
    if ( list_j == (long *) NULL ) {
 
288
        Error("Stress: failed to allocate list_j",n_stress);
 
289
    }
 
290
 
 
291
#if HAVE_MEMALIGN
 
292
    list_n = (long *) memalign(sizeof(long), (unsigned) lenbuf);
 
293
#else
 
294
    list_n = (long *) malloc((unsigned) lenbuf);
 
295
#endif
 
296
    if ( list_n  == (long *) NULL ) {
 
297
        Error("Stress: failed to allocate list_n",n_stress);
 
298
    }
 
299
 
 
300
    if ( (buf1 = malloc((unsigned) 16376)) == (char *) NULL ) {
 
301
        Error("Stress: failed to allocate buf1", (long) 16376);
 
302
    }
 
303
 
 
304
    if ( (buf2 = malloc((unsigned) 16376)) == (char *) NULL ) {
 
305
        Error("Stress: failed to allocate buf2", (long) 16376);
 
306
    }
 
307
 
 
308
    if (me == 0) { /* Make random list of node pairs and message lengths */
 
309
 
 
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]];
 
315
    }
 
316
 
 
317
    node = 0;
 
318
    tcg_brdcst(type, (void *) list_i, lenbuf, node);
 
319
    type++;
 
320
    tcg_brdcst(type, (void *) list_j, lenbuf, node);
 
321
    type++;
 
322
    tcg_brdcst(type, (void *) list_n, lenbuf, node);
 
323
    type++;
 
324
 
 
325
    type = 8;
 
326
 
 
327
    for (j=0; j<16370; j++) {
 
328
        buf1[j] = (char) (j%127);
 
329
    }
 
330
 
 
331
    j = 0;
 
332
    mod = (n_stress-1)/10 + 1;
 
333
    for (i=0; i < n_stress; i++) {
 
334
 
 
335
        from   = list_i[i];
 
336
        to     = list_j[i];
 
337
        lenbuf = list_n[i];
 
338
        type++;
 
339
 
 
340
        if ( (from < 0) || (from >= nproc) ) {
 
341
            Error("Stress: from is out of range", from);
 
342
        }
 
343
        if ( (to < 0) || (to >= nproc) ) {
 
344
            Error("Stress: to is out of range", to);
 
345
        }
 
346
 
 
347
        if (from == to) {
 
348
            continue;
 
349
        }
 
350
 
 
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);
 
355
        }
 
356
 
 
357
        j++;
 
358
 
 
359
        if (from == me) {
 
360
            tcg_snd(type, buf1, lenbuf, to, sync);
 
361
        }
 
362
        else if (to == me) {
 
363
            (void) bzero(buf2, (int) lenbuf);    /* Initialize the receive buffer */
 
364
            buf2[lenbuf] = '+';
 
365
 
 
366
            tcg_rcv(type, buf2, lenbuf, &lenmes, from, &nodefrom, sync);
 
367
 
 
368
            if (buf2[lenbuf] != '+') {
 
369
                Error("Stress: overran buffer on receive",lenbuf);
 
370
            }
 
371
            if (CheckByte((unsigned char *) buf1, lenbuf) != 
 
372
                    CheckByte((unsigned char *) buf2, lenbuf)) {
 
373
                Error("Stress: invalid checksum on receive",lenbuf);
 
374
            }
 
375
            if (lenmes != lenbuf) {
 
376
                Error("Stress: invalid message length on receive",lenbuf);
 
377
            }
 
378
        }
 
379
    }
 
380
 
 
381
    (void) free(buf2);
 
382
    (void) free(buf1);
 
383
    (void) free((char *) list_n);
 
384
    (void) free((char *) list_j);
 
385
    (void) free((char *) list_i);
 
386
#undef N_LEN
 
387
}
 
388
 
 
389
 
 
390
/** Time passing a message round a ring. */
 
391
void RingTest()
 
392
{
 
393
    long me = tcg_nodeid();
 
394
    long type = 4;
 
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;
 
401
    long max_len;
 
402
    long i;
 
403
    long sync = 1;
 
404
 
 
405
    i = 0;
 
406
    lenbuf = sizeof(long);
 
407
 
 
408
    if (me == 0) {
 
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);
 
414
        }
 
415
        if ( (max_len <= 0) || (max_len >= 4*1024*1024) ) {
 
416
            max_len = 256*1024;
 
417
        }
 
418
    }
 
419
    type = 4 | MSGINT;
 
420
    tcg_brdcst(type, (void *) &max_len, lenbuf, i);
 
421
 
 
422
    if ( (buf = malloc((unsigned) max_len)) == (char *) NULL) {
 
423
        Error("failed to allocate buf",max_len);
 
424
    }
 
425
 
 
426
    if (me == 0) {
 
427
        if ( (buf2 = malloc((unsigned) max_len)) == (char *) NULL) {
 
428
            Error("failed to allocate buf2",max_len);
 
429
        }
 
430
 
 
431
        for (i=0; i<max_len; i++) {
 
432
            buf[i] = (char) (i%127);
 
433
        }
 
434
    }
 
435
 
 
436
    type = 5;
 
437
    lenbuf = 0;
 
438
    while (lenbuf <= max_len) {
 
439
        int nloops = 10 + 1000/((lenbuf>0)?lenbuf:1);
 
440
        int loop = nloops;
 
441
        if (me == 0) {
 
442
            sum = CheckByte((unsigned char *) buf, lenbuf);
 
443
            if (lenbuf) (void) bzero(buf2, (int) lenbuf);
 
444
            start = tcg_time();
 
445
            while (loop--) {
 
446
                tcg_snd(type, buf, lenbuf, left, sync);
 
447
                tcg_rcv(type, buf2, lenbuf, &lenmes, right, &nodefrom, sync);
 
448
            }
 
449
            used = tcg_time() - start;
 
450
            sum2 = CheckByte((unsigned char *) buf2, lenbuf);
 
451
            sum2 = 0;
 
452
            if (used > 0) {
 
453
                rate = 1.0e-6 * (DoublePrecision) (tcg_nnodes() * lenbuf) / (DoublePrecision) used;
 
454
            } else {
 
455
                rate = 0.0;
 
456
            }
 
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);
 
461
        }
 
462
        else {
 
463
            while (loop--) {
 
464
                tcg_rcv(type, buf, lenbuf, &lenmes, right, &nodefrom, sync);
 
465
                tcg_snd(type, buf, lenbuf, left, sync);
 
466
            }
 
467
        }
 
468
        if (lenbuf) {
 
469
            lenbuf *= 2;
 
470
        } else {
 
471
            lenbuf = 1;
 
472
        }
 
473
        (void) fflush(stdout);
 
474
    }
 
475
 
 
476
    if (me == 0) {
 
477
        (void) free(buf2);
 
478
    }
 
479
 
 
480
    (void) free(buf);
 
481
}
 
482
 
 
483
 
 
484
/** Test receiveing a message from any node. */
 
485
void RcvAnyTest()
 
486
{
 
487
    long me = tcg_nodeid();
 
488
    long type = 337 | MSGINT;
 
489
    char buf[8];
 
490
    long i, j, node, lenbuf, lenmes, nodefrom, receiver, n_msg;
 
491
    long sync = 1;
 
492
 
 
493
    lenbuf = sizeof(long);
 
494
 
 
495
    if (me == 0) {
 
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);
 
501
        }
 
502
        if ( (receiver < 0) || (receiver >= tcg_nnodes()) ) {
 
503
            receiver = tcg_nnodes()-1;
 
504
        }
 
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);
 
509
        }
 
510
        if ( (n_msg <= 0) || (n_msg > 10) ) {
 
511
            n_msg = 5;
 
512
        }
 
513
    }
 
514
 
 
515
    node = 0;
 
516
    tcg_brdcst(type, (void *) &receiver, lenbuf, node);
 
517
    type++;
 
518
    tcg_brdcst(type, (void *) &n_msg, lenbuf, node);
 
519
    type++;
 
520
 
 
521
    lenbuf = 0;
 
522
 
 
523
    type = 321;
 
524
    for (i=0; i<n_msg; i++) {
 
525
 
 
526
        if (me == receiver) {
 
527
            for (j = 0; j<tcg_nnodes(); j++) {
 
528
                if (j !=  me) {
 
529
                    node = -1;
 
530
                    tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
 
531
                    (void) printf("RcvAnyTest: message received from %ld\n",
 
532
                                  nodefrom);
 
533
                    (void) fflush(stdout);
 
534
                }
 
535
            }
 
536
        }
 
537
        else {
 
538
            tcg_snd(type, buf, lenbuf, receiver, sync);
 
539
        }
 
540
    }
 
541
}
 
542
 
 
543
 
 
544
/** Test the load balancing mechanism. */
 
545
void NextValueTest()
 
546
{
 
547
    long nproc = tcg_nnodes();
 
548
    long me = tcg_nodeid();
 
549
    long type = 51 | MSGINT;
 
550
    long i, node, lenbuf, n_val, next;
 
551
    long ngot, ntimes;
 
552
    DoublePrecision start=0.0, used, rate;
 
553
 
 
554
    lenbuf = sizeof(long);
 
555
 
 
556
    if (me == 0) {
 
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);
 
562
        }
 
563
        if ( (n_val < 0) || (n_val >= 10000) ) {
 
564
            n_val = 100;
 
565
        }
 
566
    }
 
567
    node = 0;
 
568
    tcg_brdcst(type, (void *) &n_val, lenbuf, node);
 
569
 
 
570
    /* Loop thru a few values to visually show it is working */
 
571
 
 
572
    next = -1;
 
573
    for (i=0; i<10; i++) {
 
574
 
 
575
        if (i > next) {
 
576
            next = tcg_nxtval(nproc);
 
577
        }
 
578
 
 
579
        if (i == next) {
 
580
            (void) printf("node %ld got value %ld\n",me, i);
 
581
            (void) fflush(stdout);
 
582
        }
 
583
    }
 
584
    nproc = -nproc;
 
585
    next = tcg_nxtval(nproc);
 
586
    nproc = -nproc;
 
587
 
 
588
    /* Now time it for real .. twice*/
 
589
 
 
590
    for (ntimes=0; ntimes<2; ntimes++) {
 
591
        if (me == 0) {
 
592
            start = tcg_time();
 
593
        }
 
594
 
 
595
        next = -1;
 
596
        ngot = 0;
 
597
 
 
598
        for (i=0; i<n_val; i++) {
 
599
            if (i > next) {
 
600
                next = tcg_nxtval(nproc);
 
601
            }
 
602
            if (i == next) {
 
603
                ngot++;
 
604
            }
 
605
        }
 
606
 
 
607
        nproc = -nproc;
 
608
        next = tcg_nxtval(nproc);
 
609
        nproc = -nproc;
 
610
 
 
611
        if (me == 0) {
 
612
            used =  tcg_time() - start;
 
613
            rate = used / ngot;
 
614
            (void) printf("node 0: From %ld busy iters did %ld, used=%fs per call\n",
 
615
                          n_val, ngot, rate);
 
616
            (void) fflush(stdout);
 
617
        }
 
618
 
 
619
        type++;
 
620
        tcg_synch(type);
 
621
    }
 
622
}
 
623
 
 
624
 
 
625
void ToggleDebug()
 
626
{
 
627
    static long on = 0;
 
628
    long me = tcg_nodeid();
 
629
    long type = 666 | MSGINT;
 
630
    long lenbuf = sizeof(long);
 
631
    long from=0;
 
632
    long node;
 
633
 
 
634
    if (me == 0) {
 
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);
 
639
        }
 
640
    }
 
641
    tcg_brdcst(type, (void*) &node, lenbuf, from);
 
642
 
 
643
    if ((node < 0) || (node == me)) {
 
644
        on = (on + 1)%2;
 
645
        tcg_setdbg(on);
 
646
    }
 
647
}
 
648
 
 
649
 
 
650
int main(int argc, char **argv)
 
651
{
 
652
    long type;
 
653
    long lenbuf;
 
654
    long node, opt;
 
655
 
 
656
#if TEST_OLD_PBEGIN
 
657
    tcg_pbegin(argc, argv);
 
658
#else
 
659
    tcg_alt_pbegin(&argc, &argv);
 
660
#endif
 
661
 
 
662
    (void) printf("In process %ld\n", tcg_nodeid());
 
663
    (void) fflush(stdout);
 
664
 
 
665
    /* Read user input for action */
 
666
 
 
667
    lenbuf = sizeof(long);
 
668
    node = 0;
 
669
 
 
670
    while (1) {
 
671
 
 
672
        (void) fflush(stdout);
 
673
        if (tcg_nodeid() == 0) {
 
674
            (void) sleep(1);
 
675
        }
 
676
        type = 999;
 
677
        tcg_synch(type);
 
678
        (void) sleep(1);
 
679
 
 
680
        if (tcg_nodeid() == 0) {
 
681
again:
 
682
            (void) printf("\n\
 
683
                          0=quit\n\
 
684
                          1=Ring             5=NxtVal\n\
 
685
                          2=Stress           6=Global\n\
 
686
                          3=Hello            7=Debug\n\
 
687
                          4=RcvAny           8=Probe\n\n\
 
688
                          Enter test number : ");
 
689
 
 
690
            (void) fflush(stdout);
 
691
            if (scanf("%ld", &opt) != 1) {
 
692
                Error("test: input of option failed",(long) -1);
 
693
            }
 
694
            (void) printf("\n");
 
695
            (void) fflush(stdout);
 
696
            if ( (opt < 0) || (opt > 8) ) {
 
697
                goto again;
 
698
            }
 
699
        }
 
700
        type = 2 | MSGINT;
 
701
        tcg_brdcst(type, (void*) &opt, lenbuf, node);
 
702
 
 
703
        switch (opt) {
 
704
            case 0:
 
705
                if (tcg_nodeid() == 0) {
 
706
                    tcg_stats();
 
707
                }
 
708
                tcg_pend();
 
709
                return 0;
 
710
 
 
711
            case 1:
 
712
                RingTest();
 
713
                break;
 
714
 
 
715
            case 2:
 
716
                Stress();
 
717
                break;
 
718
 
 
719
            case 3:
 
720
                Hello();
 
721
                break;
 
722
 
 
723
            case 4:
 
724
                RcvAnyTest();
 
725
                break;
 
726
 
 
727
            case 5:
 
728
                NextValueTest();
 
729
                break;
 
730
 
 
731
            case 6:
 
732
                TestGlobals();
 
733
                break;
 
734
 
 
735
            case 7:
 
736
                ToggleDebug();
 
737
                break;
 
738
 
 
739
            case 8:
 
740
                TestProbe();
 
741
                break;
 
742
 
 
743
            default:
 
744
                Error("test: invalid option", opt);
 
745
                break;
 
746
        }
 
747
    }
 
748
}