Changeset 119


Ignore:
Timestamp:
06/02/10 13:15:24 (3 years ago)
Author:
faltet
Message:

Adjusted some parameters in order to not consume too much memory.

Now, the hard_suite should run using a maximum of 256 MB.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bench/bench.c

    r118 r119  
    66  coming from a file" comment). 
    77 
    8   To compile using GCC, go to src/ directory and do: 
     8  To compile using GCC, stay in this directory and do: 
    99 
    1010    gcc -O3 -msse2 -o bench bench.c \ 
     
    3535 
    3636#define KB  1024 
    37 #define MB  (1024*1024) 
    38  
    39 /* #define NCHUNKS (100) */ 
    40 /* #define NITER  (10)               /\* Number of iterations *\/ */ 
    41 #define NCHUNKS (128) 
    42 #define NITER  (10)               /* Number of iterations */ 
    43  
     37#define MB  (1024*KB) 
     38#define GB  (1024*MB) 
     39 
     40#define WORKINGSET (256*MB)     /* do not exceed this memory consumption */ 
     41#define NCHUNKS (32*1024)       /* maximum number of chunks */ 
     42#define NITER  3                /* number of iterations */ 
     43 
     44 
     45int nchunks = NCHUNKS; 
     46int niter = NITER; 
    4447 
    4548#if defined(_WIN32) && !defined(__MINGW32__) 
     
    100103  sec = current.tv_sec - last.tv_sec; 
    101104  usec = current.tv_usec - last.tv_usec; 
    102   return (float)(((double)sec + usec*1e-6)/((double)NITER*NCHUNKS)*1e6); 
     105  return (float)(((double)sec + usec*1e-6)/((double)niter*nchunks)*1e6); 
    103106} 
    104107 
     
    154157  init_buffer(src, size, rshift); 
    155158  memcpy(srccpy, src, size); 
    156   for (j = 0; j < NCHUNKS; j++) { 
     159  for (j = 0; j < nchunks; j++) { 
    157160    dest[j] = malloc(size); 
    158161  } 
    159162 
    160163  /* Warm destination memory (memcpy() will go a bit faster later on) */ 
    161   for (j = 0; j < NCHUNKS; j++) { 
     164  for (j = 0; j < nchunks; j++) { 
    162165    memcpy(dest[j], src, size); 
    163166  } 
     
    168171  printf("Using synthetic data with %d significant bits (out of 32)\n", rshift); 
    169172  printf("Dataset size: %d bytes\tType size: %d bytes\n", size, elsize); 
    170   printf("Working set: %.1f MB\t\t", (size*NCHUNKS) / (float)MB); 
     173  printf("Working set: %.1f MB\t\t", (size*nchunks) / (float)MB); 
    171174  printf("Number of threads: %d\n", nthreads); 
    172175  printf("********************** Running benchmarks *********************\n"); 
    173176 
    174177  gettimeofday(&last, NULL); 
    175   for (i = 0; i < NITER; i++) { 
    176     for (j = 0; j < NCHUNKS; j++) { 
     178  for (i = 0; i < niter; i++) { 
     179    for (j = 0; j < nchunks; j++) { 
    177180      memcpy(dest[j], src, size); 
    178181    } 
     
    184187 
    185188  gettimeofday(&last, NULL); 
    186   for (i = 0; i < NITER; i++) { 
    187     for (j = 0; j < NCHUNKS; j++) { 
     189  for (i = 0; i < niter; i++) { 
     190    for (j = 0; j < nchunks; j++) { 
    188191      memcpy(dest2, dest[j], size); 
    189192    } 
     
    199202 
    200203    gettimeofday(&last, NULL); 
    201     for (i = 0; i < NITER; i++) { 
    202       for (j = 0; j < NCHUNKS; j++) { 
     204    for (i = 0; i < niter; i++) { 
     205      for (j = 0; j < nchunks; j++) { 
    203206        cbytes = blosc_compress(clevel, doshuffle, elsize, size, src, dest[j]); 
    204207      } 
     
    216219    /* Compressor was unable to compress.  Copy the buffer manually. */ 
    217220    if (cbytes == 0) { 
    218       for (j = 0; j < NCHUNKS; j++) { 
     221      for (j = 0; j < nchunks; j++) { 
    219222        memcpy(dest[j], src, size); 
    220223      } 
     
    222225 
    223226    gettimeofday(&last, NULL); 
    224     for (i = 0; i < NITER; i++) { 
    225       for (j = 0; j < NCHUNKS; j++) { 
     227    for (i = 0; i < niter; i++) { 
     228      for (j = 0; j < nchunks; j++) { 
    226229        if (cbytes == 0) { 
    227230          memcpy(dest2, dest[j], size); 
     
    259262 
    260263  free(src); free(srccpy); free(dest2); 
    261   for (i = 0; i < NCHUNKS; i++) { 
     264  for (i = 0; i < nchunks; i++) { 
    262265    free(dest[i]); 
    263266  } 
    264267 
     268} 
     269 
     270 
     271/* Compute a sensible value for nchunks */ 
     272int get_nchunks(unsigned int size_) { 
     273  int nchunks; 
     274 
     275  nchunks = WORKINGSET / size_; 
     276  if (nchunks > NCHUNKS) nchunks = NCHUNKS; 
     277  if (nchunks < 1) nchunks = 1; 
     278  return nchunks; 
    265279} 
    266280 
     
    269283  int suite = 0; 
    270284  int hard_suite = 0; 
    271   int nthreads = 1;                /* The number of threads */ 
    272   unsigned int size = 2*1024*1024; /* Buffer size */ 
    273   unsigned int elsize = 8;         /* Datatype size */ 
    274   int rshift = 19;                 /* Significant bits */ 
     285  int nloops = 0; 
     286  float totalsize; 
     287  int nthreads = 1;                    /* The number of threads */ 
     288  unsigned int size = 2*1024*1024;     /* Buffer size */ 
     289  unsigned int elsize = 8;             /* Datatype size */ 
     290  int rshift = 19;                     /* Significant bits */ 
    275291  int j; 
    276292 
     
    293309    if (argc >= 3) { 
    294310      size = atoi(argv[2])*1024; 
    295       if (size > 2*1024*1024) { 
    296         printf("The test is going to require more than 256 MB of RAM!\n"); 
    297       } 
    298311    } 
    299312    if (argc >= 4) { 
     
    309322  } 
    310323 
     324  nchunks = get_nchunks(size); 
     325 
    311326  if (hard_suite) { 
    312     for (j=1; j <= nthreads; j++) { 
    313       for (size=64*KB; size <= 8*MB; size *=2) { 
    314         for (elsize=1; elsize < 32; elsize *=2) { 
    315           for (rshift=0; rshift < 32; rshift +=5) { 
     327    for (rshift=0; rshift < 32; rshift +=5) { 
     328      for (elsize=1; elsize <= 32; elsize *=2) { 
     329        for (size=32*KB; size <= 8*MB; size *=2) { 
     330          nchunks = get_nchunks(size); 
     331          for (j=1; j <= nthreads; j++) { 
    316332            do_bench(j, size, elsize, rshift); 
     333            nloops++; 
    317334          } 
    318335        } 
    319336      } 
    320337    } 
     338    /* To compute the totalsize, we should take into account the 9 
     339       compression levels */ 
     340    totalsize = (1. * nloops * WORKINGSET * NITER * 9) / GB; 
     341    printf("Performed round-trip compr/decompr on %.1f GB", totalsize); 
    321342  } 
    322343  else if (suite) { 
Note: See TracChangeset for help on using the changeset viewer.