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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
|
#if HAVE_CONFIG_H
# include "config.h"
#endif
/* $Header: /tmp/hpctools/ga/tcgmsg/ipcv5.0/test.c,v 1.4 2002-01-28 19:42:04 d3h325 Exp $ */
#if HAVE_STDIO_H
# include <stdio.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_MEMORY_H
# include <memory.h>
#endif
#if HAVE_STRINGS_H
# include <strings.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
#if HAVE_MALLOC_H
# include <malloc.h>
#endif
#include "evlog.h"
#include "msgtypesc.h"
#include "typesf2c.h"
#include "tcgmsg.h"
extern unsigned char CheckByte();
extern void Error(const char *, Integer);
/**
* Process 0 sleeps for 20 seconds and then sends each
* process a message. The other processes sleep for periods
* of 2 seconds and probes until it gets a message. All processes
* respond to process 0 which recieves using a wildcard probe.
*/
static void TestProbe()
{
long type_syn = 32;
long type_msg = 33;
long type_ack = 34;
long me = tcg_nodeid();
char buf;
long lenbuf = sizeof buf;
long sync = 1;
if (me == 0) {
(void) printf("Probe test ... processes should sleep for 20s only\n");
(void) printf("----------\n\n");
(void) fflush(stdout);
}
tcg_synch(type_syn);
if (me == 0) {
long nproc = tcg_nnodes();
long anyone = -1;
long ngot = 0;
long node;
(void) sleep((unsigned) 20);
for (node=1; node<nproc; node++) {
tcg_snd(type_msg, &buf, lenbuf, node, sync);
(void) printf(" Sent message to %ld\n", node);
(void) fflush(stdout);
}
while (ngot < (nproc-1))
if (tcg_probe(type_ack, anyone)) {
tcg_rcv(type_ack, &buf, lenbuf, &lenbuf, anyone, &node, sync);
(void) printf(" Got response from %ld\n", node);
(void) fflush(stdout);
ngot++;
}
}
else {
long node = 0;
while (!tcg_probe(type_msg, node)) {
(void) printf(" Node %ld sleeping\n", me);
(void) fflush(stdout);
(void) sleep((unsigned) 2);
}
tcg_rcv(type_msg, &buf, lenbuf, &lenbuf, node, &node, sync);
tcg_snd(type_ack, &buf, lenbuf, node, sync);
}
tcg_synch(type_syn);
}
static void TestGlobals()
{
#define MAXLENG 256*1024
double *dtest;
long *itest;
long len;
long me = tcg_nodeid(), nproc = tcg_nnodes(), from=0;
long itype=3+MSGINT, dtype=4+MSGDBL;
if (me == 0) {
(void) printf("Global test ... test brodcast, igop and dgop\n----------\n\n");
(void) fflush(stdout);
}
if (!(dtest = (double *) malloc((unsigned) (MAXLENG*sizeof(double)))))
Error("TestGlobals: failed to allocated dtest", (long) MAXLENG);
if (!(itest = (long *) malloc((unsigned) (MAXLENG*sizeof(long)))))
Error("TestGlobals: failed to allocated itest", (long) MAXLENG);
for (len=1; len<MAXLENG; len*=2) {
long ilen = len*sizeof(long);
long dlen = len*sizeof(double);
long i;
if (me == 0) {
printf("Test length = %ld ... ", len);
fflush(stdout);
}
/* Test broadcast */
if (me == from) {
for (i=0; i<len; i++) {
itest[i] = i;
dtest[i] = 1. * itest[i];
}
}
else {
for (i=0; i<len; i++) {
itest[i] = 0;
dtest[i] = 0.0;
}
}
tcg_brdcst(itype, (void *) itest, ilen, from);
tcg_brdcst(dtype, (void *) dtest, dlen, from);
for (i=0; i<len; i++)
if (itest[i] != i || dtest[i] != (double) i)
Error("TestGlobal: broadcast failed", (long) i);
if (me == 0) {
printf("broadcast OK ...");
fflush(stdout);
}
/* Test global sum */
for (i=0; i<len; i++) {
itest[i] = i*me;
dtest[i] = (double) itest[i];
}
tcg_igop(itype, itest, len, "+");
tcg_dgop(dtype, dtest, len, "+");
for (i=0; i<len; i++) {
long iresult = i*nproc*(nproc-1)/2;
if (itest[i] != iresult || dtest[i] != (double) iresult)
Error("TestGlobals: global sum failed", (long) i);
}
if (me == 0) {
printf("global sums OK\n");
fflush(stdout);
}
}
free((char *) itest);
free((char *) dtest);
}
/**
* Everyone says hi to everyone else
*/
static void Hello()
{
char buf[30];
long lenbuf = sizeof buf;
long type=19 | MSGCHR;
long node, kode, nodefrom, lenmes;
long sync = 1;
if (tcg_nodeid() == 0) {
(void) printf("Hello test ... show network integrity\n----------\n\n");
(void) fflush(stdout);
}
for (node = 0; node<tcg_nnodes(); node++) {
if (node == tcg_nodeid()) {
for (kode = 0; kode<tcg_nnodes(); kode++) {
(void) sprintf(buf, "Hello to %ld from %ld", kode, tcg_nodeid());
if (node != kode)
tcg_snd(type, buf, lenbuf, kode, sync);
}
}
else {
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
(void) printf("me=%ld, from=%ld: %s\n",tcg_nodeid(), node, buf);
(void) fflush(stdout);
}
}
}
/**
* Fill list with n random integers between lo & hi inclusively
*/
static void RandList(long lo, long hi, long *list, long n)
{
long i, ran;
double dran;
for (i=0; i<n; i++) {
dran = tcg_drand48();
ran = lo + (long) (dran * (double) (hi-lo+1));
if (ran < lo)
ran = lo;
if (ran > hi)
ran = hi;
list[i] = ran;
}
}
/**
* Stress the system by passing messages between a ranomly selected
* list of nodes
*/
void Stress()
{
long me = tcg_nodeid();
long nproc = tcg_nnodes();
long type, lenbuf, node, lenmes, nodefrom, i, j, from, to;
long *list_i, *list_j, *list_n;
#define N_LEN 11
static long len[N_LEN] = {0,1,2,4,8,4063,4064,4065,4072,8127,8129};
char *buf1, *buf2;
long n_stress, mod;
long sync = 1;
from = 0;
lenbuf = sizeof(long);
if (me == 0) {
(void) printf("Stress test ... randomly exchange messages\n-----------");
(void) printf("\n\nInput no. of messages: ");
(void) fflush(stdout);
if (scanf("%ld",&n_stress) != 1)
Error("Stress: error reading n_stress",(long) -1);
if ( (n_stress <= 0) || (n_stress > 100000) )
n_stress = 100;
}
type = 13 | MSGINT;
tcg_brdcst(type, (void *) &n_stress, lenbuf, from);
type++;
lenbuf = n_stress * sizeof(long);
#if HAVE_MEMALIGN
list_i = (long *) memalign(sizeof(long), (unsigned) lenbuf);
#else
list_i = (long *) malloc((unsigned) lenbuf);
#endif
if ( list_i == (long *) NULL ) {
Error("Stress: failed to allocate list_i",n_stress);
}
#if HAVE_MEMALIGN
list_j = (long *) memalign(sizeof(long), (unsigned) lenbuf);
#else
list_j = (long *) malloc((unsigned) lenbuf);
#endif
if ( list_j == (long *) NULL ) {
Error("Stress: failed to allocate list_j",n_stress);
}
#if HAVE_MEMALIGN
list_n = (long *) memalign(sizeof(long), (unsigned) lenbuf);
#else
list_n = (long *) malloc((unsigned) lenbuf);
#endif
if ( list_n == (long *) NULL ) {
Error("Stress: failed to allocate list_n",n_stress);
}
if ( (buf1 = malloc((unsigned) 16376)) == (char *) NULL )
Error("Stress: failed to allocate buf1", (long) 16376);
if ( (buf2 = malloc((unsigned) 16376)) == (char *) NULL )
Error("Stress: failed to allocate buf2", (long) 16376);
if (me == 0) { /* Make random list of node pairs and message lengths */
RandList((long) 0, (long) (tcg_nnodes()-1), list_i, n_stress);
RandList((long) 0, (long) (tcg_nnodes()-1), list_j, n_stress);
RandList((long) 0, (long) (N_LEN-1), list_n, n_stress);
for (i=0; i<n_stress; i++)
list_n[i] = len[list_n[i]];
}
node = 0;
tcg_brdcst(type, (void *) list_i, lenbuf, node);
type++;
tcg_brdcst(type, (void *) list_j, lenbuf, node);
type++;
tcg_brdcst(type, (void *) list_n, lenbuf, node);
type++;
type = 8;
for (j=0; j<16370; j++)
buf1[j] = (char) (j%127);
j = 0;
mod = (n_stress-1)/10 + 1;
for (i=0; i < n_stress; i++) {
from = list_i[i];
to = list_j[i];
lenbuf = list_n[i];
type++;
if ( (from < 0) || (from >= nproc) )
Error("Stress: from is out of range", from);
if ( (to < 0) || (to >= nproc) )
Error("Stress: to is out of range", to);
if (from == to)
continue;
if ( (me == 0) && (j%mod == 0) ) {
(void) printf("Stress: test=%ld: from=%ld, to=%ld, len=%ld\n",
i, from, to, lenbuf);
(void) fflush(stdout);
}
j++;
if (from == me)
tcg_snd(type, buf1, lenbuf, to, sync);
else if (to == me) {
(void) bzero(buf2, (int) lenbuf); /* Initialize the receive buffer */
buf2[lenbuf] = '+';
tcg_rcv(type, buf2, lenbuf, &lenmes, from, &nodefrom, sync);
if (buf2[lenbuf] != '+')
Error("Stress: overran buffer on receive",lenbuf);
if (CheckByte((unsigned char *) buf1, lenbuf) !=
CheckByte((unsigned char *) buf2, lenbuf))
Error("Stress: invalid checksum on receive",lenbuf);
if (lenmes != lenbuf)
Error("Stress: invalid message length on receive",lenbuf);
}
}
(void) free(buf2);
(void) free(buf1);
(void) free((char *) list_n);
(void) free((char *) list_j);
(void) free((char *) list_i);
}
/**
* Time passing a message round a ring
* */
void RingTest()
{
long me = tcg_nodeid();
long type = 4;
long left = (me + tcg_nnodes() - 1) % tcg_nnodes();
long right = (me + 1) % tcg_nnodes();
char *buf, *buf2;
unsigned char sum, sum2;
long lenbuf, lenmes, nodefrom;
double start, used, rate;
long max_len;
long i;
long sync = 1;
i = 0;
lenbuf = sizeof(long);
if (me == 0) {
(void) printf("Ring test ... time network performance\n---------\n\n");
(void) printf("Input maximum message size: ");
(void) fflush(stdout);
if (scanf("%ld", &max_len) != 1)
Error("RingTest: error reading max_len",(long) -1);
if ( (max_len <= 0) || (max_len >= 4*1024*1024) )
max_len = 256*1024;
}
type = 4 | MSGINT;
tcg_brdcst(type, (void *) &max_len, lenbuf, i);
if ( (buf = malloc((unsigned) max_len)) == (char *) NULL)
Error("failed to allocate buf",max_len);
if (me == 0) {
if ( (buf2 = malloc((unsigned) max_len)) == (char *) NULL)
Error("failed to allocate buf2",max_len);
for (i=0; i<max_len; i++)
buf[i] = (char) (i%127);
}
type = 5;
lenbuf = 1;
while (lenbuf <= max_len) {
int nloops = 10 + 1000/lenbuf;
int loop = nloops;
if (me == 0) {
sum = CheckByte((unsigned char *) buf, lenbuf);
(void) bzero(buf2, (int) lenbuf);
start = tcg_time();
while (loop--) {
tcg_snd(type, buf, lenbuf, left, sync);
tcg_rcv(type, buf2, lenbuf, &lenmes, right, &nodefrom, sync);
}
used = tcg_time() - start;
sum2 = CheckByte((unsigned char *) buf2, lenbuf);
if (used > 0)
rate = 1.0e-6 * (double) (tcg_nnodes() * lenbuf) / (double) used;
else
rate = 0.0;
rate = rate * nloops;
printf("len=%6ld bytes, nloop=%4d, used=%8.4f s, rate=%8.4f Mb/s (0x%x, 0x%x)\n",
lenbuf, nloops, used, rate, sum, sum2);
(void) fflush(stdout);
}
else {
while (loop--) {
tcg_rcv(type, buf, lenbuf, &lenmes, right, &nodefrom, sync);
tcg_snd(type, buf, lenbuf, left, sync);
}
}
lenbuf *= 2;
}
if (me == 0)
(void) free(buf2);
(void) free(buf);
}
/**
* Test receiveing a message from any node
*/
void RcvAnyTest()
{
long me = tcg_nodeid();
long type = 337 | MSGINT;
char buf[8];
long i, j, node, lenbuf, lenmes, nodefrom, receiver, n_msg;
long sync = 1;
lenbuf = sizeof(long);
if (me == 0) {
(void) printf("RCV any test ... check is working!\n-----------\n\n");
(void) printf("Input node to receive : ");
(void) fflush(stdout);
if (scanf("%ld", &receiver) != 1)
Error("RcvAnyTest: error reading receiver",(long) -1);
if ( (receiver < 0) || (receiver >= tcg_nnodes()) )
receiver = tcg_nnodes()-1;
(void) printf("Input number of messages : ");
(void) fflush(stdout);
if (scanf("%ld", &n_msg) != 1)
Error("RcvAnyTest: error reading n_msg",(long) -1);
if ( (n_msg <= 0) || (n_msg > 10) )
n_msg = 5;
}
node = 0;
tcg_brdcst(type, (void *) &receiver, lenbuf, node);
type++;
tcg_brdcst(type, (void *) &n_msg, lenbuf, node);
type++;
lenbuf = 0;
type = 321;
for (i=0; i<n_msg; i++) {
if (me == receiver) {
for (j = 0; j<tcg_nnodes(); j++)
if (j != me) {
node = -1;
tcg_rcv(type, buf, lenbuf, &lenmes, node, &nodefrom, sync);
(void) printf("RcvAnyTest: message received from %ld\n",
nodefrom);
(void) fflush(stdout);
}
}
else
tcg_snd(type, buf, lenbuf, receiver, sync);
}
}
/**
* Test the load balancing mechanism
*/
void NextValueTest()
{
long nproc = tcg_nnodes();
long me = tcg_nodeid();
long type = 51 | MSGINT;
long i, node, lenbuf, n_val, next;
long ngot, ntimes;
double start, used, rate;
lenbuf = sizeof(long);
if (me == 0) {
(void) printf("Next value test ... time overhead!\n---------------\n\n");
(void) printf("Input iteration count : ");
(void) fflush(stdout);
if (scanf("%ld", &n_val) != 1)
Error("NextValueTest: error reading n_val",(long) -1);
if ( (n_val < 0) || (n_val >= 10000) )
n_val = 100;
}
node = 0;
tcg_brdcst(type, (void *) &n_val, lenbuf, node);
/* Loop thru a few values to visually show it is working */
next = -1;
for (i=0; i<10; i++) {
if (i > next)
next = tcg_nxtval(nproc);
if (i == next) {
(void) printf("node %ld got value %ld\n",me, i);
(void) fflush(stdout);
}
}
nproc = -nproc;
next = tcg_nxtval(nproc);
nproc = -nproc;
/* Now time it for real .. twice*/
for (ntimes=0; ntimes<2; ntimes++) {
if (me == 0)
start = tcg_time();
next = -1;
ngot = 0;
for (i=0; i<n_val; i++) {
if (i > next)
next = tcg_nxtval(nproc);
if (i == next)
ngot++;
}
nproc = -nproc;
next = tcg_nxtval(nproc);
nproc = -nproc;
if (me == 0) {
used = tcg_time() - start;
if(ngot){
rate = used / ngot;
(void) printf("node 0: From %ld busy iters did %ld, used=%fs per call\n",
n_val, ngot, rate);
}else printf("node 0: From %ld busy iters did 0\n",n_val);
(void) fflush(stdout);
}
type++;
tcg_synch(type);
}
}
void ToggleDebug()
{
static long on = 0;
long me = tcg_nodeid();
long type = 666 | MSGINT;
long lenbuf = sizeof(long);
long from=0;
long node;
if (me == 0) {
(void) printf("\nInput node to debug (-1 = all) : ");
(void) fflush(stdout);
if (scanf("%ld", &node) != 1)
Error("ToggleDebug: error reading node",(long) -1);
}
tcg_brdcst(type, (void *) &node, lenbuf, from);
if ((node < 0) || (node == me)) {
on = (on + 1)%2;
tcg_setdbg(on);
}
}
int main(int argc, char **argv)
{
long type;
long lenbuf;
long node, opt;
tcg_alt_pbegin(&argc, &argv);
(void) printf("In process %ld\n", tcg_nodeid());
(void) fflush(stdout);
/* Read user input for action */
lenbuf = sizeof(long);
node = 0;
while (1) {
(void) fflush(stdout);
if (tcg_nodeid() == 0)
(void) sleep(1);
type = 999;
tcg_synch(type);
(void) sleep(1);
if (tcg_nodeid() == 0) {
again:
(void) printf("\n\
0=quit\n\
1=Ring 5=NxtVal\n\
2=Stress 6=Global\n\
3=Hello 7=Debug\n\
4=RcvAny 8=Probe\n\n\
Enter test number : ");
(void) fflush(stdout);
if (scanf("%ld", &opt) != 1)
Error("test: input of option failed",(long) -1);
(void) printf("\n");
(void) fflush(stdout);
if ( (opt < 0) || (opt > 8) )
goto again;
}
type = 2 | MSGINT;
tcg_brdcst(type, (void *) &opt, lenbuf, node);
switch (opt) {
case 0:
if (tcg_nodeid() == 0)
tcg_stats();
tcg_pend();
return 0;
case 1:
RingTest();
break;
case 2:
Stress();
break;
case 3:
Hello();
break;
case 4:
RcvAnyTest();
break;
case 5:
NextValueTest();
break;
case 6:
TestGlobals();
break;
case 7:
ToggleDebug();
break;
case 8:
TestProbe();
break;
default:
Error("test: invalid option", opt);
break;
}
}
return 0;
}
|