Stream for Windows

From: Michael Lancop <MichaelandShoSho@Yahoo.com>
Date: Thu May 15 2008 - 22:40:32 CDT

Dr. McCalpin:

  I was analyzing your memory bandwidth program, Stream. When it
occured to me that it would make a great Windows program.

  I have attatched the ported Windows source code as well as an
Intel86 executable.

  The following is a summary of a test run of the software:

Computer : MSI MS-6754
Chipset : 845GL 400 Mhz FSB
CPU : Intel Pentium 4 2.6 Ghz 512K Cache
Memory : 1 Gb PC133
OS : Windows 2000 Adv. Serv. SP4

Project Options:
                /nologo /G6 /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG"
                /D "_CONSOLE" /D "_MBCS" /Fp"Release/Stream.pch"
                /YX /Fo"Release/" /Fd"Release/" /FD /c

---------------------------------------------------------------
STREAM for Windows version 5.8w.
---------------------------------------------------------------
This system uses 8 bytes per DOUBLE PRECISION word.
---------------------------------------------------------------
Array size = 2000000, Offset = 0
Total memory required = 45.8 MB.
Each test is run 10 times, but only
the *best* time for each is used.
---------------------------------------------------------------
Your clock granularity/precision appears to be 0.279 microseconds.
Each test below will take on the order of 42893.7 microseconds.
   (= 153540 clock ticks)
Increase the size of the arrays if this shows that
you are not getting at least 20 clock ticks per test.
---------------------------------------------------------------
Function Rate (MB/s) Avg time Min time Max time
Copy: 510.8003 0.0628 0.0626 0.0630
Scale: 536.4121 0.0600 0.0597 0.0611
Add: 593.3993 0.0810 0.0809 0.0814
Triad: 590.9075 0.0814 0.0812 0.0819
---------------------------------------------------------------
Results Comparison:

   a[] Expected : 2306601562499999700.000000
        Observed : 2306601562499999700.000000

   b[] Expected : 461320312500000000.000000
        Observed : 461320312500000000.000000

   c[] Expected : 615093750000000000.000000
        Observed : 615093750000000000.000000

Clock ticks per second : 3579545.

Solution Validates.
---------------------------------------------------------------

Sincerely

  Michael

Michael Lancop
36 Government Rd.
Larder Lake, Ont.
(705)643-2133
MichaelandShoSho@Yahoo.com

/*-----------------------------------------------------------------------*/
/* Program: Stream */
/* Revision: $Id: stream.c,v 5.8 2007/02/19 23:57:39 mccalpin Exp mccalpin $ */
/* Original code developed by John D. McCalpin */
/* Programmers: John D. McCalpin */
/* Joe R. Zagar */
/* */
/* This program measures memory transfer rates in MB/s for simple */
/* computational kernels coded in C. */
/*-----------------------------------------------------------------------*/
/* Copyright 1991-2005: John D. McCalpin */
/*-----------------------------------------------------------------------*/
/* License: */
/* 1. You are free to use this program and/or to redistribute */
/* this program. */
/* 2. You are free to modify this program for your own use, */
/* including commercial use, subject to the publication */
/* restrictions in item 3. */
/* 3. You are free to publish results obtained from running this */
/* program, or from works that you derive from this program, */
/* with the following limitations: */
/* 3a. In order to be referred to as "STREAM benchmark results", */
/* published results must be in conformance to the STREAM */
/* Run Rules, (briefly reviewed below) published at */
/* http://www.cs.virginia.edu/stream/ref.html */
/* and incorporated herein by reference. */
/* As the copyright holder, John McCalpin retains the */
/* right to determine conformity with the Run Rules. */
/* 3b. Results based on modified source code or on runs not in */
/* accordance with the STREAM Run Rules must be clearly */
/* labelled whenever they are published. Examples of */
/* proper labelling include: */
/* "tuned STREAM benchmark results" */
/* "based on a variant of the STREAM benchmark code" */
/* Other comparable, clear and reasonable labelling is */
/* acceptable. */
/* 3c. Submission of results to the STREAM benchmark web site */
/* is encouraged, but not required. */
/* 4. Use of this program or creation of derived works based on this */
/* program constitutes acceptance of these licensing restrictions. */
/* 5. Absolutely no warranty is expressed or implied. */
/*-----------------------------------------------------------------------*/
/* */
/* Ported to Windows' Visual Studio 6 by Michael Lancop May 15,2008. */
/* Email : MichaelandShoSho@Yahoo.com */
/* Project Options: */
/* /nologo /G6 /ML /W3 /GX /O2 /D "WIN32" /D "NDEBUG" */
/* /D "_CONSOLE" /D "_MBCS" /Fp"Release/Stream.pch" */
/* /YX /Fo"Release/" /Fd"Release/" /FD /c */
/* */
/*-----------------------------------------------------------------------*/

#include<windows.h>
#include<stdio.h>
#include<float.h>
#include<limits.h>

/* INSTRUCTIONS:
 *
 * 1) Stream requires a good bit of memory to run. Adjust the
 * value of 'N' (below) to give a 'timing calibration' of
 * at least 20 clock-ticks. This will provide rate estimates
 * that should be good to about 5% precision.
 */

#define VERBOSE
#define N 2000000
#define NTIMES 10
#define OFFSET 0

/*
 * 3) Compile the code with full optimization. Many compilers
 * generate unreasonably bad code before the optimizer tightens
 * things up. If the results are unreasonably good, on the
 * other hand, the optimizer might be too smart for me!
 *
 * Try compiling with:
 * cc -O stream_omp.c -o stream_omp
 *
 * This is known to work on Cray, SGI, IBM, and Sun machines.
 *
 *
 * 4) Mail the results to mccalpin@cs.virginia.edu
 * Be sure to include:
 * a) computer hardware model number and software revision
 * b) the compiler flags
 * c) all of the output from the test case.
 * Thanks!
 *
 */

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

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

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

static double a[N+OFFSET],
                b[N+OFFSET],
                c[N+OFFSET],

                avgtime[4]={0},
                maxtime[4]={0},
                mintime[4]={FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};

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

static double bytes[4]={
                          2*sizeof(double)*N,
                          2*sizeof(double)*N,
                          3*sizeof(double)*N,
                          3*sizeof(double)*N
                         };

void checkSTREAMresults(__int64);

int main(void)
 {

  int BytesPerWord;

  register int j,
                  k;

  double scalar,
                  t,
                  times[4][NTIMES];

  __int64 beginTime64,
                  endTime64,
                  ticks,
                  ticksPerSecond;

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

// _controlfp(PC_24,MCW_PC); // fpu 24bit precision.
// _controlfp(PC_53,MCW_PC); // fpu 53bit precision (Windows default).
  _controlfp(PC_64,MCW_PC); // fpu 64bit precision.

  printf(HLINE);
  printf("STREAM for Windows version 5.8w.\n");
  printf(HLINE);
  BytesPerWord=sizeof(double);
  printf("This system uses %d bytes per DOUBLE PRECISION word.\n",BytesPerWord);
  printf(HLINE);
  printf("Array size = %d, Offset = %d\n" , N, OFFSET);
  printf("Total memory required = %.1f MB.\n",(3.0*BytesPerWord)*((double)N/1048576.0));
  printf("Each test is run %d times, but only\n",NTIMES);
  printf("the *best* time for each is used.\n");

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

  printf(HLINE);

  /* Get initial value for system clock. */

  QueryPerformanceFrequency((LARGE_INTEGER*)&ticksPerSecond);
  t=1/(double)ticksPerSecond*1.0E6;
  printf("Your clock granularity/precision appears to be %.3f microseconds.\n",t);

  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
  QueryPerformanceCounter((LARGE_INTEGER*)&beginTime64);
  for(j=0;j<N;j++) a[j]=2.0E0*a[j];
  QueryPerformanceCounter((LARGE_INTEGER*)&endTime64);
  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);

  ticks=endTime64-beginTime64;
  t=(double)ticks/(double)ticksPerSecond*1.0E6;
  printf("Each test below will take on the order of %g microseconds.\n",t);
  printf(" (= %I64d clock ticks)\n",ticks);
  printf("Increase the size of the arrays if this shows that\n");
  printf("you are not getting at least 20 clock ticks per test.\n");
  printf(HLINE);

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

  scalar=3.0;
  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL);
  for(k=0;k<NTIMES;k++)
   {

  /* --- Copy --- */

    QueryPerformanceCounter((LARGE_INTEGER*)&beginTime64);
    for(j=0;j<N;j++) c[j]=a[j];
    QueryPerformanceCounter((LARGE_INTEGER*)&endTime64);
    ticks=endTime64-beginTime64;
    times[0][k]=(double)ticks/(double)ticksPerSecond;

  /* --- Scale --- */

    QueryPerformanceCounter((LARGE_INTEGER*)&beginTime64);
    for(j=0;j<N;j++) b[j]=scalar*c[j];
    QueryPerformanceCounter((LARGE_INTEGER*)&endTime64);
    ticks=endTime64-beginTime64;
    times[1][k]=(double)ticks/(double)ticksPerSecond;

  /* --- Add --- */

    QueryPerformanceCounter((LARGE_INTEGER*)&beginTime64);
    for(j=0;j<N;j++) c[j]=a[j]+b[j];
    QueryPerformanceCounter((LARGE_INTEGER*)&endTime64);
    ticks=endTime64-beginTime64;
    times[2][k]=(double)ticks/(double)ticksPerSecond;

  /* --- Triad --- */

    QueryPerformanceCounter((LARGE_INTEGER*)&beginTime64);
    for(j=0;j<N;j++) a[j]=b[j]+scalar*c[j];
    QueryPerformanceCounter((LARGE_INTEGER*)&endTime64);
    ticks=endTime64-beginTime64;
    times[3][k]=(double)ticks/(double)ticksPerSecond;
   }
  SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_NORMAL);

  /* --- SUMMARY --- */

  for(k=1;k<NTIMES;k++) /* note -- skip first iteration */
   {
    for(j=0;j<4;j++)
     {
      avgtime[j]=avgtime[j]+times[j][k];
      mintime[j]=MIN(mintime[j],times[j][k]);
      maxtime[j]=MAX(maxtime[j],times[j][k]);
     }
   }
  printf("Function Rate (MB/s) Avg time Min time Max time\n");
  for(j=0;j<4;j++)
   {
    avgtime[j]=avgtime[j]/(double)(NTIMES-1);
    printf("%s%11.4f %11.4f %11.4f %11.4f\n",label[j]
                                               ,1.0E-06*bytes[j]/mintime[j]
                                               ,avgtime[j]
                                               ,mintime[j]
                                               ,maxtime[j]);
   }
  printf(HLINE);

  /* --- Check Results --- */

  checkSTREAMresults(ticksPerSecond);
  printf(HLINE);
  return 0;
 }

void checkSTREAMresults(__int64 ticksPerSecond)
 {
  double aj,
           bj,
           cj,
           scalar,
           asum,
           bsum,
           csum,
           epsilon;

  int j,
           k;

  /* reproduce initialization */

  aj=1.0;
  bj=2.0;
  cj=0.0;
  /* a[] is modified during timing check */
  aj=2.0E0*aj;
  /* now execute timing loop */
  scalar=3.0;
  for(k=0;k<NTIMES;k++)
   {
    cj=aj;
    bj=scalar*cj;
    cj=aj+bj;
    aj=bj+scalar*cj;
   }
  aj=aj*(double)(N);
  bj=bj*(double)(N);
  cj=cj*(double)(N);
  asum=0.0;
  bsum=0.0;
  csum=0.0;
  for(j=0;j<N;j++)
   {
    asum+=a[j];
    bsum+=b[j];
    csum+=c[j];
   }

#ifdef VERBOSE
  printf("Results Comparison: \n\n");
  printf(" a[] Expected : %f\n",aj);
  printf(" Observed : %f\n\n",asum);
  printf(" b[] Expected : %f\n",bj);
  printf(" Observed : %f\n\n",bsum);
  printf(" c[] Expected : %f\n",cj);
  printf(" Observed : %f\n\n",csum);
  printf("Clock ticks per second : %I64d.\n\n",ticksPerSecond);
#endif

#ifndef abs
#define abs(a) ((a) >= 0 ? (a) : -(a))
#endif

  epsilon=1.0E-8;

  if(abs(aj-asum)/asum>epsilon)
   {
    printf("Failed Validation on array a[]\n");
    printf(" Expected : %f \n",aj);
    printf(" Observed : %f \n",asum);
   }
  else if(abs(bj-bsum)/bsum>epsilon)
   {
    printf("Failed Validation on array b[]\n");
    printf(" Expected : %f \n",bj);
    printf(" Observed : %f \n",bsum);
   }
  else if(abs(cj-csum)/csum>epsilon)
   {
    printf("Failed Validation on array c[]\n");
    printf(" Expected : %f \n",cj);
    printf(" Observed : %f \n",csum);
   }
  else
   {
    printf("Solution Validates.\n");
   }
 }


Received on Sat May 17 10:10:24 2008

This archive was generated by hypermail 2.1.8 : Sat Dec 06 2008 - 12:16:11 CST