root/user/uw-testbin/sparse/sparse.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /* 
   2  * sparse.c
   3  *
   4  *      This program declares a large array, but only uses a small
   5  *      part of it.  The intention is that the full array will not
   6  *      fit into memory, but the used part of the array will fit.
   7  *
   8  *      This is similar to testbin/huge.
   9  *
  10  */
  11 
  12 #include <stdio.h>
  13 #include <stdlib.h>
  14 
  15 /* 
  16  * set these to match the page size of the 
  17  * machine and the number of pages of physical memory
  18  * in the machine.
  19  */
  20 #define PageSize        4096
  21 #define NumPages        128
  22 
  23 /* a large array, 2 times the size of physical memory */
  24 #define ArraySize (2*NumPages*PageSize)
  25 char sparse[ArraySize];
  26 
  27 int
  28 main()
  29 {
  30         int i,j;
  31 
  32         printf("Starting the sparse program\n");
  33 
  34         /* write some values into the array, but only
  35            touch one array entry on every 10th page */
  36         for (i=0; i<ArraySize; i+=(10*PageSize)) {
  37           sparse[i]= 'a';
  38         }
  39         
  40         printf("stage [1] done\n");
  41         
  42         /* increment each location 5 times */
  43         for(j=0; j<5; j++) {
  44           for (i=0; i<ArraySize; i+=(10*PageSize)) {
  45             sparse[i] += 1;
  46           }
  47         }
  48         
  49         printf("stage [2] done\n");
  50         
  51         /* check the values that were written */
  52         /* increment each location 5 times */
  53         for (i=0; i<ArraySize; i+=(10*PageSize)) {
  54           if (sparse[i] != ('a'+5)) {
  55             printf("Test failed! Unexpected value at array position %d\n", i);
  56             return(1);
  57           }
  58         }
  59 
  60         printf("SUCCESS\n");
  61         
  62         return 0;
  63 }
  64 

/* [<][>][^][v][top][bottom][index][help] */