~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/tcgmsg/tests/test3.c

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

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