Skip to content

Commit 03985ee

Browse files
committed
True random option added compared to shuffling when using -z -z.
1 parent ce2c1bd commit 03985ee

File tree

3 files changed

+68
-33
lines changed

3 files changed

+68
-33
lines changed

src/aiori-DUMMY.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static IOR_offset_t DUMMY_GetFileSize(aiori_mod_opt_t * options, char *testFileN
137137

138138
static IOR_offset_t DUMMY_Xfer(int access, aiori_fd_t *file, IOR_size_t * buffer, IOR_offset_t length, IOR_offset_t offset, aiori_mod_opt_t * options){
139139
if(verbose > 4){
140-
fprintf(out_logfile, "DUMMY xfer: %p\n", file);
140+
fprintf(out_logfile, "DUMMY %d xfer: %p, %lld, %lld\n", rank, file, offset, length);
141141
}
142142
dummy_options_t * o = (dummy_options_t*) options;
143143
if (o->delay_xfer){

src/ior.c

+66-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2-
* vim:expandtab:shiftwidth=8:tabstop=8:
1+
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2+
* vim:expandtab:shiftwidth=2:tabstop=2:
33
*/
44
/******************************************************************************\
55
* *
@@ -1401,6 +1401,9 @@ static void TestIoSys(IOR_test_t *test)
14011401
}
14021402
/* Using globally passed rankOffset, following function generates testFileName to read */
14031403
GetTestFileName(testFileName, params);
1404+
if(params->randomOffset > 1){
1405+
params->expectedAggFileSize = backend->get_file_size(params->backend_options, testFileName);
1406+
}
14041407

14051408
if (verbose >= VERBOSE_3) {
14061409
fprintf(out_logfile, "task %d reading %s\n", rank,
@@ -1520,7 +1523,7 @@ static void ValidateTests(IOR_param_t * test, MPI_Comm com)
15201523
}
15211524
if (test->blockSize < test->transferSize)
15221525
ERR("block size must not be smaller than transfer size");
1523-
if (test->randomOffset && test->blockSize == test->transferSize)
1526+
if (test->randomOffset == 1 && test->blockSize == test->transferSize)
15241527
ERR("IOR will randomize access within a block and repeats the same pattern for all segments, therefore choose blocksize > transferSize");
15251528
if (! test->randomOffset && test->randomPrefillBlocksize)
15261529
ERR("Setting the randomPrefill option without using random is not useful");
@@ -1583,6 +1586,33 @@ static void ValidateTests(IOR_param_t * test, MPI_Comm com)
15831586
}
15841587
}
15851588

1589+
static int init_random_seed(IOR_param_t * test, int pretendRank){
1590+
int seed;
1591+
if (test->filePerProc) {
1592+
/* set up seed, each process can determine which regions to access individually */
1593+
if (test->randomSeed == -1) {
1594+
seed = time(NULL);
1595+
test->randomSeed = seed;
1596+
} else {
1597+
seed = test->randomSeed + pretendRank;
1598+
}
1599+
}else{
1600+
/* Shared file requires that the seed is synchronized */
1601+
if (test->randomSeed == -1) {
1602+
// all processes need to have the same seed.
1603+
if(rank == 0){
1604+
seed = time(NULL);
1605+
}
1606+
MPI_CHECK(MPI_Bcast(& seed, 1, MPI_INT, 0, test->testComm), "cannot broadcast random seed value");
1607+
test->randomSeed = seed;
1608+
}else{
1609+
seed = test->randomSeed;
1610+
}
1611+
}
1612+
srandom(seed);
1613+
return seed;
1614+
}
1615+
15861616
/**
15871617
* Returns a precomputed array of IOR_offset_t for the inner benchmark loop.
15881618
* They get created sequentially and mixed up in the end.
@@ -1604,28 +1634,7 @@ IOR_offset_t *GetOffsetArrayRandom(IOR_param_t * test, int pretendRank, IOR_offs
16041634
IOR_offset_t offsetCnt = 0;
16051635
IOR_offset_t *offsetArray;
16061636

1607-
if (test->filePerProc) {
1608-
/* set up seed, each process can determine which regions to access individually */
1609-
if (test->randomSeed == -1) {
1610-
seed = time(NULL);
1611-
test->randomSeed = seed;
1612-
} else {
1613-
seed = test->randomSeed + pretendRank;
1614-
}
1615-
}else{
1616-
/* Shared file requires that the seed is synchronized */
1617-
if (test->randomSeed == -1) {
1618-
// all processes need to have the same seed.
1619-
if(rank == 0){
1620-
seed = time(NULL);
1621-
}
1622-
MPI_CHECK(MPI_Bcast(& seed, 1, MPI_INT, 0, test->testComm), "cannot broadcast random seed value");
1623-
test->randomSeed = seed;
1624-
}else{
1625-
seed = test->randomSeed;
1626-
}
1627-
}
1628-
srandom(seed);
1637+
seed = init_random_seed(test, pretendRank);
16291638

16301639
/* count needed offsets (pass 1) */
16311640
if (test->filePerProc) {
@@ -1766,11 +1775,15 @@ static IOR_offset_t WriteOrRead(IOR_param_t *test, int rep, IOR_results_t *resul
17661775

17671776
IOR_offset_t offsets;
17681777
IOR_offset_t * offsets_rnd;
1769-
if (test->randomOffset) {
1778+
if (test->randomOffset == 1) {
17701779
offsets_rnd = GetOffsetArrayRandom(test, pretendRank, & offsets);
17711780
}else{
17721781
offsets = (test->blockSize / test->transferSize);
17731782
}
1783+
if (test->randomOffset > 1){
1784+
int seed = init_random_seed(test, pretendRank);
1785+
srand(seed + pretendRank);
1786+
}
17741787

17751788
void * randomPrefillBuffer = NULL;
17761789
if(test->randomPrefillBlocksize && (access == WRITE || access == WRITECHECK)){
@@ -1799,9 +1812,9 @@ static IOR_offset_t WriteOrRead(IOR_param_t *test, int rep, IOR_results_t *resul
17991812
// must synchronize processes to ensure they are not running ahead
18001813
MPI_Barrier(test->testComm);
18011814
}
1802-
18031815
do{ // to ensure the benchmark runs a certain time
18041816
for (i = 0; i < test->segmentCount && !hitStonewall; i++) {
1817+
IOR_offset_t offset;
18051818
if(randomPrefillBuffer && test->deadlineForStonewalling != 0){
18061819
// prefill the whole segment with data, this needs to be done collectively
18071820
double t_start = GetTimeStamp();
@@ -1811,14 +1824,27 @@ static IOR_offset_t WriteOrRead(IOR_param_t *test, int rep, IOR_results_t *resul
18111824
fprintf(out_logfile, "Random: synchronizing segment count with barrier and prefill took: %fs\n", GetTimeStamp() - t_start);
18121825
}
18131826
}
1827+
if (test->randomOffset > 1){
1828+
size_t sizerand = test->expectedAggFileSize;
1829+
if(test->filePerProc){
1830+
sizerand /= test->numTasks;
1831+
}
1832+
offset = rand() % (sizerand / test->blockSize) * test->blockSize - test->transferSize;
1833+
if(i == 0 && access == WRITE){ // always write the last block first
1834+
if(test->filePerProc || rank == 0){
1835+
offset = (sizerand / test->blockSize - 1) * test->blockSize - test->transferSize;
1836+
}
1837+
}
1838+
}
18141839
for (j = 0; j < offsets && !hitStonewall ; j++) {
1815-
IOR_offset_t offset;
1816-
if (test->randomOffset) {
1840+
if (test->randomOffset == 1) {
18171841
if(test->filePerProc){
18181842
offset = offsets_rnd[j] + (i * test->blockSize);
18191843
}else{
18201844
offset = offsets_rnd[j] + (i * test->numTasks * test->blockSize);
18211845
}
1846+
}else if (test->randomOffset > 1){
1847+
offset += test->transferSize;
18221848
}else{
18231849
offset = j * test->transferSize;
18241850
if (test->filePerProc) {
@@ -1873,15 +1899,24 @@ static IOR_offset_t WriteOrRead(IOR_param_t *test, int rep, IOR_results_t *resul
18731899
i++;
18741900
}
18751901
for ( ; pairCnt < point->pairs_accessed; i++) {
1902+
IOR_offset_t offset;
18761903
if(i == test->segmentCount) i = 0; // wrap over, necessary to deal with minTimeDuration
1904+
if (test->randomOffset > 1){
1905+
size_t sizerand = test->expectedAggFileSize;
1906+
if(test->filePerProc){
1907+
sizerand /= test->numTasks;
1908+
}
1909+
offset = rand() % (sizerand / test->blockSize) * test->blockSize - test->transferSize;
1910+
}
18771911
for ( ; j < offsets && pairCnt < point->pairs_accessed ; j++) {
1878-
IOR_offset_t offset;
1879-
if (test->randomOffset) {
1912+
if (test->randomOffset == 1) {
18801913
if(test->filePerProc){
18811914
offset = offsets_rnd[j] + (i * test->blockSize);
18821915
}else{
18831916
offset = offsets_rnd[j] + (i * test->numTasks * test->blockSize);
18841917
}
1918+
}else if (test->randomOffset > 1){
1919+
offset += test->transferSize;
18851920
}else{
18861921
offset = j * test->transferSize;
18871922
if (test->filePerProc) {

src/parse_options.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ option_help * createGlobalOptions(IOR_param_t * params){
467467
{'X', NULL, "reorderTasksRandomSeed -- random seed for -Z option", OPTION_OPTIONAL_ARGUMENT, 'd', & params->reorderTasksRandomSeed},
468468
{'y', NULL, "dualMount -- use dual mount points for a filesystem", OPTION_FLAG, 'd', & params->dualMount},
469469
{'Y', NULL, "fsyncPerWrite -- perform sync operation after every write operation", OPTION_FLAG, 'd', & params->fsyncPerWrite},
470-
{'z', NULL, "randomOffset -- access is to random, not sequential, offsets within a file", OPTION_FLAG, 'd', & params->randomOffset},
470+
{'z', NULL, "randomOffset -- access is to shuffled, not sequential, offsets within a file, specify twice for random (potentially overlapping)", OPTION_FLAG, 'd', & params->randomOffset},
471471
{0, "randomPrefill", "For random -z access only: Prefill the file with this blocksize, e.g., 2m", OPTION_OPTIONAL_ARGUMENT, 'l', & params->randomPrefillBlocksize},
472472
{0, "random-offset-seed", "The seed for -z", OPTION_OPTIONAL_ARGUMENT, 'd', & params->randomSeed},
473473
{'Z', NULL, "reorderTasksRandom -- changes task ordering to random select regions for readback, use twice for shuffling", OPTION_FLAG, 'd', & params->reorderTasksRandom},

0 commit comments

Comments
 (0)