Skip to content

Commit

Permalink
Add support for memory limiting
Browse files Browse the repository at this point in the history
This change enables the user to set a memory limit at which the
benchmark is stopped. The limit is specified in megabytes as the first
parameter to the benchmark executable. The documentation has been
updated accordingly.
  • Loading branch information
Brian "DragonLord" Wong authored and Brian "DragonLord" Wong committed Dec 28, 2014
1 parent 6a8fc6f commit 9e73a6f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,22 @@ may be set this way include `ADVANCE`, `NCHUNK`, `NTRIAL`, `PATIENCE`, `RUNTM`,

## Usage

HI64 saves its output to a directory whose name is determined by the first
parameter passed to it, prefixed by `data`. For example, if the parameter is
`foo`, it will attempt to write output to the directory called `datafoo`. The
name of the output file used is the same as the name by which the executable
was invoked. If no parameter is given, it will attempt to write to the directory
named `data`. If the directory does not exist, the benchmark will not run. (This
unusual output behavior was inherited from the original HINT code and will be
changed in a future release to make the program easier to use.)
The first parameter is used to set a memory limit in megabytes. The benchmark
will end when this memory limit is reached. If this value is zero, then no limit
is set. If no parameters are given, or if this parameter is invalid, no limit
will be set either.

The second parameter determines the name of the output directory, prefixed by `data`. For example, if the parameter is `foo`, it will attempt to write output
to the directory called `datafoo`. The name of the output file used is the same
as the name by which the executable was invoked. If there are fewer than two
parameters, it will attempt to write to the directory named `data`. If the
directory does not exist, the benchmark will not run. (This unusual output
behavior was inherited from the original HINT code and will be changed in a
future release to make the program easier to use.)

The program runs until the `STOPRT` or `STOPTM` thresholds are reached. This
generally means that the system will run out of memory and start swapping to
disk heavily before the benchmark is finished. A feature to stop the benchmark
after reaching a user-defined memory limit will be added in a future release.
disk heavily before the benchmark is finished.

## Interpreting output

Expand Down
26 changes: 21 additions & 5 deletions hi64.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ int main(int argc, char *argv[])
ibits, /* Number of bits for imax */
i, j, k, /* Loop counters */
laps, /* Approximate number of laps in a trial */
memuse; /* Amount of memory used, in bytes */
memuse, /* Amount of memory used, in bytes */
memuse2, /* Same as memuse, but for keeping track of memory */
/* usage during each loop for memory limiting */
memlimit; /* Memory limit */

char* suffix; /* Suffix for data.suffix directory */

Expand All @@ -91,12 +94,23 @@ int main(int argc, char *argv[])
printf("---------------------------------------------------------\n");
printf("RECT is %d bytes\n",sizeof(RECT));

if (argc >= 2) {
memlimit = (int64_t)strtol(argv[1], NULL, 10) * 1048576;
}
else
memlimit = 0x7fffffffffffffffLL;

if (memlimit <= 0)
memlimit = 0x7fffffffffffffffLL;
if (memlimit < 0x7fffffffffffffffLL)
printf("Memory use limited to %I64d MB\n", memlimit / 1048576 );

#ifdef DEBUG
curv = stdout;
#else
suffix="";
if (argc>=2) {
suffix=argv[1];
if (argc>=3) {
suffix=argv[2];
}
snprintf(filnm, 80, "data%s/%s", suffix, argv[0]);
if ((curv = fopen(filnm, "w")) == NULL)
Expand Down Expand Up @@ -200,8 +214,9 @@ int main(int argc, char *argv[])


/* This loop is the main loop driver of the HINT kernel. */
for (t = 0, i = 0, n = NMIN, qpeak = 0, qprat = 1;
((i < NSAMP) && (t < STOPTM) && (n < scx) && (qprat > STOPRT));
for (t = 0, i = 0, n = NMIN, qpeak = 0, qprat = 1, memuse2 = 0;
((i < NSAMP) && (t < STOPTM) && (n < scx) && (qprat > STOPRT)
&& (memuse2 < memlimit * ADVANCE));
i++, n = ((int64_t)(n * ADVANCE) > n)? (n * ADVANCE) : n + 1)
{
printf(".");
Expand All @@ -228,6 +243,7 @@ int main(int argc, char *argv[])
qdata[i].n = n;
qpeak = MAX(qpeak, quips);
qprat = quips / qpeak;
memuse2 = (int64_t)(qdata[i].n * (sizeof(RECT)+sizeof(DSIZE)+sizeof(ISIZE)));
}
memuse = (int64_t)(qdata[i-1].n * (sizeof(RECT)+sizeof(DSIZE)+sizeof(ISIZE)));
if ((qprat > STOPRT) && (eflag == NOMEM))
Expand Down

0 comments on commit 9e73a6f

Please sign in to comment.