diff options
Diffstat (limited to 'dis/Update/update.c')
-rw-r--r-- | dis/Update/update.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/dis/Update/update.c b/dis/Update/update.c new file mode 100644 index 0000000..1fd8197 --- /dev/null +++ b/dis/Update/update.c | |||
@@ -0,0 +1,138 @@ | |||
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 | #include "extra.h" | ||
22 | |||
23 | #define MIN_FIELD_SIZE 16 | ||
24 | |||
25 | #define MAX_FIELD_SIZE 16777216 | ||
26 | |||
27 | #define MIN_WINDOW_SIZE 1 | ||
28 | |||
29 | #define MAX_WINDOW_SIZE 15 | ||
30 | |||
31 | #define MIN_HOP_LIMIT 1 | ||
32 | |||
33 | #define MAX_HOP_LIMIT 4294967295U | ||
34 | |||
35 | #define MIN_SEED -2147483647 | ||
36 | |||
37 | #define MAX_SEED -1 | ||
38 | |||
39 | /* | ||
40 | *main() | ||
41 | */ | ||
42 | |||
43 | int main(int argc, char** argv){ | ||
44 | |||
45 | unsigned int *field; | ||
46 | unsigned int f; | ||
47 | unsigned int index; | ||
48 | unsigned short int w; | ||
49 | unsigned int maxhops; | ||
50 | int seed; | ||
51 | time_t startTime; | ||
52 | unsigned int initial; | ||
53 | unsigned int minStop; | ||
54 | unsigned int maxStop; | ||
55 | unsigned int hops; | ||
56 | unsigned int l; | ||
57 | |||
58 | assert(fscanf(stdin, "%u %u %u %d %u %u %u", | ||
59 | &f, &l, &maxhops, &seed, &initial, &minStop, &maxStop) == 7); | ||
60 | |||
61 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | ||
62 | w = (unsigned int )l; | ||
63 | assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); | ||
64 | assert(w%2 == 1); | ||
65 | assert(f > w); | ||
66 | assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); | ||
67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
68 | assert((initial >= 0) && (initial < f)); | ||
69 | assert((minStop >= 0) && (minStop < f)); | ||
70 | assert((maxStop >= 0) && (maxStop < f)); | ||
71 | |||
72 | if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) | ||
73 | return (-1); | ||
74 | |||
75 | randInit(seed); | ||
76 | for (l=0; l<f; l++){ | ||
77 | field[l] = randInt(0, f-w); | ||
78 | } | ||
79 | |||
80 | SET_UP | ||
81 | startTime = time(NULL); | ||
82 | |||
83 | hops = 0; | ||
84 | index = initial; | ||
85 | |||
86 | while ((hops < maxhops) && | ||
87 | (!((index >= minStop) && | ||
88 | (index < maxStop)))){ | ||
89 | int sum; | ||
90 | |||
91 | unsigned int ll, lll; | ||
92 | unsigned int max, min; | ||
93 | unsigned int partition; | ||
94 | unsigned int high; | ||
95 | if (hops % 100 == 0) {START_LOOP} // These loops are too quick to sample individually | ||
96 | max = MAX_FIELD_SIZE; | ||
97 | min = 0; | ||
98 | high = 0; | ||
99 | sum = 0; | ||
100 | |||
101 | for (ll=0; ll<w; ll++){ | ||
102 | unsigned int balance; | ||
103 | unsigned int x; | ||
104 | x = field[index+ll]; | ||
105 | sum += x; | ||
106 | |||
107 | if (x > max) high++; | ||
108 | else if (x >min){ /* start else* */ | ||
109 | partition = x; | ||
110 | balance = 0; | ||
111 | for (lll=ll+1; lll<w; lll++){ | ||
112 | if (field[index+lll] > partition) balance++; | ||
113 | } | ||
114 | if (balance+high == w/2) break; | ||
115 | else if (balance+high>w/2){ | ||
116 | min = partition; | ||
117 | }/* end if */ | ||
118 | else{ | ||
119 | max = partition; | ||
120 | high++; | ||
121 | } /* end else */ | ||
122 | } | ||
123 | if (min == max) break; | ||
124 | }/* end else* */ | ||
125 | field[index] = sum % (f-w); | ||
126 | index = (partition+hops)%(f-w); | ||
127 | hops++; | ||
128 | if (hops % 100 == 0) {STOP_LOOP} // These loops are too quick to sample individually | ||
129 | }/* end for loop */ | ||
130 | |||
131 | startTime = time(NULL) - startTime; | ||
132 | |||
133 | fprintf(stdout, "%u hops\n", hops); | ||
134 | fprintf(stderr, "total time = %u seconds.\n", (unsigned int)startTime); | ||
135 | free(field); | ||
136 | WRITE_TO_FILE | ||
137 | return(1); | ||
138 | } | ||