-
Notifications
You must be signed in to change notification settings - Fork 6
/
supermagic.c
1612 lines (1380 loc) · 50.7 KB
/
supermagic.c
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
/**
* Copyright (c) 2010-2022 Los Alamos National Security, LLC.
* All rights reserved.
*
* This program was prepared by Los Alamos National Security, LLC at Los Alamos
* National Laboratory (LANL) under contract No. DE-AC52-06NA25396 with the U.S.
* Department of Energy (DOE). All rights in the program are reserved by the DOE
* and Los Alamos National Security, LLC. Permission is granted to the public to
* copy and use this software without charge, provided that this Notice and any
* statement of authorship are reproduced on all copies. Neither the U.S.
* Government nor LANS makes any warranty, express or implied, or assumes any
* liability or responsibility for the use of this software.
*/
/**
* @author Samuel K. Gutierrez - samuelREMOVEME@lanl.gov
* found a bug? have an idea? please let me know.
*/
#include "supermagic.h"
/* ////////////////////////////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////// */
/* private utility functions */
/* ////////////////////////////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////// */
#if 0
/* ////////////////////////////////////////////////////////////////////////// */
static int
qsort_cmp_uli(const void *p1,
const void *p2)
{
return (*(unsigned long int *)p1 - *(unsigned long int *)p2);
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
get_my_global_color(bool used_cached, int *out_color)
{
unsigned long int *net_nums = NULL;
int mpi_rc = MPI_ERR_OTHER, rc = SMGC_ERROR;
int i = 0, node_i = 0;
unsigned long int prev_num;
if (NULL == out_color) {
return SMGC_ERROR;
}
/* do we have to figure this out - or can we use a cached value? */
if (SMGC_COLOR_INVALID != my_color && used_cached) {
*out_color = my_color;
return SMGC_SUCCESS;
}
/* if we are here, then we have to do some work :-( */
net_nums = (unsigned long int *)calloc(num_ranks,
sizeof(unsigned long int));
if (NULL == net_nums) {
SMGC_ERR_MSG("out of resources\n");
return SMGC_ERROR;
}
if (SMGC_SUCCESS != get_net_num(host_name_buff, &my_net_num)) {
SMGC_ERR_MSG("get_net_num failure\n");
goto out;
}
SMGC_MPF(" mpi_comm_world: exchanging network infomation\n"
" mpi_allgather buffer size: %lu B\n",
(num_ranks * sizeof(unsigned long int)));
mpi_rc = MPI_Allgather(&my_net_num, 1, MPI_UNSIGNED_LONG, net_nums, 1,
MPI_UNSIGNED_LONG, MPI_COMM_WORLD);
SMGC_MPICHK(mpi_rc, out);
qsort(net_nums, (size_t)num_ranks, sizeof(unsigned long int),
qsort_cmp_uli);
prev_num = net_nums[i++];
while (i < num_ranks && prev_num != my_net_num) {
while (net_nums[i] == prev_num) {
++i;
}
++node_i;
prev_num = net_nums[i];
}
*out_color = node_i;
rc = SMGC_SUCCESS;
out:
if (NULL != net_nums) free(net_nums);
return rc;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
get_net_num(const char *target_hostname,
unsigned long int *out_net_num)
{
struct hostent *host = NULL;
if (NULL == target_hostname || NULL == out_net_num) {
return SMGC_ERROR;
}
if (NULL == (host = gethostbyname(target_hostname))) {
SMGC_ERR_MSG("gethostbyname error\n");
/* epic fail! */
return SMGC_ERROR;
}
/* htonl used here for good measure - probably not needed */
*out_net_num = (unsigned long int)
htonl(inet_network(inet_ntoa(*(struct in_addr *)host->h_addr)));
return SMGC_SUCCESS;
}
#endif
/* ////////////////////////////////////////////////////////////////////////// */
static int
get_mult(char symbol, int *resp)
{
*resp = -42;
switch (symbol) {
case 'B':
*resp = 1;
break;
case 'k':
*resp = 1024;
break;
case 'M':
*resp = 1048576;
break;
case 'G':
*resp = 1073741824;
break;
default:
SMGC_ERR_MSG("\'%c\' is not a supported message size option.\n",
symbol);
/* fail */
return SMGC_ERROR;
/* never reached */
break;
}
return SMGC_SUCCESS;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
get_msg_size(const char *str, const char *label, int *real_msg_size)
{
long unit_size = -1;
/* default multiplier is 1 (B) */
int mult = 1;
char *end_ptr = NULL;
errno = 0;
unit_size = strtol(str, &end_ptr, 10);
/* was there an error */
if ((EINVAL == errno && 0 == unit_size) ||
(ERANGE == errno && (LONG_MIN == unit_size || LONG_MAX == unit_size))) {
int err = errno;
SMGC_ERR_MSG("strtol error: %d (%s)\n", err, strerror(err));
return SMGC_ERROR;
}
/* catch negative message sizes */
else if (unit_size < 0) {
SMGC_ERR_MSG("negative %s sizes are not supported.\n", label);
return SMGC_ERROR;
}
/* all is well with the value returned by strtol */
else {
/* big hammer */
uint64_t us = 0, m = 0, tmp = 0;
/* a multiplier was provided by the user */
if ('\0' != *end_ptr) {
/* get the multiplier */
if (SMGC_ERROR == get_mult(end_ptr[0], &mult)) {
/* fail */
return SMGC_ERROR;
}
}
us = (uint64_t)unit_size;
m = (uint64_t)mult;
/* what is the real message size (B) */
tmp = (us * m);
if (tmp > INT_MAX || tmp < us || tmp < m) {
SMGC_ERR_MSG("requested %s size is too large.\n", label);
return SMGC_ERROR;
}
else {
*real_msg_size = (int)tmp;
}
return SMGC_SUCCESS;
}
/* never reached */
return SMGC_ERROR;
}
/* ////////////////////////////////////////////////////////////////////////// */
/**
* returns number of tests within test suite pointed to by test_suite_ptr
*/
static int
get_num_tests(smgc_test_t *test_suite_ptr)
{
int i;
for (i = 0; i < SMGC_MAX_TESTS; ++i) {
if (NULL == test_suite_ptr[i].tname || NULL == test_suite_ptr[i].tfp) {
break;
}
}
return i;
}
/* ////////////////////////////////////////////////////////////////////////// */
/**
* prints all available tests
*/
static void
list_all_tests(void)
{
int i, num_tests = get_num_tests(smgc_all_tests);
SMGC_MPF("available tests:\n");
for (i = 0; i < num_tests; ++i) {
SMGC_MPF(" %s\n", smgc_all_tests[i].tname);
}
SMGC_MPF("\n");
}
/* ////////////////////////////////////////////////////////////////////////// */
/**
* prints usage information
*/
static void
usage(void)
{
SMGC_MPF("\n%s\n", SMGC_USAGE);
list_all_tests();
SMGC_MPF("%s\n", SMGC_EXAMPLE);
}
/* ////////////////////////////////////////////////////////////////////////// */
static bool
is_valid_test(char *test_name, int *test_index)
{
int i;
for (i = 0; NULL != smgc_all_tests[i].tname; ++i) {
if (0 == strcmp(test_name, smgc_all_tests[i].tname)) {
if (NULL != test_index) {
*test_index = i;
}
return true;
}
}
/* if test_name is not valid, *test_index is undefined */
return false;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
create_test_list(const char *test_list_str,
smgc_test_t **smgc_custom_jb_test_ptr)
{
char *test_string = NULL;
char *last = NULL;
char *tmp_list = NULL;
int num_tests = 0;
int test_index = 0;
smgc_test_t *tmp_ptr = *smgc_custom_jb_test_ptr;
if (tests_on_heap) {
if (NULL != smgc_test_ptr) {
free(smgc_test_ptr);
smgc_test_ptr = NULL;
}
}
if (NULL == (tmp_list = strdup(test_list_str))) {
SMGC_ERR_MSG("out of resources\n");
return SMGC_ERROR;
}
else if (NULL == (tmp_ptr = (smgc_test_t *)malloc(sizeof(smgc_test_t) *
SMGC_MAX_TESTS))) {
free(tmp_list);
SMGC_ERR_MSG("out of resources\n");
return SMGC_ERROR;
}
/* if we are here, then let the games begin */
for (test_string = strtok_r(tmp_list, ",", &last);
NULL != test_string && SMGC_MAX_TESTS >= num_tests;
test_string = strtok_r(NULL, ",", &last)) {
if (is_valid_test(test_string, &test_index)) {
tmp_ptr[num_tests++] = smgc_all_tests[test_index];
}
}
/* cap with NULLs */
tmp_ptr[num_tests].tname = NULL;
tmp_ptr[num_tests].tfp = NULL;
/* update the test suite */
upd_test_suite(tmp_ptr);
tests_on_heap = true;
return SMGC_SUCCESS;
}
/* ////////////////////////////////////////////////////////////////////////// */
static char *
get_time_str(time_t *raw_time)
{
char tsb[SMGC_MAX_TIME_LEN];
struct tm *bd_time_ptr = NULL;
time(raw_time);
bd_time_ptr = localtime(raw_time);
strftime(tsb, SMGC_MAX_TIME_LEN - 1, SMGC_DATE_FORMAT, bd_time_ptr);
/* caller is responsible for freeing returned resources */
return strdup(tsb);
}
/* ////////////////////////////////////////////////////////////////////////// */
static char *
get_rhn(int rank)
{
if (NULL != rhname_lut_ptr) {
return &(rhname_lut_ptr[rank * SMGC_HOST_NAME_MAX]);
}
else {
return rhn_unknown;
}
}
/* ////////////////////////////////////////////////////////////////////////// */
static void
upd_test_suite(smgc_test_t *new_test_suite_ptr)
{
smgc_test_ptr = new_test_suite_ptr;
num_tests = get_num_tests(smgc_test_ptr);
}
/* ////////////////////////////////////////////////////////////////////////// */
static void
set_jb_params()
{
if (num_ranks >= SMGC_LRG_JB) {
msg_size = SMGC_LRG_JB_MSG_SIZE;
be_verbose = false;
be_quiet = true;
upd_test_suite(smgc_lrg_jb_tests);
}
else {
upd_test_suite(smgc_small_jb_tests);
}
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
io_stats(double_int_t in_dint, char *label, int unit_type)
{
char *unit = NULL;
double val = in_dint.val;
double sum = 0.0;
double_int_t max = {0.0, 0}, min = {0.0, 0};
int mpi_ret_code = MPI_ERR_OTHER;
switch (unit_type) {
case IO_STATS_TIME_S:
unit = SMGC_TIME_S_UNIT_STR;
break;
case IO_STATS_MBS:
unit = SMGC_MBS_UNIT_STR;
break;
default:
SMGC_ERR_MSG("io_stats::unknow unit_type\n");
goto err;
/* never reached */
break;
}
mpi_ret_code = MPI_Reduce(&in_dint, &max, 1, MPI_DOUBLE_INT, MPI_MAXLOC,
SMGC_MASTER_RANK, MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, err);
mpi_ret_code = MPI_Reduce(&in_dint, &min, 1, MPI_DOUBLE_INT, MPI_MINLOC,
SMGC_MASTER_RANK, MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, err);
mpi_ret_code = MPI_Reduce(&val, &sum, 1, MPI_DOUBLE, MPI_SUM,
SMGC_MASTER_RANK, MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, err);
SMGC_MPF(" --- %s:\n", label);
SMGC_MPF(" max rank: %06d (%s)\n", max.rank, get_rhn(max.rank));
SMGC_MPF(" max %s: %.3f %s\n", label, max.val, unit);
SMGC_MPF(" min rank: %06d (%s)\n", min.rank, get_rhn(min.rank));
SMGC_MPF(" min %s: %.3f %s\n", label, min.val, unit);
SMGC_MPF(" ave %s: %.3f %s\n", label, sum / num_ranks, unit);
SMGC_MPF(" aggregate %s: %.3f %s\n", label, sum, unit);
return SMGC_SUCCESS;
err:
return SMGC_ERROR;
}
/* ////////////////////////////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////// */
/* test functions */
/* ////////////////////////////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////// */
/* ////////////////////////////////////////////////////////////////////////// */
/* test by request only */
static int
n_to_n_io(void)
{
int i = 0, j = 0, fd = -1, rc = SMGC_ERROR, mpi_rc = MPI_ERR_OTHER;
/* what we are going to write and what we should read, buff rest char */
char wr_char = 'j', clobber_char = 'x';
ssize_t bytes_written = -1, bytes_read = -1;
/* the size of the file that i'll be writing (in B) */
size_t buff_size = file_size;
char *my_file_name = NULL;
/* points to buffer used for both reading and writing */
char *buff = NULL;
/* variables for recording time */
double open_time = 0.0, close_time = 0.0, write_start = 0.0,
write_fin = 0.0;
double read_start = 0.0, read_fin = 0.0, lseek_start = 0.0, lseek_fin = 0.0,
effe_bw_time_fix = 0.0, memset_start = 0.0, memset_fin = 0.0,
tmp_dbl = 0.0;
/* bandwidth variables */
double effe_bw = 0.0, read_bw = 0.0, write_bw = 0.0;
/* for reduce operations that find max and min rank */
double_int_t in_effe = {0.0, 0};
double_int_t in_wr = {0.0, 0};
double_int_t in_rd = {0.0, 0};
/* no work to do, return success and move on */
if (0 == num_fs_test_paths) {
SMGC_MPF(" zero paths requested via -w option. skipping test.\n");
return SMGC_SUCCESS;
}
/* if we are here, let the games begin! */
if (NULL == (buff = (char *)malloc(buff_size * sizeof(char)))) {
SMGC_ERR_MSG("out of resources\n");
return SMGC_ERROR;
}
memset(buff, wr_char, buff_size);
SMGC_MPF(" file size (per rank process): %lu B\n", buff_size);
/* write to all requested paths */
for (i = 0; i < num_fs_test_paths; ++i) {
if (-1 == asprintf(&my_file_name, "%s/%s_%d", fs_test_list[i],
SMGC_MPI_FILE_NAME, my_rank)) {
SMGC_ERR_MSG("out of resources\n");
goto out;
}
if (NULL == my_file_name) {
SMGC_ERR_MSG("out of resources\n");
goto out;
}
/* let the user know we are working on it */
SMGC_MPF(" === mpi_comm_world: writing to %s\n", fs_test_list[i]);
/* barrier before we start */
mpi_rc = MPI_Barrier(MPI_COMM_WORLD);
SMGC_MPICHK(mpi_rc, out);
open_time = MPI_Wtime();
if (-1 == (fd = open(my_file_name, O_CREAT | O_RDWR, 0600))) {
int error = errno;
SMGC_ERR_MSG("open failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
write_start = MPI_Wtime();
if (-1 == (bytes_written = write(fd, buff, buff_size))) {
int error = errno;
SMGC_ERR_MSG("write failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
write_fin = MPI_Wtime();
/* seek to beginning of file - time this step so we can subtract the
* time spent here from our bw calculations
*/
lseek_start = MPI_Wtime();
if(-1 == lseek(fd, 0, SEEK_SET)) {
int error = errno;
SMGC_ERR_MSG("lseek failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
lseek_fin = MPI_Wtime();
memset_start = MPI_Wtime();
/* overwrite buff's contents before read */
memset(buff, clobber_char, buff_size);
memset_fin = MPI_Wtime();
read_start = MPI_Wtime();
if (-1 == (bytes_read = read(fd, buff, buff_size))) {
int error = errno;
SMGC_ERR_MSG("read failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
read_fin = MPI_Wtime();
if (0 != close(fd)) {
int error = errno;
SMGC_ERR_MSG("close failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
close_time = MPI_Wtime();
fd = -1;
if (0 != unlink(my_file_name)) {
int error = errno;
SMGC_ERR_MSG("unlink failed with errno: %d (%s)\n", error,
strerror(error));
goto out;
}
/* check integrity of read */
if (bytes_written != bytes_read) {
SMGC_ERR_MSG("write/read mismatch. wrote %lu read %lu\n",
bytes_written, bytes_read);
goto out;
}
/* iterate over char buff - making certain all is well */
for (j = 0; j < bytes_written; ++j) {
if (wr_char != buff[j]) {
SMGC_ERR_MSG(
"characters read do not match characters written!\n"
);
goto out;
}
}
/* subtract time not spent in benchmarked routines */
effe_bw_time_fix = (lseek_fin - lseek_start) +
(memset_fin - memset_start);
/* calculate bandwidths */
/* negative and 0 length file size protection provided by lower level */
/* zero value fixup - good enough for our purposes */
/* effective bandwidth */
if (0.0 >= (tmp_dbl = ((close_time - open_time) - effe_bw_time_fix))) {
effe_bw = 0.0;
}
else {
effe_bw = ((double)buff_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* write bandwidth */
if (0.0 >= (tmp_dbl = (write_fin - write_start))) {
write_bw = 0.0;
}
else {
write_bw = ((double)buff_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* read bandwidth */
if (0.0 >= (tmp_dbl = (read_fin - read_start))) {
read_bw = 0.0;
}
else {
read_bw = ((double)buff_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* prepare values for reduce */
in_effe.val = effe_bw;
in_effe.rank = my_rank;
in_wr.val = write_bw;
in_wr.rank = my_rank;
in_rd.val = read_bw;
in_rd.rank = my_rank;
/* calculate effective bandwidth stats */
if (SMGC_SUCCESS != (rc = io_stats(in_effe, "effective write bandwidth",
IO_STATS_MBS))) {
goto out;
}
/* calculate write bandwidth stats */
if (SMGC_SUCCESS != (rc = io_stats(in_wr, "pure write bandwidth",
IO_STATS_MBS))) {
goto out;
}
/* calculate read bandwidth stats */
if (SMGC_SUCCESS != (rc = io_stats(in_rd, "pure read bandwidth",
IO_STATS_MBS))) {
goto out;
}
/* all is well for this iteration */
if (NULL != my_file_name) {
free(my_file_name);
my_file_name = NULL;
}
}
/* all is well */
rc = SMGC_SUCCESS;
out:
if (-1 != fd) {
close(fd);
unlink(my_file_name);
}
if (NULL != buff) free(buff);
if (NULL != my_file_name) free(my_file_name);
return rc;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
hello_world(void)
{
int res_len = 0;
char name_buff[MPI_MAX_PROCESSOR_NAME + 1];
mpi_ret_code = MPI_Get_processor_name(name_buff, &res_len);
SMGC_MPICHK(mpi_ret_code, err);
SMGC_FPF(stdout, " hello from rank %06d (%s) of %06d\n", my_rank,
name_buff, num_ranks);
return SMGC_SUCCESS;
err:
return SMGC_ERROR;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
stat_paths(void)
{
int i = 0;
struct stat buff;
/* nothing to do, so that's easy */
if (0 == num_stat_paths) {
SMGC_MPF(" zero paths requested via -s option. skipping test.\n");
return SMGC_SUCCESS;
}
for (i = 0; i < num_stat_paths; ++i) {
SMGC_MPF(" mpi_comm_world: stating %s\n", stat_list[i]);
/* try to stat the file */
if (0 != stat(stat_list[i], &buff)) {
SMGC_FPF(stderr, " !!! rank %d (%s) unable to stat %s\n", my_rank,
host_name_buff, stat_list[i]);
return SMGC_ERROR;
}
}
return SMGC_SUCCESS;
}
/* ////////////////////////////////////////////////////////////////////////// */
static void
kill_mpi_messaging(int sig)
{
(void)sig;
/* no check in error path - hope for the best */
gethostname(host_name_buff, SMGC_HOST_NAME_MAX - 1);
host_name_buff[SMGC_HOST_NAME_MAX - 1] = '\0';
fprintf(stderr, "\n########## HANG DETECTED "
"[on loop iteration: %d] %d (%s) ==> %d (%s) ==> %d (%s) "
"##########\n",
glob_loop_iter, glob_l_neighbor, get_rhn(glob_l_neighbor), my_rank,
host_name_buff, glob_r_neighbor, get_rhn(glob_r_neighbor));
exit(EXIT_FAILURE);
}
/* ////////////////////////////////////////////////////////////////////////// */
#if SMGC_HAVE_CELL_SUPPORT == 1
/* in seconds */
#define CELL_TEST_TIMEOUT 480
/* ////////////////////////////////////////////////////////////////////////// */
static void
kill_cell_check(void)
{
/* no check in error path - hope for the best */
gethostname(host_name_buff, SMGC_HOST_NAME_MAX - 1);
host_name_buff[SMGC_HOST_NAME_MAX - 1] = '\0';
SMGC_ERR_MSG(
"rank %d (%s) unable to execute cell_sanity test within %d s.\n",
my_rank, host_name_buff, CELL_TEST_TIMEOUT);
exit(EXIT_FAILURE);
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
cell_sanity(void)
{
unsigned long rc = 0;
struct itimerval itimer;
itimer.it_value.tv_sec = CELL_TEST_TIMEOUT;
itimer.it_value.tv_usec = 0;
itimer.it_interval = itimer.it_value;
SMGC_MPF(" mpi_comm_world: running cell diagnostics\n");
signal(SIGALRM, (void(*)(int))&kill_cell_check);
setitimer(ITIMER_REAL, &itimer, NULL);
if (0 != (rc = cell_check(CELL_CHECK_MSG_FAIL, CELL_CHECK_TEST_ALL))) {
SMGC_ERR_MSG("cell_check failure - return code: %lu\n", rc);
goto err;
}
else {
/* all is well... disable the alarm */
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;
itimer.it_interval = itimer.it_value;
setitimer(ITIMER_REAL, &itimer, NULL);
}
return SMGC_SUCCESS;
err:
return SMGC_ERROR;
}
#endif /* SMGC_HAVE_CELL_SUPPORT */
/* ////////////////////////////////////////////////////////////////////////// */
static int
mpi_io(void)
{
int mpi_ret_code = MPI_ERR_OTHER, num_elems = 0, i = 0, rc = SMGC_ERROR;
/* access mode flags */
int amode = MPI_MODE_RDWR | MPI_MODE_CREATE | MPI_MODE_DELETE_ON_CLOSE;
char *buff = NULL, path_buff[SMGC_PATH_MAX];
/* i/o time markers */
double effe_start = 0.0, effe_fin = 0.0;
double write_start = 0.0, write_fin = 0.0, read_start = 0.0, read_fin = 0.0;
/* bandwidth variables */
double effe_bw = 0.0, write_bw = 0.0, read_bw = 0.0, effe_bw_time_fix = 0.0,
gete_start = 0.0, gete_fin = 0.0, gete_start2 = 0.0, gete_fin2 = 0.0;
double tmp_dbl = 0.0;
/* structs for min/max */
double_int_t in_wr = {0.0, 0}, in_rd = {0.0, 0}, in_effe = {0.0, 0};
/* file handle */
MPI_File mpi_fh;
MPI_Status status;
MPI_Offset offset = (MPI_Offset)(my_rank * file_size);
/* no writing to do, so return SMGC_SUCCESS */
if (0 == num_fs_test_paths) {
SMGC_MPF(" zero paths requested via -w option. skipping test.\n");
return SMGC_SUCCESS;
}
buff = (char *)malloc(file_size * sizeof(char));
SMGC_MEMCHK(buff, out);
memset(buff, 'j', (size_t)(file_size * sizeof(char)));
/* if we are here, then let the real work begin */
SMGC_MPF(" file size (per rank process): %lu B\n", file_size);
for (i = 0; i < num_fs_test_paths; ++i) {
int nw = snprintf(path_buff, SMGC_PATH_MAX, "%s/%s", fs_test_list[i],
SMGC_MPI_FILE_NAME);
if (nw >= SMGC_PATH_MAX) return SMGC_ERROR;
SMGC_MPF(" === mpi_comm_world: writing to %s\n", fs_test_list[i]);
/* barrier before we start each iteration */
mpi_ret_code = MPI_Barrier(MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, out);
effe_start = MPI_Wtime();
mpi_ret_code = MPI_File_open(MPI_COMM_WORLD, path_buff, amode,
MPI_INFO_NULL, &mpi_fh);
SMGC_MPICHK(mpi_ret_code, out);
mpi_ret_code = MPI_File_set_view(mpi_fh, (MPI_Offset)0, MPI_CHAR,
MPI_CHAR, "native", MPI_INFO_NULL);
SMGC_MPICHK(mpi_ret_code, out);
write_start = MPI_Wtime();
mpi_ret_code = MPI_File_write_at(mpi_fh, offset, buff,
file_size, MPI_CHAR,
&status);
SMGC_MPICHK(mpi_ret_code, out);
write_fin = MPI_Wtime();
gete_start = MPI_Wtime();
mpi_ret_code = MPI_Get_elements(&status, MPI_CHAR, &num_elems);
SMGC_MPICHK(mpi_ret_code, out);
gete_fin = MPI_Wtime();
if ((sizeof(char) * file_size) != (size_t)num_elems) {
SMGC_ERR_MSG("write size mismatch. wrote %lu requested %d\n",
sizeof(char) * file_size,
num_elems);
goto out;
}
read_start = MPI_Wtime();
mpi_ret_code = MPI_File_read_at(mpi_fh, offset, buff, file_size,
MPI_CHAR, &status);
SMGC_MPICHK(mpi_ret_code, out);
read_fin = MPI_Wtime();
gete_start2 = MPI_Wtime();
mpi_ret_code = MPI_Get_elements(&status, MPI_CHAR, &num_elems);
SMGC_MPICHK(mpi_ret_code, out);
gete_fin2 = MPI_Wtime();
mpi_ret_code = MPI_File_close(&mpi_fh);
SMGC_MPICHK(mpi_ret_code, out);
effe_fin = MPI_Wtime();
if ((sizeof(char) * file_size) != (size_t)num_elems) {
SMGC_ERR_MSG("write/read mismatch. wrote %lu read %d\n",
sizeof(char) * file_size,
num_elems);
goto out;
}
/* subtract time not spent in benchmarked routines */
effe_bw_time_fix = (gete_fin - gete_start) +
(gete_fin2 - gete_start2);
/* calculate bandwidths */
/* negative and 0 length file size protection provided by lower level */
/* zero value fixup - good enough for our purposes */
/* effective bandwidth */
if (0.0 >= (tmp_dbl = ((effe_fin - effe_start) - effe_bw_time_fix))) {
effe_bw = 0.0;
}
else {
effe_bw = ((double)file_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* write bandwidth */
if (0.0 >= (tmp_dbl = (write_fin - write_start))) {
write_bw = 0.0;
}
else {
write_bw = ((double)file_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* read bandwidth */
if (0.0 >= (tmp_dbl = (read_fin - read_start))) {
read_bw = 0.0;
}
else {
read_bw = ((double)file_size / tmp_dbl / (double)SMGC_MB_SIZE);
}
/* fill structs for calculating min/max */
in_effe.val = effe_bw;
in_effe.rank = my_rank;
in_wr.val = write_bw;
in_wr.rank = my_rank;
in_rd.val = read_bw;
in_rd.rank = my_rank;
/* calculate effective bandwidth stats */
if (SMGC_SUCCESS != io_stats(in_effe, "effective write bandwidth",
IO_STATS_MBS)) {
goto out;
}
/* calculate write bandwidth stats */
if (SMGC_SUCCESS != io_stats(in_wr, "pure write bandwidth",
IO_STATS_MBS)) {
goto out;
}
/* calculate read bandwidth stats */
if (SMGC_SUCCESS != io_stats(in_rd, "pure read bandwidth",
IO_STATS_MBS)) {
goto out;
}
}
/* all is well, set rc accordingly */
rc = SMGC_SUCCESS;
out:
if (NULL != buff) free(buff);
return rc;
}
#if 0
/* ////////////////////////////////////////////////////////////////////////// */
static int
host_info_exchange(void)
{
unsigned long int *net_nums = (unsigned long int *)
calloc(num_ranks, sizeof(unsigned long int));
int rc = SMGC_ERROR;
if (NULL == net_nums) {
SMGC_ERR_MSG("out of resources\n");
return SMGC_ERROR;
}
if (SMGC_SUCCESS != get_my_global_color(true, &my_color)) {
SMGC_ERR_MSG("get_my_global_color failure\n");
goto out;
}
out:
if (NULL != net_nums) free(net_nums);
return rc;
}
#endif
/* ////////////////////////////////////////////////////////////////////////// */
static int
hostname_exchange(void)
{
int buff_size = num_ranks * SMGC_HOST_NAME_MAX * sizeof(char);
if (NULL == rhname_lut_ptr) {
rhname_lut_ptr = (char *)calloc(buff_size, sizeof(char));
SMGC_MEMCHK(rhname_lut_ptr, error);
}
memset(rhname_lut_ptr, '\0', buff_size);
SMGC_MPF(" mpi_comm_world: mpi_allgather buffer size: %d B\n",
buff_size);
SMGC_MPF(" mpi_comm_world: exchanging host name information\n");
/* populate the remote host name lookup table */
mpi_ret_code = MPI_Allgather(host_name_buff, SMGC_HOST_NAME_MAX, MPI_CHAR,
rhname_lut_ptr, SMGC_HOST_NAME_MAX, MPI_CHAR,
MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, error);
return SMGC_SUCCESS;
error:
/* only free rhname_lut_ptr in error condition */
if (NULL != rhname_lut_ptr) {
free(rhname_lut_ptr);
rhname_lut_ptr = NULL;
}
return SMGC_ERROR;
}
/* ////////////////////////////////////////////////////////////////////////// */
static int
small_allreduce_max(void)
{
double send_buff = (double)my_rank, recv_buff = 0.0;
SMGC_MPF(" message size: %d B\n", (int)sizeof(double));
SMGC_MPF(" mpi_comm_world: mpi_allreducing\n");
mpi_ret_code = MPI_Allreduce(&send_buff, &recv_buff, 1, MPI_DOUBLE,
MPI_MAX, MPI_COMM_WORLD);
SMGC_MPICHK(mpi_ret_code, error);
SMGC_MPF(" mpi_comm_world: verifying result\n");
/* yes, i do want to do it this way :-) */
if (recv_buff != (double)(num_ranks - 1)) {
SMGC_ERR_MSG("invalid result detected\n");
goto error;
}
return SMGC_SUCCESS;
error:
return SMGC_ERROR;
}
/* ////////////////////////////////////////////////////////////////////////// */
/**
* potentially a very synchronous all to root point-to-point implementation.
*/
static int
large_all_to_root_ptp(void)
{
int buff_size = msg_size;
int src_rank = 0, tag = 0;
int rc = SMGC_ERROR;