text: /* $Id: cnt.c,v 1.3 2005/04/04 11:34:58 csg Exp $ */
  
  
  
  /* sumcntmatrix.c */
  
  
  
  //#include <sys/types.h>
  
  //#include <sys/times.h>
  
  
  
  // #define WORSTCASE 1
  
  // #define MAXSIZE 100 Changed JG/Ebbe
  
  #define MAXSIZE 10
  
  
  
  // Typedefs
  
  typedef int matrix [MAXSIZE][MAXSIZE];
  
  
  
  // Forwards declarations
  
  static inline int Test(matrix);
  
  static int Initialize(matrix);
  
  static int InitSeed(void);
  
  static void Sum(matrix);
  
  static int RandomInteger(void);
  
  
  
  // Globals
  
  static int Seed;
  
  static matrix Array;
  
  static int Postotal, Negtotal, Poscnt, Negcnt;
  
  
  
  // The main function
  
  int go (void)
  
  {
  
     InitSeed();
  
     //printf("\n   *** MATRIX SUM AND COUNT BENCHMARK TEST ***\n\n");
  
     //printf("RESULTS OF THE TEST:\n");
  
     return Test(Array);
  }
  
  
  
  
  
  static inline int Test(matrix Array)
  
  {
  
     long StartTime, StopTime;
  
     float TotalTime;
  
  
  
     Initialize(Array);
  
     StartTime = 1000.0; //ttime();
  
     Sum(Array);
  
     StopTime = 1500.0; //ttime();
  
  
  
     TotalTime = (StopTime - StartTime) / 1000.0;
  
  
  
     //printf("    - Size of array is %d\n", MAXSIZE);
  
     //printf("    - Num pos was %d and Sum was %d\n", Poscnt, Postotal);
  
     //printf("    - Num neg was %d and Sum was %d\n", Negcnt, Negtotal);
  
     //printf("    - Num neg was %d\n", Negcnt);
  
     //printf("    - Total sum time is %3.3f seconds\n\n", TotalTime);
  
     return Poscnt+Negcnt+Postotal+Negtotal+TotalTime;
  
  }
  
  
  
  
  
  // Intializes the given array with random integers.
  
  static int Initialize(matrix Array)
  
  {
  
     register int OuterIndex, InnerIndex;
  
  
  
     for (OuterIndex = 0; OuterIndex < MAXSIZE; OuterIndex++) //100 + 1
  
        for (InnerIndex = 0; InnerIndex < MAXSIZE; InnerIndex++) //100 + 1
  
           Array[OuterIndex][InnerIndex] = RandomInteger();
  
  
  
     return 0;
  
  }
  
  
  
  
  
  // Initializes the seed used in the random number generator.
  
  static int InitSeed (void)
  
  {
  
     Seed = 0;
  
     return 0;
  
  }
  
  
  
  static void Sum(matrix Array)
  
  {
  
    register int Outer, Inner;
  
  
  
    int Ptotal = 0; /* changed these to locals in order to drive worst case */
  
    int Ntotal = 0;
  
    int Pcnt = 0;
  
    int Ncnt = 0;
  
  
  
    for (Outer = 0; Outer < MAXSIZE; Outer++) //Maxsize = 100
  
      for (Inner = 0; Inner < MAXSIZE; Inner++)
  
  #ifdef WORSTCASE
  
        if (Array[Outer][Inner] >= 0) {
  
  #else
  
  	if (Array[Outer][Inner] < 0) {
  
  #endif
  
  	  Ptotal += Array[Outer][Inner];
  
  	  Pcnt++;
  
  	}
  
  	else {
  
  	  Ntotal += Array[Outer][Inner];
  
  	  Ncnt++;
  
  	}
  
  
  
    Postotal = Ptotal;
  
    Poscnt = Pcnt;
  
    Negtotal = Ntotal;
  
    Negcnt = Ncnt;
  
  }
  
  
  
  
  
  // This function returns in milliseconds the amount of compiler time
  
  //int ttime()
  
  //{
  
  //  struct tms buffer;
  
  //int utime;
  
  
  
  //times(&buffer);
  
  //utime = (buffer.tms_utime / 60.0) * 1000.0;
  
  //return (utime);
  
  //}
  
  
  
  
  
  // Generates random integers between 0 and 8095
  
  int RandomInteger(void)
  
  {
  
     Seed = ((Seed * 133) + 81) % 8095;
  
     return Seed;
  
  }
  
  
  
  
  
  
  
  
  
  
  
  