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 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029
|
#if HAVE_CONFIG_H
# include "config.h"
#endif
/* $Id: test2.c,v 1.1.4.1 2007-05-29 19:36:23 manoj Exp $ */
#if HAVE_STDIO_H
# include <stdio.h>
#endif
#if HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if HAVE_STRING_H
# include <string.h>
#endif
#if HAVE_ASSERT_H
# include <assert.h>
#endif
#if HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#if HAVE_UNISTD_H
# include <unistd.h>
#elif HAVE_WINDOWS_H
# include <windows.h>
# define sleep(x) Sleep(1000*(x))
#endif
/*#define ARMCI_INT -99 */
/*#define ARMCI_LONG -101 */
/*#define ARMCI_FLOAT -306 */
/*#define ARMCI_DOUBLE -307 */
#define FLOAT_EPS ((float) 1.0 / 4096)
#define DOUBLE_EPS ((double) 1.0 / 16384)
#include "armci.h"
#include "message.h"
#define DIM1 5
#define DIM2 3
#ifdef __sun
/* Solaris has shared memory shortages in the default system configuration */
# define DIM3 6
# define DIM4 5
# define DIM5 4
#elif defined(__alpha__)
# define DIM3 8
# define DIM4 5
# define DIM5 6
#else
# define DIM3 8
# define DIM4 9
# define DIM5 7
#endif
#define DIM6 3
#define DIM7 2
#define OFF 1
#define EDIM1 (DIM1+OFF)
#define EDIM2 (DIM2+OFF)
#define EDIM3 (DIM3+OFF)
#define EDIM4 (DIM4+OFF)
#define EDIM5 (DIM5+OFF)
#define EDIM6 (DIM6+OFF)
#define EDIM7 (DIM7+OFF)
#define DIMS 4
#define MAXDIMS 7
#define MAX_DIM_VAL 50
#define LOOP 200
#define BASE 100.
#define MAXPROC 1024
#define TIMES 100
# define ELEMS 200
typedef struct {
float real;
float imag;
} cmpl_t;
typedef struct {
double real;
double imag;
} dcmpl_t;
/***************************** macros ************************/
#define COPY(src, dst, bytes) memcpy((dst),(src),(bytes))
#define ARMCI_MAX(a,b) (((a) >= (b)) ? (a) : (b))
#define ARMCI_MIN(a,b) (((a) <= (b)) ? (a) : (b))
#define ARMCI_ABS(a) (((a) <0) ? -(a) : (a))
/***************************** global data *******************/
int me, nproc;
void *work[MAXPROC]; /* work array for propagating addresses */
void create_array(void *a[], int elem_size, int ndim, int dims[])
{
int bytes = elem_size, i, rc;
assert(ndim <= MAXDIMS);
for (i = 0; i < ndim; i++) {
bytes *= dims[i];
}
rc = ARMCI_Malloc(a, bytes);
assert(rc == 0);
assert(a[me]);
}
void destroy_array(void *ptr[])
{
int check;
ARMCI_Barrier();
check = !ARMCI_Free(ptr[me]);
assert(check);
}
int loA[MAXDIMS], hiA[MAXDIMS];
int dimsA[MAXDIMS] = {DIM1, DIM2, DIM3, DIM4, DIM5, DIM6, DIM7};
int loB[MAXDIMS], hiB[MAXDIMS];
int dimsB[MAXDIMS] = {EDIM1, EDIM2, EDIM3, EDIM4, EDIM5, EDIM6, EDIM7};
int count[MAXDIMS];
int strideA[MAXDIMS], strideB[MAXDIMS];
int loC[MAXDIMS], hiC[MAXDIMS];
int idx[MAXDIMS] = {0, 0, 0, 0, 0, 0, 0};
void test_brdcst(int datatype)
{
void *a[6];
int len[6] = {1, 10, 100, 1000, 10000, 100000};
int datatype_size = 0;
int i, j;
switch (datatype) {
case ARMCI_INT:
datatype_size = sizeof(int);
for (i = 0; i < 6; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < 6; i++)
if (me == 0)
for (j = 0; j < len[i]; j++) {
((int *) a[i])[j] = (int) j;
}
else {
memset(a[i], 0x0, len[i] * datatype_size);
}
break;
case ARMCI_LONG:
datatype_size = sizeof(long);
for (i = 0; i < 6; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < 6; i++)
if (me == 0)
for (j = 0; j < len[i]; j++) {
((long *) a[i])[j] = (long) j;
}
else {
memset(a[i], 0x0, len[i] * datatype_size);
}
break;
case ARMCI_FLOAT:
datatype_size = sizeof(float);
for (i = 0; i < 6; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < 6; i++)
if (me == 0)
for (j = 0; j < len[i]; j++) {
((float *) a[i])[j] = (float) j;
}
else {
memset(a[i], 0x0, len[i] * datatype_size);
}
break;
case ARMCI_DOUBLE:
datatype_size = sizeof(double);
for (i = 0; i < 6; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < 6; i++)
if (me == 0)
for (j = 0; j < len[i]; j++) {
((double *) a[i])[j] = (double) j;
}
else {
memset(a[i], 0x0, len[i] * datatype_size);
}
break;
default:
break;
}
for (i = 0; i < 6; i++) {
armci_msg_brdcst(a[i], len[i] * datatype_size, 0);
}
switch (datatype) {
case ARMCI_INT:
for (i = 0; i < 6; i++)
for (j = 0; j < len[i]; j++)
if (((int *) a[i])[j] != (int) j) {
printf("ERROR a[%d][%d] = %d != %d\n", i, j, ((int *) a[i])[j], (int) j);
ARMCI_Error("armci_brdcst failed (int)\n", 0);
}
break;
case ARMCI_LONG:
for (i = 0; i < 6; i++)
for (j = 0; j < len[i]; j++)
if (((long *) a[i])[j] != (long) j) {
printf("ERROR a[%d][%d] = %ld != %ld\n", i, j, ((long *) a[i])[j], (long) j);
ARMCI_Error("armci_brdcst failed (long)\n", 0);
}
break;
case ARMCI_FLOAT:
for (i = 0; i < 6; i++)
for (j = 0; j < len[i]; j++)
if (((float *) a[i])[j] != (float) j) {
printf("ERROR a[%d][%d] = %f != %f\n", i, j, ((float *) a[i])[j], (float) j);
ARMCI_Error("armci_brdcst failed (float)\n", 0);
}
break;
case ARMCI_DOUBLE:
for (i = 0; i < 6; i++)
for (j = 0; j < len[i]; j++)
if (((double *) a[i])[j] != (double) j) {
printf("ERROR a[%d][%d] = %f != %f\n", i, j, ((double *) a[i])[j], (double) j);
ARMCI_Error("armci_brdcst failed (double)\n", 0);
}
break;
default:
break;
}
for (i = 0; i < 6; i++) {
free(a[i]);
}
}
void test_gop2_or_reduce(const int datatype, char *op, const int reduce_test)
{
void *a[6];
int len[6] = {1, 10, 100, 1000, 10000, 100000};
int len_length = 3;
int datatype_size = 0;
int i, j;
char *test_type;
int verbose = 0;
if (reduce_test == 0) {
test_type = "gop2";
}
else {
test_type = "reduce";
}
switch (datatype) {
case ARMCI_INT:
datatype_size = sizeof(int);
for (i = 0; i < len_length; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < len_length; i++)
for (j = 0; j < len[i]; j++) {
((int *) a[i])[j] = (int)(me + j) * (((me + j) % 2 == 0) ? 1 : -1);
}
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("testing %s %s message size = %d op = %s\n", test_type, "ARMCI_INT", len[i], op);
}
if (reduce_test == 0) {
armci_msg_igop(a[i], len[i], op);
}
else {
armci_msg_reduce(a[i], len[i], op, datatype);
}
}
if (me == 0 || reduce_test == 0)
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("checking %s %s message size = %d op = %s\n", test_type, "ARMCI_INT", len[i], op);
}
for (j = 0; j < len[i]; j++)
if (strncmp(op, "+", 1) == 0) {
int compare = 0;
if (nproc % 2 == 0) {
if (j % 2 == 0) {
compare = -nproc / 2;
}
else {
compare = nproc / 2;
}
}
else {
if (j % 2 == 0) {
compare = j + nproc / 2;
}
else {
compare = -(j + nproc / 2);
}
}
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "*", 1) == 0) {
int compare = 1;
int k = 0;
for (k = 0; k < nproc; k++) {
compare *= (k + j) * (((k + j) % 2 == 0) ? 1 : -1);
}
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "min", 3) == 0) {
int compare = -(j + nproc - 1);
if (compare % 2 == 0 && nproc > 1) {
compare = -(j + nproc - 2);
}
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "max", 3) == 0) {
int compare = j + nproc - 1;
if (compare % 2 != 0 && nproc > 1) {
compare = j + nproc - 2;
}
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmax", 6) == 0) {
int compare = j + nproc - 1;
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmin", 6) == 0) {
int compare = j;
if (((int *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %d != %d\n", test_type, "ARMCI_INT", op, i, j, ((int *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "or", 2) == 0) {
}
}
break;
case ARMCI_LONG:
datatype_size = sizeof(long);
for (i = 0; i < len_length; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < len_length; i++)
for (j = 0; j < len[i]; j++) {
((long *) a[i])[j] = (long)(me + j) * (((me + j) % 2 == 0) ? 1 : -1);
}
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("testing %s %s message size = %d op = %s\n", test_type, "ARMCI_LONG", len[i], op);
}
if (reduce_test == 0) {
armci_msg_lgop(a[i], len[i], op);
}
else {
armci_msg_reduce(a[i], len[i], op, datatype);
}
}
if (me == 0 || reduce_test == 0)
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("checking %s %s message size = %d op = %s\n", test_type, "ARMCI_LONG", len[i], op);
}
for (j = 0; j < len[i]; j++)
if (strncmp(op, "+", 1) == 0) {
int compare = 0;
if (nproc % 2 == 0) {
if (j % 2 == 0) {
compare = -nproc / 2;
}
else {
compare = nproc / 2;
}
}
else {
if (j % 2 == 0) {
compare = j + nproc / 2;
}
else {
compare = -(j + nproc / 2);
}
}
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "*", 1) == 0) {
int compare = 1;
int k = 0;
for (k = 0; k < nproc; k++) {
compare *= (k + j) * (((k + j) % 2 == 0) ? 1 : -1);
}
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "min", 3) == 0) {
int compare = -(j + nproc - 1);
if (compare % 2 == 0 && nproc > 1) {
compare = -(j + nproc - 2);
}
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "max", 3) == 0) {
int compare = j + nproc - 1;
if (compare % 2 != 0 && nproc > 1) {
compare = j + nproc - 2;
}
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmax", 6) == 0) {
int compare = j + nproc - 1;
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmin", 6) == 0) {
int compare = j;
if (((long *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %ld != %d\n", test_type, "ARMCI_LONG", op, i, j, ((long *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "or", 2) == 0) {
}
}
break;
case ARMCI_FLOAT:
datatype_size = sizeof(float);
for (i = 0; i < len_length; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < len_length; i++)
for (j = 0; j < len[i]; j++) {
((float *) a[i])[j] = (float)(me + j) * (((me + j) % 2 == 0) ? 1.0 / nproc : -1.0 / nproc);
}
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("testing %s ARMCI_FLOAT message size = %d op = %s\n", test_type, len[i], op);
}
if (reduce_test == 0) {
armci_msg_fgop(a[i], len[i], op);
}
else {
armci_msg_reduce(a[i], len[i], op, datatype);
}
}
if (me == 0 || reduce_test == 0)
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("checking %s ARMCI_FLOAT message size = %d op = %s\n", test_type, len[i], op);
}
for (j = 0; j < len[i]; j++)
if (strncmp(op, "+", 1) == 0) {
float compare = 0.0;
if (nproc % 2 == 0) {
if (j % 2 == 0) {
compare = -(((int)nproc / 2) / (float) nproc);
}
else {
compare = ((int)nproc / 2) / (float) nproc;
}
}
else {
if (j % 2 == 0) {
compare = ((int) j + nproc / 2) / (float) nproc;
}
else {
compare = -(((int) j + nproc / 2) / (float) nproc);
}
}
if (ARMCI_ABS(((float *) a[i])[j] - compare) > ARMCI_ABS(compare) * FLOAT_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "*", 1) == 0) {
float compare = 1.0;
int k = 0;
for (k = 0; k < nproc; k++) {
compare *= ((float) k + j) / (float) nproc;
}
if ((nproc / 2) % 2 != 0)
if (nproc % 2 != 0)
if (j % 2 == 0) {
compare *= -1.0;
}
if (ARMCI_ABS(((float *) a[i])[j] - compare) > ARMCI_ABS(compare) * FLOAT_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "min", 3) == 0) {
float compare = -((float) j + nproc - 1) / nproc;
if ((j + nproc - 1) % 2 == 0 && nproc > 1) {
compare = -((float) j + nproc - 2) / nproc;
}
if (((float *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "max", 3) == 0) {
float compare = ((float) j + nproc - 1) / nproc;
if ((j + nproc - 1) % 2 != 0 && nproc > 1) {
compare = ((float) j + nproc - 2) / nproc;
}
if (((float *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmax", 6) == 0) {
float compare = ((float) j + nproc - 1) / nproc;
if (((float *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmin", 6) == 0) {
float compare = (float) j / nproc;
if (((float *) a[i])[j] != compare) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_FLOAT", op, i, j, ((float *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
}
break;
case ARMCI_DOUBLE:
datatype_size = sizeof(double);
for (i = 0; i < len_length; i++) {
a[i] = malloc(len[i] * datatype_size);
}
for (i = 0; i < len_length; i++)
for (j = 0; j < len[i]; j++) {
((double *) a[i])[j] = (double)(me + j) * (((me + j) % 2 == 0) ? 1.0 / nproc : -1.0 / nproc);
}
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("testing %s ARMCI_DOUBLE message size = %d op = %s\n", test_type, len[i], op);
}
if (reduce_test == 0) {
armci_msg_dgop(a[i], len[i], op);
}
else {
armci_msg_reduce(a[i], len[i], op, datatype);
}
}
if (me == 0 || reduce_test == 0)
for (i = 0; i < len_length; i++) {
if (me == 0 && verbose != 0) {
printf("checking %s ARMCI_DOUBLE message size = %d op = %s\n", test_type, len[i], op);
}
for (j = 0; j < len[i]; j++)
if (strncmp(op, "+", 1) == 0) {
double compare = 0.0;
if (nproc % 2 == 0) {
if (j % 2 == 0) {
compare = -(((int)nproc / 2) / (double) nproc);
}
else {
compare = ((int)nproc / 2) / (double) nproc;
}
}
else {
if (j % 2 == 0) {
compare = ((int) j + nproc / 2) / (double) nproc;
}
else {
compare = -(((int) j + nproc / 2) / (double) nproc);
}
}
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "*", 1) == 0) {
double compare = 1.0;
int k = 0;
for (k = 0; k < nproc; k++) {
compare *= ((float) k + j) / (float) nproc;
}
if ((nproc / 2) % 2 != 0)
if (nproc % 2 != 0)
if (j % 2 == 0) {
compare *= -1.0;
}
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "min", 3) == 0) {
double compare = -((double) j + nproc - 1) / nproc;
if ((j + nproc - 1) % 2 == 0 && nproc > 1) {
compare = -((double) j + nproc - 2) / nproc;
}
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "max", 3) == 0) {
double compare = ((double) j + nproc - 1) / nproc;
if ((j + nproc - 1) % 2 != 0 && nproc > 1) {
compare = ((double) j + nproc - 2) / nproc;
}
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmax", 6) == 0) {
double compare = ((double) j + nproc - 1) / nproc;
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
else if (strncmp(op, "absmin", 6) == 0) {
double compare = (double) j / nproc;
if (ARMCI_ABS(((double *) a[i])[j] - compare) > ARMCI_ABS(compare) * DOUBLE_EPS) {
printf("ERROR %s %s %s a[%d][%d] = %f != %f\n", test_type, "ARMCI_DOUBLE", op, i, j, ((double *) a[i])[j], compare);
ARMCI_Error("test_gop2_or_reduce failed\n", 0);
}
}
}
break;
default:
break;
}
for (i = 0; i < len_length; i++) {
free(a[i]);
}
}
void test_collective(const int datatype)
{
char *op[7] = {"+", "*", "min", "max", "absmax", "absmin", "or"};
int i = 0;
int num_tests = 7;
if (datatype == ARMCI_DOUBLE || datatype == ARMCI_FLOAT) {
num_tests = 6;
}
/* test armci_msg_brdcst */
test_brdcst(datatype);
/* test armci_msg_gop2 */
for (i = 0; i < num_tests; i++) {
test_gop2_or_reduce(datatype, op[i], 0);
}
/* test armci_msg_reduce */
for (i = 0; i < num_tests; i++) {
test_gop2_or_reduce(datatype, op[i], 1);
}
ARMCI_Barrier();
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("O.K.\n\n");
fflush(stdout);
}
}
void test_acc_type(const int datatype)
{
int i = 0;
int datatype_size = 0;
void *scale;
void *a;
void *b[MAXPROC];
int elems = ELEMS;
int dim = 1;
int count = 0;
int strideA = 0;
int strideB = 0;
switch (datatype) {
case ARMCI_ACC_INT:
datatype_size = sizeof(int);
scale = malloc(datatype_size);
*((int *) scale) = 1;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((int *) a)[i] = i + me;
((int *) b[me])[i] = 0;
}
break;
case ARMCI_ACC_LNG:
datatype_size = sizeof(long);
scale = malloc(datatype_size);
*((long *) scale) = 1;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((long *) a)[i] = i + me;
((long *) b[me])[i] = 0;
}
break;
case ARMCI_ACC_FLT:
datatype_size = sizeof(float);
scale = malloc(datatype_size);
*((float *) scale) = 1.0;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((float *) a)[i] = (float) i + me;
((float *) b[me])[i] = 0.0;
}
break;
case ARMCI_ACC_DBL:
datatype_size = sizeof(double);
scale = malloc(datatype_size);
*((double *) scale) = 1.0;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((double *) a)[i] = (double) i + me;
((double *) b[me])[i] = 0.0;
}
break;
case ARMCI_ACC_CPL:
datatype_size = sizeof(cmpl_t);
scale = malloc(datatype_size);
((cmpl_t *) scale)->real = 2.0;
((cmpl_t *) scale)->imag = 1.0;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((cmpl_t *) a)[i].real = ((float) i + me);
((cmpl_t *) a)[i].imag = ((float) i + me);
((cmpl_t *) b[me])[i].real = 0.0;
((cmpl_t *) b[me])[i].imag = 0.0;
}
break;
case ARMCI_ACC_DCP:
datatype_size = sizeof(dcmpl_t);
scale = malloc(datatype_size);
((dcmpl_t *) scale)->real = 2.0;
((dcmpl_t *) scale)->imag = 1.0;
a = malloc(elems * datatype_size);
create_array((void **)b, datatype_size, dim, &elems);
for (i = 0; i < elems; i++) {
((dcmpl_t *) a)[i].real = ((double) i + me);
((dcmpl_t *) a)[i].imag = ((double) i + me);
((dcmpl_t *) b[me])[i].real = 0.0;
((dcmpl_t *) b[me])[i].imag = 0.0;
}
break;
default:
return;
break;
}
count = elems * datatype_size;
strideA = elems * datatype_size;
strideB = elems * datatype_size;
ARMCI_AllFence();
ARMCI_Barrier();
for (i = 0; i < nproc; i++) {
ARMCI_AccS(datatype, scale, a, &strideA, b[(me + i) % nproc], &strideB, &count, 0, (me + i) % nproc);
}
ARMCI_AllFence();
ARMCI_Barrier();
switch (datatype) {
case ARMCI_ACC_INT:
for (i = 0; i < elems; i++) {
int compare = (i * nproc) + nproc / 2 * (nproc - 1);
if (((int *)b[me])[i] != compare) {
printf("ERROR accumulate ARMCI_ACC_INT [%d] = %d != %d\n", i, ((int *)b[me])[i], compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
case ARMCI_ACC_LNG:
for (i = 0; i < elems; i++) {
long compare = (i * nproc) + nproc / 2 * (nproc - 1);
if (((long *)b[me])[i] != compare) {
printf("ERROR accumulate ARMCI_ACC_LNG [%d] = %d != %ld\n", i, ((int *)b[me])[i], compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
case ARMCI_ACC_FLT:
for (i = 0; i < elems; i++) {
float compare = (float)((i * nproc) + nproc / 2 * (nproc - 1));
if (((float *)b[me])[i] != compare) {
printf("ERROR accumulate ARMCI_ACC_FLT [%d] = %f != %f\n", i, ((float *)b[me])[i], compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
case ARMCI_ACC_DBL:
for (i = 0; i < elems; i++) {
double compare = (double)((i * nproc) + nproc / 2 * (nproc - 1));
if (((double *)b[me])[i] != (double)((i * nproc) + nproc / 2 *(nproc - 1))) {
printf("ERROR accumulate ARMCI_ACC_DBL [%d] = %f != %f \n", i, ((double *)b[me])[i], compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
case ARMCI_ACC_CPL:
for (i = 0; i < elems; i++) {
float compare = (float)((i * nproc) + nproc / 2 * (nproc - 1));
if (((cmpl_t *)b[me])[i].real != compare && ((cmpl_t *)b[me])[i].imag != 3 * compare) {
printf("ERROR accumulate ARMCI_ACC_CPL [%d] = %f + %fj != %f + %fj\n", i, ((cmpl_t *)b[me])[i].real, ((cmpl_t *)b[me])[i].imag, compare, 3 * compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
case ARMCI_ACC_DCP:
for (i = 0; i < elems; i++) {
double compare = (double)((i * nproc) + nproc / 2 * (nproc - 1));
if (((dcmpl_t *)b[me])[i].real != compare && ((dcmpl_t *)b[me])[i].imag != 3 * compare) {
printf("ERROR accumulate ARMCI_ACC_DCP [%d] = %f + %fj != %f + %fj\n", i, ((dcmpl_t *)b[me])[i].real, ((dcmpl_t *)b[me])[i].imag, compare, 3 * compare);
ARMCI_Error("test_acc_type failed\n", 0);
}
}
break;
default:
break;
}
ARMCI_Barrier();
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("O.K.\n\n");
fflush(stdout);
}
destroy_array((void **)b);
free(a);
free(scale);
}
int main(int argc, char *argv[])
{
int i;
struct timeval start_time[14];
struct timeval stop_time[14];
/*
char * test_name[14] = {
"dim", "nbdim", "vec_small", "acc",
"vector", "vector_acc", "fetch_add",
"swap", "rput", "aggregate", "implicit",
"memlock", "acc_type", "collective"
};
int test_flags[14] = {
1, 1, 1, 1,
1, 1, 1,
1, 1, 0, 1,
1, 1, 1
};
*/
char *test_name[2] = { "acc_type", "collective" };
int test_flags[2] = { 1, 1 };
#define TEST_ACC_TYPE 0
#define TEST_COLLECTIVE 1
armci_msg_init(&argc, &argv);
ARMCI_Init_args(&argc, &argv);
nproc = armci_msg_nproc();
me = armci_msg_me();
if (nproc > MAXPROC && me == 0) {
ARMCI_Error("Test works for up to %d processors\n", MAXPROC);
}
if (me == 0) {
printf("ARMCI test program (%d processes)\n", nproc);
fflush(stdout);
sleep(1);
}
gettimeofday(&start_time[TEST_ACC_TYPE], NULL);
if (test_flags[TEST_ACC_TYPE] == 1) {
if (me == 0) {
printf("\nTesting Accumulate Types\n");
fflush(stdout);
}
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_INT\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_INT);
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_LNG\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_LNG);
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_FLT\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_FLT);
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_DBL\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_DBL);
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_CPL\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_CPL);
ARMCI_AllFence();
ARMCI_Barrier();
if (me == 0) {
printf("Test Accumulate ARMCI_ACC_DCP\n");
fflush(stdout);
}
test_acc_type(ARMCI_ACC_DCP);
ARMCI_AllFence();
ARMCI_Barrier();
}
gettimeofday(&stop_time[TEST_ACC_TYPE], NULL);
gettimeofday(&start_time[TEST_COLLECTIVE], NULL);
if (test_flags[TEST_COLLECTIVE] == 1) {
if (me == 0) {
printf("\nTesting Collective Types\n");
fflush(stdout);
}
if (me == 0) {
printf("Test Collective ARMCI_INT\n");
fflush(stdout);
}
ARMCI_Barrier();
test_collective(ARMCI_INT);
ARMCI_Barrier();
if (me == 0) {
printf("Test Collective ARMCI_LONG\n");
fflush(stdout);
}
ARMCI_Barrier();
test_collective(ARMCI_LONG);
ARMCI_Barrier();
if (me == 0) {
printf("Test Collective ARMCI_FLOAT\n");
fflush(stdout);
}
ARMCI_Barrier();
test_collective(ARMCI_FLOAT);
ARMCI_Barrier();
if (me == 0) {
printf("Test Collective ARMCI_DOUBLE\n");
fflush(stdout);
}
ARMCI_Barrier();
test_collective(ARMCI_DOUBLE);
ARMCI_Barrier();
}
gettimeofday(&stop_time[TEST_COLLECTIVE], NULL);
if (me == 0) {
printf("Accumulate and Collective tests passed\n");
fflush(stdout);
}
if (me == 0) {
printf("Testcase runtime\n");
printf("Name,Time(seconds)\n");
for (i = 0; i < 2; i++)
if (test_flags[i] == 1) {
double time_spent = (stop_time[i].tv_sec - start_time[i].tv_sec) + ((double) stop_time[i].tv_usec - start_time[i].tv_usec) / 1E6;
printf("%s,%.6f\n", test_name[i], time_spent);
}
}
ARMCI_Barrier();
ARMCI_Finalize();
armci_msg_finalize();
return(0);
}
|