summaryrefslogtreecommitdiffstats
path: root/dis/original/Update/update.c
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-19 10:50:11 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-19 10:50:11 -0400
commit7e6ceb16b53fdbdb2a27cf3ade15d32177ff811f (patch)
treed6cf9044570b8b9707e89260d7267bcd69e163e7 /dis/original/Update/update.c
parent386b7d3366f1359a265da207a9cafa3edf553b64 (diff)
Add DIS benchmarks
Diffstat (limited to 'dis/original/Update/update.c')
-rw-r--r--dis/original/Update/update.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/dis/original/Update/update.c b/dis/original/Update/update.c
new file mode 100644
index 0000000..51e1530
--- /dev/null
+++ b/dis/original/Update/update.c
@@ -0,0 +1,133 @@
1/*
2 * Sample code for the DIS Update Stressmark
3 *
4 * This source code is the completely correct source code based on
5 * the example codes provided by Atlantic Aerospace Division, Titan
6 * Systems Corporation, 2000.
7 *
8 * If you just compile and generate the executables from this source
9 * code, this code would be enough. However, if you wish to get a complete
10 * understanding of this stressmark, it is strongly suggested that you
11 * read the Benchmark Analysis and Specifications Document Version 1.0
12 * before going on since the detailed comments are given in this documents.
13 * the comments are not repeated here.
14 */
15
16#include <stdio.h>
17#include <stdlib.h>
18#include <time.h>
19#include<assert.h>
20#include "DISstressmarkRNG.h"
21
22#define MIN_FIELD_SIZE 16
23
24#define MAX_FIELD_SIZE 16777216
25
26#define MIN_WINDOW_SIZE 1
27
28#define MAX_WINDOW_SIZE 15
29
30#define MIN_HOP_LIMIT 1
31
32#define MAX_HOP_LIMIT 4294967295U
33
34#define MIN_SEED -2147483647
35
36#define MAX_SEED -1
37
38/*
39 *main()
40 */
41
42int main(){
43
44 unsigned int *field;
45 unsigned int f;
46 unsigned int index;
47 unsigned short int w;
48 unsigned int maxhops;
49 int seed;
50 time_t startTime;
51 unsigned int initial;
52 unsigned int minStop;
53 unsigned int maxStop;
54 unsigned int hops;
55 unsigned int l;
56
57 fscanf(stdin, "%u %u %u %d %u %u %u",
58 &f, &l, &maxhops, &seed, &initial, &minStop, &maxStop);
59
60 assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE));
61 w = (unsigned int )l;
62 assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE));
63 assert(w%2 == 1);
64 assert(f > w);
65 assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT));
66 assert((seed >= MIN_SEED) && (seed <= MAX_SEED));
67 assert((initial >= 0) && (initial < f));
68 assert((minStop >= 0) && (minStop < f));
69 assert((maxStop >= 0) && (maxStop < f));
70
71 if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL)
72 return (-1);
73
74 randInit(seed);
75 for (l=0; l<f; l++){
76 field[l] = randInt(0, f-w);
77 }
78
79 startTime = time(NULL);
80
81 hops = 0;
82 index = initial;
83
84 while ((hops < maxhops) &&
85 (!((index >= minStop) &&
86 (index < maxStop)))){
87 int sum;
88
89 unsigned int ll, lll;
90 unsigned int max, min;
91 unsigned int partition;
92 unsigned int high;
93 max = MAX_FIELD_SIZE;
94 min = 0;
95 high = 0;
96 sum = 0;
97
98 for (ll=0; ll<w; ll++){
99 unsigned int balance;
100 unsigned int x;
101 x = field[index+ll];
102 sum += x;
103
104 if (x > max) high++;
105 else if (x >min){ /* start else* */
106 partition = x;
107 balance = 0;
108 for (lll=ll+1; lll<w; lll++){
109 if (field[index+lll] > partition) balance++;
110 }
111 if (balance+high == w/2) break;
112 else if (balance+high>w/2){
113 min = partition;
114 }/* end if */
115 else{
116 max = partition;
117 high++;
118 } /* end else */
119 }
120 if (min == max) break;
121 }/* end else* */
122 field[index] = sum % (f-w);
123 index = (partition+hops)%(f-w);
124 hops++;
125 }/* end for loop */
126
127 startTime = time(NULL) - startTime;
128
129 fprintf(stdout, "%u hops\n", hops);
130 fprintf(stderr, "total time = %u seconds.\n", (unsigned int)startTime);
131 free(field);
132 return(1);
133}