Back to index

numactl  2.0.8~rc4
Defines | Functions | Variables
stream_lib.c File Reference
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <sys/time.h>
#include <stdlib.h>
#include "stream_lib.h"

Go to the source code of this file.

Defines

#define NTIMES   10
#define OFFSET   0
#define HLINE   "-------------------------------------------------------------\n"
#define MIN(x, y)   ((x)<(y)?(x):(y))
#define MAX(x, y)   ((x)>(y)?(x):(y))
#define Vprintf(x...)   do { if (stream_verbose) printf(x); } while(0)
#define M   20

Functions

static double mysecond ()
int checktick ()
void stream_check (void)
void stream_test (double *res)
void stream_setmem (unsigned long size)
long stream_memsize (void)
long stream_init (void *mem)

Variables

long N = 8000000
static double * a
static double * b
static double * c
static double rmstime [4] = { 0 }
static double maxtime [4]
static double mintime [4]
static char * label [4]
char * stream_names [] = { "Copy","Scale","Add","Triad" }
static double bytes [4]
int stream_verbose = 1

Define Documentation

#define HLINE   "-------------------------------------------------------------\n"

Definition at line 65 of file stream_lib.c.

#define M   20

Definition at line 206 of file stream_lib.c.

#define MAX (   x,
 
)    ((x)>(y)?(x):(y))

Definition at line 71 of file stream_lib.c.

#define MIN (   x,
 
)    ((x)<(y)?(x):(y))

Definition at line 68 of file stream_lib.c.

#define NTIMES   10

Definition at line 39 of file stream_lib.c.

#define OFFSET   0

Definition at line 40 of file stream_lib.c.

#define Vprintf (   x...)    do { if (stream_verbose) printf(x); } while(0)

Definition at line 89 of file stream_lib.c.


Function Documentation

int checktick ( )

Definition at line 208 of file stream_lib.c.

{
       int i, minDelta, Delta;
       double t1, t2, timesfound[M];

/*  Collect a sequence of M unique time values from the system. */

       for (i = 0; i < M; i++) {
              t1 = mysecond();
              while (((t2 = mysecond()) - t1) < 1.0E-6);
              timesfound[i] = t1 = t2;
       }

/*
 * Determine the minimum difference between these M values.
 * This result will be our estimate (in microseconds) for the
 * clock granularity.
 */

       minDelta = 1000000;
       for (i = 1; i < M; i++) {
              Delta =
                  (int) (1.0E6 * (timesfound[i] - timesfound[i - 1]));
              minDelta = MIN(minDelta, MAX(Delta, 0));
       }

       return (minDelta);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double mysecond ( ) [inline, static]

Definition at line 9 of file stream_lib.c.

{
       struct timeval tv;
       gettimeofday(&tv, NULL);
       return tv.tv_sec + tv.tv_usec * 1.e-6;
}

Here is the caller graph for this function:

void stream_check ( void  )

Definition at line 91 of file stream_lib.c.

{
       int quantum;
       int BytesPerWord;
       register int j;
       double t;

       /* --- SETUP --- determine precision and check timing --- */

       Vprintf(HLINE);
       BytesPerWord = sizeof(double);
       Vprintf("This system uses %d bytes per DOUBLE PRECISION word.\n",
              BytesPerWord);

       Vprintf(HLINE);
       Vprintf("Array size = %lu, Offset = %d\n", N, OFFSET);
       Vprintf("Total memory required = %.1f MB.\n",
              (3 * N * BytesPerWord) / 1048576.0);
       Vprintf("Each test is run %d times, but only\n", NTIMES);
       Vprintf("the *best* time for each is used.\n");

       /* Get initial value for system clock. */

       for (j = 0; j < N; j++) {
              a[j] = 1.0;
              b[j] = 2.0;
              c[j] = 0.0;
       }

       Vprintf(HLINE);

       if ((quantum = checktick()) >= 1)
              Vprintf("Your clock granularity/precision appears to be "
                     "%d microseconds.\n", quantum);
       else
              Vprintf("Your clock granularity appears to be "
                     "less than one microsecond.\n");

       t = mysecond();
       for (j = 0; j < N; j++)
              a[j] = 2.0E0 * a[j];
       t = 1.0E6 * (mysecond() - t);

       Vprintf("Each test below will take on the order"
              " of %d microseconds.\n", (int) t);
       Vprintf("   (= %d clock ticks)\n", (int) (t / quantum));
       Vprintf("Increase the size of the arrays if this shows that\n");
       Vprintf("you are not getting at least 20 clock ticks per test.\n");

       Vprintf(HLINE);

       Vprintf("WARNING -- The above is only a rough guideline.\n");
       Vprintf("For best results, please be sure you know the\n");
       Vprintf("precision of your system timer.\n");
       Vprintf(HLINE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long stream_init ( void *  mem)

Definition at line 247 of file stream_lib.c.

{
       int i;

       for (i = 0; i < 4; i++) {
              rmstime[i] = 0;
              maxtime[i] = 0;
              mintime[i] = FLT_MAX;
       }

       bytes[0] = 2 * sizeof(double) * N;
       bytes[1] = 2 * sizeof(double) * N;
       bytes[2] = 3 * sizeof(double) * N;
       bytes[3] = 3 * sizeof(double) * N;

       a = mem;
       b = (double *)mem +   (N+OFFSET);
       c = (double *)mem + 2*(N+OFFSET);
       stream_check();
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

long stream_memsize ( void  )

Definition at line 242 of file stream_lib.c.

{
       return 3*(sizeof(double) * (N+OFFSET)) ;
}

Here is the caller graph for this function:

void stream_setmem ( unsigned long  size)

Definition at line 237 of file stream_lib.c.

{
       N = (size - OFFSET) / (3*sizeof(double));
}

Here is the caller graph for this function:

void stream_test ( double *  res)

Definition at line 148 of file stream_lib.c.

{
       register int j, k;
       double scalar, times[4][NTIMES];

       /*  --- MAIN LOOP --- repeat test cases NTIMES times --- */

       scalar = 3.0;
       for (k = 0; k < NTIMES; k++) {
              times[0][k] = mysecond();
              for (j = 0; j < N; j++)
                     c[j] = a[j];
              times[0][k] = mysecond() - times[0][k];

              times[1][k] = mysecond();
              for (j = 0; j < N; j++)
                     b[j] = scalar * c[j];
              times[1][k] = mysecond() - times[1][k];

              times[2][k] = mysecond();
              for (j = 0; j < N; j++)
                     c[j] = a[j] + b[j];
              times[2][k] = mysecond() - times[2][k];

              times[3][k] = mysecond();
              for (j = 0; j < N; j++)
                     a[j] = b[j] + scalar * c[j];
              times[3][k] = mysecond() - times[3][k];
       }

       /*  --- SUMMARY --- */

       for (k = 0; k < NTIMES; k++) {
              for (j = 0; j < 4; j++) {
                     rmstime[j] =
                         rmstime[j] + (times[j][k] * times[j][k]);
                     mintime[j] = MIN(mintime[j], times[j][k]);
                     maxtime[j] = MAX(maxtime[j], times[j][k]);
              }
       }

       Vprintf
           ("Function      Rate (MB/s)   RMS time     Min time     Max time\n");
       for (j = 0; j < 4; j++) {
              double speed = 1.0E-06 * bytes[j] / mintime[j];

              rmstime[j] = sqrt(rmstime[j] / (double) NTIMES);

              Vprintf("%s%11.4f  %11.4f  %11.4f  %11.4f\n", label[j],
                     speed,
                     rmstime[j], mintime[j], maxtime[j]);

              if (res)
                     res[j] = speed;

       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

double* a [static]

Definition at line 74 of file stream_lib.c.

double * b [static]

Definition at line 74 of file stream_lib.c.

double bytes[4] [static]

Definition at line 85 of file stream_lib.c.

double * c [static]

Definition at line 74 of file stream_lib.c.

char* label[4] [static]
Initial value:
 { "Copy:      ", "Scale:     ",
       "Add:       ", "Triad:     "
}

Definition at line 80 of file stream_lib.c.

double maxtime[4] [static]
Initial value:
 {
0}

Definition at line 76 of file stream_lib.c.

double mintime[4] [static]
Initial value:
 {
FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX}

Definition at line 77 of file stream_lib.c.

long N = 8000000

Definition at line 38 of file stream_lib.c.

double rmstime[4] = { 0 } [static]

Definition at line 76 of file stream_lib.c.

char* stream_names[] = { "Copy","Scale","Add","Triad" }

Definition at line 83 of file stream_lib.c.

int stream_verbose = 1

Definition at line 87 of file stream_lib.c.