summaryrefslogtreecommitdiffstats
path: root/dis/Neighborhood/neighborhood.c
blob: ea1c65868beebcd1ad8082ad191341adca5c9af8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 *  Sample code for the DIS Neighborhood Stressmark
 *
 * This source code is the completely correct source code based on
 * the example codes provided by Atlantic Aerospace Division, Titan
 * Systems Corporation, 2000.
 *
 * If you just compile and generate the executables from this source
 * code, this code would be enough. However, if you wish to get a complete
 * understanding of this stressmark, it is strongly suggested that you
 * read the Benchmark Analysis and Specifications Document Version 1.0
 * before going on since the detailed comments are given in this documents.
 * the comments are not repeated here.
 *
 * Change log:
 * ------- ---------------- ---------------------------------------------------
 * 06/2020 Joshua Bakita    Include image creation time in timing
 */

#include "DISstressmarkRNG.h"
#include "extra.h"
#include "utili.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/*
 * main()
 */
int main(int argc, char **argv) {
  long int seed;
  int dimension;
  int numberLines;
  int minThickness;
  int maxThickness;
  int distanceShort;
  int distanceLong;
  int bitDepth;
  int maxPixel;
  Pixel *image;
  Neighborhood values;

  time_t beginTime;
  time_t endTime;
  SET_UP

  assert(fscanf(stdin, "%ld %d %d %d %d %d %d %d", &seed, &bitDepth, &dimension,
                &numberLines, &minThickness, &maxThickness, &distanceShort,
                &distanceLong) == 8);

  assert((seed >= MIN_SEED) && (seed <= MAX_SEED));
  assert((dimension > 0) && (dimension <= MAX_DIMENSION));
  assert((numberLines > 0) && (numberLines <= MAX_NUMBER_LINES));
  assert((minThickness > 0) && (minThickness < dimension));
  assert((maxThickness >= minThickness) && (maxThickness < dimension));
  assert((distanceShort > 0) && (distanceShort < dimension));
  assert((distanceLong > 0) && (distanceLong < dimension));
  assert((bitDepth >= MIN_BIT_DEPTH) && (bitDepth <= MAX_BIT_DEPTH));

  randInit(seed);
  maxPixel = (1 << bitDepth) - 1;
  image = malloc(sizeof(Pixel) * dimension * dimension);
  assert(image != NULL);

  for_each_job {
    beginTime = time(NULL);
    createImage(image, dimension, maxPixel, numberLines, minThickness,
                maxThickness);

    neighborhoodCalculation(image, dimension, distanceShort, distanceLong,
                            &values, maxPixel);
  }
  endTime = time(NULL);
  WRITE_TO_FILE

  volatile double _stop_optimizer = values.distShort.deg0.entropy
          + values.distShort.deg0.energy + values.distShort.deg45.entropy
          + values.distShort.deg45.energy + values.distShort.deg90.entropy
          + values.distShort.deg90.energy + values.distShort.deg135.entropy
          + values.distShort.deg135.energy + values.distLong.deg0.entropy
          + values.distLong.deg0.energy + values.distShort.deg45.entropy
          + values.distLong.deg45.energy + values.distLong.deg90.entropy
          + values.distLong.deg90.energy + values.distLong.deg135.entropy
          + values.distLong.deg135.energy;
  //fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e",
  //        values.distShort.deg0.entropy, values.distShort.deg0.energy,
  //        values.distShort.deg45.entropy, values.distShort.deg45.energy,
  //        values.distShort.deg90.entropy, values.distShort.deg90.energy,
  //        values.distShort.deg135.entropy, values.distShort.deg135.energy);

  //fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e",
  //        values.distLong.deg0.entropy, values.distLong.deg0.energy,
  //        values.distShort.deg45.entropy, values.distLong.deg45.energy,
  //        values.distLong.deg90.entropy, values.distLong.deg90.energy,
  //        values.distLong.deg135.entropy, values.distLong.deg135.energy);

  fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n",
          difftime(endTime, beginTime));

  free((Pixel *)image);
  return (0);
}