This repository has been archived by the owner on Feb 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
ior.c
2636 lines (2376 loc) · 99.8 KB
/
ior.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
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
* vim:expandtab:shiftwidth=8:tabstop=8:
*/
/******************************************************************************\
* *
* Copyright (c) 2003, The Regents of the University of California *
* See the file COPYRIGHT for a complete copyright notice and license. *
* *
\******************************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h> /* tolower() */
#include <errno.h>
#include <math.h>
#include <mpi.h>
#include <string.h>
#include <sys/stat.h> /* struct stat */
#include <time.h>
#ifndef _WIN32
#include <sys/time.h> /* gettimeofday() */
#include <sys/utsname.h> /* uname() */
#endif
#include <assert.h>
#include "ior.h"
#include "aiori.h"
#include "utilities.h"
#include "parse_options.h"
/* globals used by other files, also defined "extern" in ior.h */
int numTasksWorld = 0;
int rank = 0;
int rankOffset = 0;
int tasksPerNode = 0; /* tasks per node */
int verbose = VERBOSE_0; /* verbose output */
MPI_Comm testComm;
/* file scope globals */
extern char **environ;
int totalErrorCount = 0;
double wall_clock_delta = 0;
double wall_clock_deviation;
ior_aiori_t *backend;
ior_aiori_t *available_aiori[] = {
#ifdef USE_POSIX_AIORI
&posix_aiori,
#endif
#ifdef USE_MPIIO_AIORI
&mpiio_aiori,
#endif
#ifdef USE_HDF5_AIORI
&hdf5_aiori,
#endif
#ifdef USE_NCMPI_AIORI
&ncmpi_aiori,
#endif
NULL
};
static void DestroyTests(IOR_test_t *tests_head);
static void DisplayUsage(char **);
static void GetTestFileName(char *, IOR_param_t *);
static char *PrependDir(IOR_param_t *, char *);
static char **ParseFileName(char *, int *);
static void PrintHeader(int argc, char **argv);
static IOR_test_t *SetupTests(int, char **);
static void ShowTestInfo(IOR_param_t *);
static void ShowSetup(IOR_param_t *params);
static void ShowTest(IOR_param_t *);
static void PrintLongSummaryAllTests(IOR_test_t *tests_head);
static void TestIoSys(IOR_test_t *);
static void ValidTests(IOR_param_t *);
static IOR_offset_t WriteOrRead(IOR_param_t *, void *, int);
static void WriteTimes(IOR_param_t *, double **, int, int);
/********************************** M A I N ***********************************/
int main(int argc, char **argv)
{
int i;
IOR_test_t *tests_head;
IOR_test_t *tptr;
/*
* check -h option from commandline without starting MPI;
* if the help option is requested in a script file (showHelp=TRUE),
* the help output will be displayed in the MPI job
*/
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0) {
DisplayUsage(argv);
return (0);
}
}
/* start the MPI code */
MPI_CHECK(MPI_Init(&argc, &argv), "cannot initialize MPI");
MPI_CHECK(MPI_Comm_size(MPI_COMM_WORLD, &numTasksWorld),
"cannot get number of tasks");
MPI_CHECK(MPI_Comm_rank(MPI_COMM_WORLD, &rank), "cannot get rank");
/* set error-handling */
/*MPI_CHECK(MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN),
"cannot set errhandler"); */
/* Sanity check, we were compiled with SOME backend, right? */
if (available_aiori[0] == NULL) {
ERR("No IO backends compiled into ior. That should not have happened.");
}
/* setup tests before verifying test validity */
tests_head = SetupTests(argc, argv);
verbose = tests_head->params.verbose;
tests_head->params.testComm = MPI_COMM_WORLD;
/* check for commandline usage */
if (rank == 0 && tests_head->params.showHelp == TRUE) {
DisplayUsage(argv);
}
PrintHeader(argc, argv);
/* perform each test */
for (tptr = tests_head; tptr != NULL; tptr = tptr->next) {
verbose = tptr->params.verbose;
if (rank == 0 && verbose >= VERBOSE_0) {
ShowTestInfo(&tptr->params);
}
if (rank == 0 && verbose >= VERBOSE_3) {
ShowTest(&tptr->params);
}
TestIoSys(tptr);
}
if (verbose < 0)
/* always print final summary */
verbose = 0;
PrintLongSummaryAllTests(tests_head);
/* display finish time */
if (rank == 0 && verbose >= VERBOSE_0) {
fprintf(stdout, "\n");
fprintf(stdout, "Finished: %s", CurrentTimeString());
}
DestroyTests(tests_head);
MPI_CHECK(MPI_Finalize(), "cannot finalize MPI");
return (totalErrorCount);
}
/***************************** F U N C T I O N S ******************************/
/*
* Initialize an IOR_param_t structure to the defaults
*/
void init_IOR_Param_t(IOR_param_t * p)
{
memset(p, 0, sizeof(IOR_param_t));
p->mode = IOR_IRUSR | IOR_IWUSR | IOR_IRGRP | IOR_IWGRP;
p->openFlags = IOR_RDWR | IOR_CREAT;
assert(available_aiori[0] != NULL);
strncpy(p->api, available_aiori[0]->name, MAX_STR);
strncpy(p->platform, "HOST(OSTYPE)", MAX_STR);
strncpy(p->testFileName, "testFile", MAXPATHLEN);
p->nodes = 1;
p->tasksPerNode = 1;
p->repetitions = 1;
p->repCounter = -1;
p->open = WRITE;
p->taskPerNodeOffset = 1;
p->segmentCount = 1;
p->blockSize = 1048576;
p->transferSize = 262144;
p->randomSeed = -1;
p->testComm = MPI_COMM_WORLD;
p->setAlignment = 1;
p->lustre_start_ost = -1;
}
/*
* Bind the global "backend" pointer to the requested backend AIORI's
* function table.
*/
static void AioriBind(char *api)
{
ior_aiori_t **tmp;
backend = NULL;
for (tmp = available_aiori; *tmp != NULL; tmp++) {
if (strcmp(api, (*tmp)->name) == 0) {
backend = *tmp;
break;
}
}
if (backend == NULL) {
ERR("unrecognized IO API");
}
}
static void
DisplayOutliers(int numTasks,
double timerVal,
char *timeString, int access, int outlierThreshold)
{
char accessString[MAX_STR];
double sum, mean, sqrDiff, var, sd;
/* for local timerVal, don't compensate for wall clock delta */
timerVal += wall_clock_delta;
MPI_CHECK(MPI_Allreduce
(&timerVal, &sum, 1, MPI_DOUBLE, MPI_SUM, testComm),
"MPI_Allreduce()");
mean = sum / numTasks;
sqrDiff = pow((mean - timerVal), 2);
MPI_CHECK(MPI_Allreduce
(&sqrDiff, &var, 1, MPI_DOUBLE, MPI_SUM, testComm),
"MPI_Allreduce()");
var = var / numTasks;
sd = sqrt(var);
if (access == WRITE) {
strcpy(accessString, "write");
} else { /* READ */
strcpy(accessString, "read");
}
if (fabs(timerVal - mean) > (double)outlierThreshold) {
fprintf(stdout, "WARNING: for task %d, %s %s is %f\n",
rank, accessString, timeString, timerVal);
fprintf(stdout, " (mean=%f, stddev=%f)\n", mean, sd);
fflush(stdout);
}
}
/*
* Check for outliers in start/end times and elapsed create/xfer/close times.
*/
static void CheckForOutliers(IOR_param_t * test, double **timer, int rep,
int access)
{
int shift;
if (access == WRITE) {
shift = 0;
} else { /* READ */
shift = 6;
}
DisplayOutliers(test->numTasks, timer[shift + 0][rep],
"start time", access, test->outlierThreshold);
DisplayOutliers(test->numTasks,
timer[shift + 1][rep] - timer[shift + 0][rep],
"elapsed create time", access, test->outlierThreshold);
DisplayOutliers(test->numTasks,
timer[shift + 3][rep] - timer[shift + 2][rep],
"elapsed transfer time", access,
test->outlierThreshold);
DisplayOutliers(test->numTasks,
timer[shift + 5][rep] - timer[shift + 4][rep],
"elapsed close time", access, test->outlierThreshold);
DisplayOutliers(test->numTasks, timer[shift + 5][rep], "end time",
access, test->outlierThreshold);
}
/*
* Check if actual file size equals expected size; if not use actual for
* calculating performance rate.
*/
static void CheckFileSize(IOR_test_t *test, IOR_offset_t dataMoved, int rep)
{
IOR_param_t *params = &test->params;
IOR_results_t *results = test->results;
MPI_CHECK(MPI_Allreduce(&dataMoved, &results->aggFileSizeFromXfer[rep],
1, MPI_LONG_LONG_INT, MPI_SUM, testComm),
"cannot total data moved");
if (strcmp(params->api, "HDF5") != 0 && strcmp(params->api, "NCMPI") != 0) {
if (verbose >= VERBOSE_0 && rank == 0) {
if ((params->expectedAggFileSize
!= results->aggFileSizeFromXfer[rep])
|| (results->aggFileSizeFromStat[rep]
!= results->aggFileSizeFromXfer[rep])) {
fprintf(stdout,
"WARNING: Expected aggregate file size = %lld.\n",
(long long) params->expectedAggFileSize);
fprintf(stdout,
"WARNING: Stat() of aggregate file size = %lld.\n",
(long long) results->aggFileSizeFromStat[rep]);
fprintf(stdout,
"WARNING: Using actual aggregate bytes moved = %lld.\n",
(long long) results->aggFileSizeFromXfer[rep]);
}
}
}
results->aggFileSizeForBW[rep] = results->aggFileSizeFromXfer[rep];
}
/*
* Compare buffers after reading/writing each transfer. Displays only first
* difference in buffers and returns total errors counted.
*/
static size_t
CompareBuffers(void *expectedBuffer,
void *unknownBuffer,
size_t size,
IOR_offset_t transferCount, IOR_param_t *test, int access)
{
char testFileName[MAXPATHLEN];
char bufferLabel1[MAX_STR];
char bufferLabel2[MAX_STR];
size_t i, j, length, first, last;
size_t errorCount = 0;
int inError = 0;
unsigned long long *goodbuf = (unsigned long long *)expectedBuffer;
unsigned long long *testbuf = (unsigned long long *)unknownBuffer;
if (access == WRITECHECK) {
strcpy(bufferLabel1, "Expected: ");
strcpy(bufferLabel2, "Actual: ");
} else if (access == READCHECK) {
strcpy(bufferLabel1, "1st Read: ");
strcpy(bufferLabel2, "2nd Read: ");
} else {
ERR("incorrect argument for CompareBuffers()");
}
length = size / sizeof(IOR_size_t);
first = -1;
if (verbose >= VERBOSE_3) {
fprintf(stdout,
"[%d] At file byte offset %lld, comparing %llu-byte transfer\n",
rank, test->offset, (long long)size);
}
for (i = 0; i < length; i++) {
if (testbuf[i] != goodbuf[i]) {
errorCount++;
if (verbose >= VERBOSE_2) {
fprintf(stdout,
"[%d] At transfer buffer #%lld, index #%lld (file byte offset %lld):\n",
rank, transferCount - 1, (long long)i,
test->offset +
(IOR_size_t) (i * sizeof(IOR_size_t)));
fprintf(stdout, "[%d] %s0x", rank, bufferLabel1);
fprintf(stdout, "%016llx\n", goodbuf[i]);
fprintf(stdout, "[%d] %s0x", rank, bufferLabel2);
fprintf(stdout, "%016llx\n", testbuf[i]);
}
if (!inError) {
inError = 1;
first = i;
last = i;
} else {
last = i;
}
} else if (verbose >= VERBOSE_5 && i % 4 == 0) {
fprintf(stdout,
"[%d] PASSED offset = %lld bytes, transfer %lld\n",
rank,
((i * sizeof(unsigned long long)) +
test->offset), transferCount);
fprintf(stdout, "[%d] GOOD %s0x", rank, bufferLabel1);
for (j = 0; j < 4; j++)
fprintf(stdout, "%016llx ", goodbuf[i + j]);
fprintf(stdout, "\n[%d] GOOD %s0x", rank, bufferLabel2);
for (j = 0; j < 4; j++)
fprintf(stdout, "%016llx ", testbuf[i + j]);
fprintf(stdout, "\n");
}
}
if (inError) {
inError = 0;
GetTestFileName(testFileName, test);
fprintf(stdout,
"[%d] FAILED comparison of buffer containing %d-byte ints:\n",
rank, (int)sizeof(unsigned long long int));
fprintf(stdout, "[%d] File name = %s\n", rank, testFileName);
fprintf(stdout, "[%d] In transfer %lld, ", rank,
transferCount);
fprintf(stdout,
"%lld errors between buffer indices %lld and %lld.\n",
(long long)errorCount, (long long)first,
(long long)last);
fprintf(stdout, "[%d] File byte offset = %lld:\n", rank,
((first * sizeof(unsigned long long)) + test->offset));
fprintf(stdout, "[%d] %s0x", rank, bufferLabel1);
for (j = first; j < length && j < first + 4; j++)
fprintf(stdout, "%016llx ", goodbuf[j]);
if (j == length)
fprintf(stdout, "[end of buffer]");
fprintf(stdout, "\n[%d] %s0x", rank, bufferLabel2);
for (j = first; j < length && j < first + 4; j++)
fprintf(stdout, "%016llx ", testbuf[j]);
if (j == length)
fprintf(stdout, "[end of buffer]");
fprintf(stdout, "\n");
if (test->quitOnError == TRUE)
ERR("data check error, aborting execution");
}
return (errorCount);
}
/*
* Count all errors across all tasks; report errors found.
*/
static int CountErrors(IOR_param_t * test, int access, int errors)
{
int allErrors = 0;
if (test->checkWrite || test->checkRead) {
MPI_CHECK(MPI_Reduce(&errors, &allErrors, 1, MPI_INT, MPI_SUM,
0, testComm), "cannot reduce errors");
MPI_CHECK(MPI_Bcast(&allErrors, 1, MPI_INT, 0, testComm),
"cannot broadcast allErrors value");
if (allErrors != 0) {
totalErrorCount += allErrors;
test->errorFound = TRUE;
}
if (rank == 0 && allErrors != 0) {
if (allErrors < 0) {
WARN("overflow in errors counted");
allErrors = -1;
}
fprintf(stdout, "WARNING: incorrect data on %s (%d errors found).\n",
access == WRITECHECK ? "write" : "read", allErrors);
fprintf(stdout,
"Used Time Stamp %u (0x%x) for Data Signature\n",
test->timeStampSignatureValue,
test->timeStampSignatureValue);
}
}
return (allErrors);
}
/*
* Compares hostnames to determine the number of tasks per node
*/
static int CountTasksPerNode(int numTasks, MPI_Comm comm)
{
char localhost[MAX_STR], hostname[MAX_STR], taskOnNode[MAX_STR];
int count = 1, resultsLen = MAX_STR, i;
static int firstPass = TRUE;
MPI_Status status;
MPI_CHECK(MPI_Get_processor_name(localhost, &resultsLen),
"cannot get processor name");
if (verbose >= VERBOSE_2 && firstPass) {
sprintf(taskOnNode, "task %d on %s", rank, localhost);
OutputToRoot(numTasks, comm, taskOnNode);
firstPass = FALSE;
}
if (numTasks > 1) {
if (rank == 0) {
/* MPI_receive all hostnames, and compare to local hostname */
for (i = 0; i < numTasks - 1; i++) {
MPI_CHECK(MPI_Recv
(hostname, MAX_STR, MPI_CHAR,
MPI_ANY_SOURCE, MPI_ANY_TAG, comm,
&status),
"cannot receive hostnames");
if (strcmp(hostname, localhost) == 0)
count++;
}
} else {
/* MPI_send hostname to root node */
MPI_CHECK(MPI_Send(localhost, MAX_STR, MPI_CHAR, 0, 0,
comm), "cannot send hostname");
}
MPI_CHECK(MPI_Bcast(&count, 1, MPI_INT, 0, comm),
"cannot broadcast tasks-per-node value");
}
return (count);
}
/*
* Allocate a page-aligned (required by O_DIRECT) buffer.
*/
static void *aligned_buffer_alloc(size_t size)
{
size_t pageSize;
size_t pageMask;
char *buf, *tmp;
char *aligned;
pageSize = getpagesize();
pageMask = pageSize - 1;
buf = malloc(size + pageSize + sizeof(void *));
if (buf == NULL)
ERR("out of memory");
/* find the alinged buffer */
tmp = buf + sizeof(char *);
aligned = tmp + pageSize - ((size_t) tmp & pageMask);
/* write a pointer to the original malloc()ed buffer into the bytes
preceding "aligned", so that the aligned buffer can later be free()ed */
tmp = aligned - sizeof(void *);
*(void **)tmp = buf;
return (void *)aligned;
}
/*
* Free a buffer allocated by aligned_buffer_alloc().
*/
static void aligned_buffer_free(void *buf)
{
free(*(void **)((char *)buf - sizeof(char *)));
}
void AllocResults(IOR_test_t *test)
{
int reps;
if (test->results != NULL)
return;
reps = test->params.repetitions;
test->results = (IOR_results_t *)malloc(sizeof(IOR_results_t));
if (test->results == NULL)
ERR("malloc of IOR_results_t failed");
test->results->writeTime = (double *)malloc(reps * sizeof(double));
if (test->results->writeTime == NULL)
ERR("malloc of writeTime array failed");
memset(test->results->writeTime, 0, reps * sizeof(double));
test->results->readTime = (double *)malloc(reps * sizeof(double));
if (test->results->readTime == NULL)
ERR("malloc of readTime array failed");
memset(test->results->readTime, 0, reps * sizeof(double));
test->results->aggFileSizeFromStat =
(IOR_offset_t *)malloc(reps * sizeof(IOR_offset_t));
if (test->results->aggFileSizeFromStat == NULL)
ERR("malloc of aggFileSizeFromStat failed");
test->results->aggFileSizeFromXfer =
(IOR_offset_t *)malloc(reps * sizeof(IOR_offset_t));
if (test->results->aggFileSizeFromXfer == NULL)
ERR("malloc of aggFileSizeFromXfer failed");
test->results->aggFileSizeForBW =
(IOR_offset_t *)malloc(reps * sizeof(IOR_offset_t));
if (test->results->aggFileSizeForBW == NULL)
ERR("malloc of aggFileSizeForBW failed");
}
void FreeResults(IOR_test_t *test)
{
if (test->results != NULL) {
free(test->results->aggFileSizeFromStat);
free(test->results->aggFileSizeFromXfer);
free(test->results->aggFileSizeForBW);
free(test->results->readTime);
free(test->results->writeTime);
free(test->results);
}
}
/*
* Create new test for list of tests.
*/
IOR_test_t *CreateTest(IOR_param_t *init_params, int test_num)
{
IOR_test_t *newTest = NULL;
newTest = (IOR_test_t *) malloc(sizeof(IOR_test_t));
if (newTest == NULL)
ERR("malloc() of IOR_test_t failed");
newTest->params = *init_params;
GetPlatformName(newTest->params.platform);
newTest->params.nodes = init_params->numTasks / tasksPerNode;
newTest->params.tasksPerNode = tasksPerNode;
newTest->params.id = test_num;
newTest->next = NULL;
newTest->results = NULL;
return newTest;
}
static void DestroyTest(IOR_test_t *test)
{
FreeResults(test);
free(test);
}
static void DestroyTests(IOR_test_t *tests_head)
{
IOR_test_t *tptr, *next;
for (tptr = tests_head; tptr != NULL; tptr = next) {
next = tptr->next;
DestroyTest(tptr);
}
}
/*
* Sleep for 'delay' seconds.
*/
static void DelaySecs(int delay)
{
if (rank == 0 && delay > 0) {
if (verbose >= VERBOSE_1)
fprintf(stdout, "delaying %d seconds . . .\n", delay);
sleep(delay);
}
}
/*
* Display freespace (df).
*/
static void DisplayFreespace(IOR_param_t * test)
{
char fileName[MAX_STR] = { 0 };
int i;
int directoryFound = FALSE;
/* get outfile name */
GetTestFileName(fileName, test);
/* get directory for outfile */
i = strlen(fileName);
while (i-- > 0) {
if (fileName[i] == '/') {
fileName[i] = '\0';
directoryFound = TRUE;
break;
}
}
/* if no directory/, use '.' */
if (directoryFound == FALSE) {
strcpy(fileName, ".");
}
ShowFileSystemSize(fileName);
return;
}
/*
* Display usage of script file.
*/
static void DisplayUsage(char **argv)
{
char *opts[] = {
"OPTIONS:",
" -a S api -- API for I/O [POSIX|MPIIO|HDF5|NCMPI]",
" -A N refNum -- user supplied reference number to include in the summary",
" -b N blockSize -- contiguous bytes to write per task (e.g.: 8, 4k, 2m, 1g)",
" -B useO_DIRECT -- uses O_DIRECT for POSIX, bypassing I/O buffers",
" -c collective -- collective I/O",
" -C reorderTasks -- changes task ordering to n+1 ordering for readback",
" -d N interTestDelay -- delay between reps in seconds",
" -D N deadlineForStonewalling -- seconds before stopping write or read phase",
" -e fsync -- perform fsync upon POSIX write close",
" -E useExistingTestFile -- do not remove test file before write access",
" -f S scriptFile -- test script name",
" -F filePerProc -- file-per-process",
" -g intraTestBarriers -- use barriers between open, write/read, and close",
" -G N setTimeStampSignature -- set value for time stamp signature",
" -h showHelp -- displays options and help",
" -H showHints -- show hints",
" -i N repetitions -- number of repetitions of test",
" -I individualDataSets -- datasets not shared by all procs [not working]",
" -j N outlierThreshold -- warn on outlier N seconds from mean",
" -J N setAlignment -- HDF5 alignment in bytes (e.g.: 8, 4k, 2m, 1g)",
" -k keepFile -- don't remove the test file(s) on program exit",
" -K keepFileWithError -- keep error-filled file(s) after data-checking",
" -l storeFileOffset -- use file offset as stored signature",
" -m multiFile -- use number of reps (-i) for multiple file count",
" -M N memoryPerNode -- hog memory on the node (e.g.: 2g, 75%)",
" -n noFill -- no fill in HDF5 file creation",
" -N N numTasks -- number of tasks that should participate in the test",
" -o S testFile -- full name for test",
" -O S string of IOR directives (e.g. -O checkRead=1,lustreStripeCount=32)",
" -p preallocate -- preallocate file size",
" -P useSharedFilePointer -- use shared file pointer [not working]",
" -q quitOnError -- during file error-checking, abort on error",
" -Q N taskPerNodeOffset for read tests use with -C & -Z options (-C constant N, -Z at least N)",
" -r readFile -- read existing file",
" -R checkRead -- check read after read",
" -s N segmentCount -- number of segments",
" -S useStridedDatatype -- put strided access into datatype [not working]",
" -t N transferSize -- size of transfer in bytes (e.g.: 8, 4k, 2m, 1g)",
" -T N maxTimeDuration -- max time in minutes for each test",
" -u uniqueDir -- use unique directory name for each file-per-process",
" -U S hintsFileName -- full name for hints file",
" -v verbose -- output information (repeating flag increases level)",
" -V useFileView -- use MPI_File_set_view",
" -w writeFile -- write file",
" -W checkWrite -- check read after write",
" -x singleXferAttempt -- do not retry transfer if incomplete",
" -X N reorderTasksRandomSeed -- random seed for -Z option",
" -Y fsyncPerWrite -- perform fsync after each POSIX write",
" -z randomOffset -- access is to random, not sequential, offsets within a file",
" -Z reorderTasksRandom -- changes task ordering to random ordering for readback",
" ",
" NOTE: S is a string, N is an integer number.",
" ",
""
};
int i = 0;
fprintf(stdout, "Usage: %s [OPTIONS]\n\n", *argv);
for (i = 0; strlen(opts[i]) > 0; i++)
fprintf(stdout, "%s\n", opts[i]);
return;
}
/*
* Distribute IOR_HINTs to all tasks' environments.
*/
void DistributeHints(void)
{
char hint[MAX_HINTS][MAX_STR], fullHint[MAX_STR], hintVariable[MAX_STR];
int hintCount = 0, i;
if (rank == 0) {
for (i = 0; environ[i] != NULL; i++) {
if (strncmp(environ[i], "IOR_HINT", strlen("IOR_HINT"))
== 0) {
hintCount++;
if (hintCount == MAX_HINTS) {
WARN("exceeded max hints; reset MAX_HINTS and recompile");
hintCount = MAX_HINTS;
break;
}
/* assume no IOR_HINT is greater than MAX_STR in length */
strncpy(hint[hintCount - 1], environ[i],
MAX_STR - 1);
}
}
}
MPI_CHECK(MPI_Bcast(&hintCount, sizeof(hintCount), MPI_BYTE,
0, MPI_COMM_WORLD), "cannot broadcast hints");
for (i = 0; i < hintCount; i++) {
MPI_CHECK(MPI_Bcast(&hint[i], MAX_STR, MPI_BYTE,
0, MPI_COMM_WORLD),
"cannot broadcast hints");
strcpy(fullHint, hint[i]);
strcpy(hintVariable, strtok(fullHint, "="));
if (getenv(hintVariable) == NULL) {
/* doesn't exist in this task's environment; better set it */
if (putenv(hint[i]) != 0)
WARN("cannot set environment variable");
}
}
}
/*
* Fill buffer, which is transfer size bytes long, with known 8-byte long long
* int values. In even-numbered 8-byte long long ints, store MPI task in high
* bits and timestamp signature in low bits. In odd-numbered 8-byte long long
* ints, store transfer offset. If storeFileOffset option is used, the file
* (not transfer) offset is stored instead.
*/
static void
FillBuffer(void *buffer,
IOR_param_t * test, unsigned long long offset, int fillrank)
{
size_t i;
unsigned long long hi, lo;
unsigned long long *buf = (unsigned long long *)buffer;
hi = ((unsigned long long)fillrank) << 32;
lo = (unsigned long long)test->timeStampSignatureValue;
for (i = 0; i < test->transferSize / sizeof(unsigned long long); i++) {
if ((i % 2) == 0) {
/* evens contain MPI rank and time in seconds */
buf[i] = hi | lo;
} else {
/* odds contain offset */
buf[i] = offset + (i * sizeof(unsigned long long));
}
}
}
/*
* Return string describing machine name and type.
*/
void GetPlatformName(char *platformName)
{
char nodeName[MAX_STR], *p, *start, sysName[MAX_STR];
struct utsname name;
if (uname(&name) != 0) {
EWARN("cannot get platform name");
sprintf(sysName, "%s", "Unknown");
sprintf(nodeName, "%s", "Unknown");
} else {
sprintf(sysName, "%s", name.sysname);
sprintf(nodeName, "%s", name.nodename);
}
start = nodeName;
if (strlen(nodeName) == 0) {
p = start;
} else {
/* point to one character back from '\0' */
p = start + strlen(nodeName) - 1;
}
/*
* to cut off trailing node number, search backwards
* for the first non-numeric character
*/
while (p != start) {
if (*p < '0' || *p > '9') {
*(p + 1) = '\0';
break;
} else {
p--;
}
}
sprintf(platformName, "%s(%s)", nodeName, sysName);
}
/*
* Return test file name to access.
* for single shared file, fileNames[0] is returned in testFileName
*/
static void GetTestFileName(char *testFileName, IOR_param_t * test)
{
char **fileNames,
initialTestFileName[MAXPATHLEN],
testFileNameRoot[MAX_STR], tmpString[MAX_STR];
int count;
/* parse filename for multiple file systems */
strcpy(initialTestFileName, test->testFileName);
fileNames = ParseFileName(initialTestFileName, &count);
if (count > 1 && test->uniqueDir == TRUE)
ERR("cannot use multiple file names with unique directories");
if (test->filePerProc) {
strcpy(testFileNameRoot,
fileNames[((rank +
rankOffset) % test->numTasks) % count]);
} else {
strcpy(testFileNameRoot, fileNames[0]);
}
/* give unique name if using multiple files */
if (test->filePerProc) {
/*
* prepend rank subdirectory before filename
* e.g., /dir/file => /dir/<rank>/file
*/
if (test->uniqueDir == TRUE) {
strcpy(testFileNameRoot,
PrependDir(test, testFileNameRoot));
}
sprintf(testFileName, "%s.%08d", testFileNameRoot,
(rank + rankOffset) % test->numTasks);
} else {
strcpy(testFileName, testFileNameRoot);
}
/* add suffix for multiple files */
if (test->repCounter > -1) {
sprintf(tmpString, ".%d", test->repCounter);
strcat(testFileName, tmpString);
}
}
/*
* Get time stamp. Use MPI_Timer() unless _NO_MPI_TIMER is defined,
* in which case use gettimeofday().
*/
static double GetTimeStamp(void)
{
double timeVal;
#ifdef _NO_MPI_TIMER
struct timeval timer;
if (gettimeofday(&timer, (struct timezone *)NULL) != 0)
ERR("cannot use gettimeofday()");
timeVal = (double)timer.tv_sec + ((double)timer.tv_usec / 1000000);
#else /* not _NO_MPI_TIMER */
timeVal = MPI_Wtime(); /* no MPI_CHECK(), just check return value */
if (timeVal < 0)
ERR("cannot use MPI_Wtime()");
#endif /* _NO_MPI_TIMER */
/* wall_clock_delta is difference from root node's time */
timeVal -= wall_clock_delta;
return (timeVal);
}
/*
* Convert IOR_offset_t value to human readable string.
*/
static char *HumanReadable(IOR_offset_t value, int base)
{
char *valueStr;
int m = 0, g = 0;
char m_str[8], g_str[8];
valueStr = (char *)malloc(MAX_STR);
if (valueStr == NULL)
ERR("out of memory");
if (base == BASE_TWO) {
m = MEBIBYTE;
g = GIBIBYTE;
strcpy(m_str, "MiB");
strcpy(g_str, "GiB");
} else if (base == BASE_TEN) {
m = MEGABYTE;
g = GIGABYTE;
strcpy(m_str, "MB");
strcpy(g_str, "GB");
}
if (value >= g) {
if (value % (IOR_offset_t) g) {
sprintf(valueStr, "%.2f %s",
(double)((double)value / g), g_str);
} else {
sprintf(valueStr, "%d %s", (int)(value / g), g_str);
}
} else if (value >= m) {
if (value % (IOR_offset_t) m) {
sprintf(valueStr, "%.2f %s",
(double)((double)value / m), m_str);
} else {
sprintf(valueStr, "%d %s", (int)(value / m), m_str);
}
} else if (value >= 0) {
sprintf(valueStr, "%d bytes", (int)value);
} else {
sprintf(valueStr, "-");
}
return valueStr;
}
/*
* Parse file name.
*/
static char **ParseFileName(char *name, int *count)
{
char **fileNames, *tmp, *token;
char delimiterString[3] = { FILENAME_DELIMITER, '\n', '\0' };
int i = 0;
*count = 0;
tmp = name;
/* pass one */
/* if something there, count the first item */
if (*tmp != '\0') {
(*count)++;
}
/* count the rest of the filenames */
while (*tmp != '\0') {
if (*tmp == FILENAME_DELIMITER) {
(*count)++;
}
tmp++;
}
fileNames = (char **)malloc((*count) * sizeof(char **));
if (fileNames == NULL)
ERR("out of memory");
/* pass two */
token = strtok(name, delimiterString);
while (token != NULL) {
fileNames[i] = token;
token = strtok(NULL, delimiterString);
i++;
}
return (fileNames);
}
/*
* Pretty Print a Double. The First parameter is a flag determining if left
* justification should be used. The third parameter a null-terminated string
* that should be appended to the number field.
*/
static void PPDouble(int leftjustify, double number, char *append)
{