diff options
Diffstat (limited to 'dis/Update/update.c')
-rw-r--r-- | dis/Update/update.c | 98 |
1 files changed, 50 insertions, 48 deletions
diff --git a/dis/Update/update.c b/dis/Update/update.c index f5e770a..a12c3df 100644 --- a/dis/Update/update.c +++ b/dis/Update/update.c | |||
@@ -1,24 +1,24 @@ | |||
1 | /* | 1 | /* |
2 | * Sample code for the DIS Update Stressmark | 2 | * Sample code for the DIS Update Stressmark |
3 | * | 3 | * |
4 | * This source code is the completely correct source code based on | 4 | * This source code is the completely correct source code based on |
5 | * the example codes provided by Atlantic Aerospace Division, Titan | 5 | * the example codes provided by Atlantic Aerospace Division, Titan |
6 | * Systems Corporation, 2000. | 6 | * Systems Corporation, 2000. |
7 | * | 7 | * |
8 | * If you just compile and generate the executables from this source | 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 | 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 | 10 | * understanding of this stressmark, it is strongly suggested that you |
11 | * read the Benchmark Analysis and Specifications Document Version 1.0 | 11 | * read the Benchmark Analysis and Specifications Document Version 1.0 |
12 | * before going on since the detailed comments are given in this documents. | 12 | * before going on since the detailed comments are given in this documents. |
13 | * the comments are not repeated here. | 13 | * the comments are not repeated here. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include "DISstressmarkRNG.h" | ||
17 | #include "extra.h" | ||
18 | #include <assert.h> | ||
16 | #include <stdio.h> | 19 | #include <stdio.h> |
17 | #include <stdlib.h> | 20 | #include <stdlib.h> |
18 | #include <time.h> | 21 | #include <time.h> |
19 | #include<assert.h> | ||
20 | #include "DISstressmarkRNG.h" | ||
21 | #include "extra.h" | ||
22 | 22 | ||
23 | #define MIN_FIELD_SIZE 16 | 23 | #define MIN_FIELD_SIZE 16 |
24 | 24 | ||
@@ -36,11 +36,11 @@ | |||
36 | 36 | ||
37 | #define MAX_SEED -1 | 37 | #define MAX_SEED -1 |
38 | 38 | ||
39 | /* | 39 | /* |
40 | *main() | 40 | *main() |
41 | */ | 41 | */ |
42 | 42 | ||
43 | int main(int argc, char** argv){ | 43 | int main(int argc, char **argv) { |
44 | 44 | ||
45 | unsigned int *field; | 45 | unsigned int *field; |
46 | unsigned int f; | 46 | unsigned int f; |
@@ -55,13 +55,13 @@ int main(int argc, char** argv){ | |||
55 | unsigned int hops; | 55 | unsigned int hops; |
56 | unsigned int l; | 56 | unsigned int l; |
57 | 57 | ||
58 | assert(fscanf(stdin, "%u %u %u %d %u %u %u", | 58 | assert(fscanf(stdin, "%u %u %u %d %u %u %u", &f, &l, &maxhops, &seed, |
59 | &f, &l, &maxhops, &seed, &initial, &minStop, &maxStop) == 7); | 59 | &initial, &minStop, &maxStop) == 7); |
60 | 60 | ||
61 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | 61 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); |
62 | w = (unsigned int )l; | 62 | w = (unsigned int)l; |
63 | assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); | 63 | assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); |
64 | assert(w%2 == 1); | 64 | assert(w % 2 == 1); |
65 | assert(f > w); | 65 | assert(f > w); |
66 | assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); | 66 | assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); |
67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | 67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); |
@@ -69,14 +69,14 @@ int main(int argc, char** argv){ | |||
69 | assert((minStop >= 0) && (minStop < f)); | 69 | assert((minStop >= 0) && (minStop < f)); |
70 | assert((maxStop >= 0) && (maxStop < f)); | 70 | assert((maxStop >= 0) && (maxStop < f)); |
71 | 71 | ||
72 | if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) | 72 | if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) |
73 | return (-1); | 73 | return (-1); |
74 | 74 | ||
75 | randInit(seed); | 75 | randInit(seed); |
76 | for (l=0; l<f; l++){ | 76 | for (l = 0; l < f; l++) { |
77 | field[l] = randInt(0, f-w); | 77 | field[l] = randInt(0, f - w); |
78 | } | 78 | } |
79 | 79 | ||
80 | SET_UP | 80 | SET_UP |
81 | startTime = time(NULL); | 81 | startTime = time(NULL); |
82 | 82 | ||
@@ -84,9 +84,7 @@ int main(int argc, char** argv){ | |||
84 | index = initial; | 84 | index = initial; |
85 | 85 | ||
86 | START_LOOP | 86 | START_LOOP |
87 | while ((hops < maxhops) && | 87 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { |
88 | (!((index >= minStop) && | ||
89 | (index < maxStop)))){ | ||
90 | int sum; | 88 | int sum; |
91 | 89 | ||
92 | unsigned int ll, lll; | 90 | unsigned int ll, lll; |
@@ -98,43 +96,47 @@ int main(int argc, char** argv){ | |||
98 | high = 0; | 96 | high = 0; |
99 | sum = 0; | 97 | sum = 0; |
100 | 98 | ||
101 | for (ll=0; ll<w; ll++){ | 99 | for (ll = 0; ll < w; ll++) { |
102 | unsigned int balance; | 100 | unsigned int balance; |
103 | unsigned int x; | 101 | unsigned int x; |
104 | x = field[index+ll]; | 102 | x = field[index + ll]; |
105 | sum += x; | 103 | sum += x; |
106 | 104 | ||
107 | if (x > max) high++; | 105 | if (x > max) |
108 | else if (x >min){ /* start else* */ | 106 | high++; |
109 | partition = x; | 107 | else if (x > min) { /* start else* */ |
110 | balance = 0; | 108 | partition = x; |
111 | for (lll=ll+1; lll<w; lll++){ | 109 | balance = 0; |
112 | if (field[index+lll] > partition) balance++; | 110 | for (lll = ll + 1; lll < w; lll++) { |
113 | } | 111 | if (field[index + lll] > partition) |
114 | if (balance+high == w/2) break; | 112 | balance++; |
115 | else if (balance+high>w/2){ | 113 | } |
116 | min = partition; | 114 | if (balance + high == w / 2) |
117 | }/* end if */ | 115 | break; |
118 | else{ | 116 | else if (balance + high > w / 2) { |
119 | max = partition; | 117 | min = partition; |
120 | high++; | 118 | } /* end if */ |
121 | } /* end else */ | 119 | else { |
120 | max = partition; | ||
121 | high++; | ||
122 | } /* end else */ | ||
122 | } | 123 | } |
123 | if (min == max) break; | 124 | if (min == max) |
124 | }/* end else* */ | 125 | break; |
125 | field[index] = sum % (f-w); | 126 | } /* end else* */ |
126 | index = (partition+hops)%(f-w); | 127 | field[index] = sum % (f - w); |
128 | index = (partition + hops) % (f - w); | ||
127 | hops++; | 129 | hops++; |
128 | }/* end for loop */ | 130 | } /* end for loop */ |
129 | STOP_LOOP | 131 | STOP_LOOP |
130 | 132 | ||
131 | endTime = time(NULL); | 133 | endTime = time(NULL); |
132 | 134 | ||
133 | volatile int _stop_optimizer = hops; | 135 | volatile int _stop_optimizer = hops; |
134 | //fprintf(stdout, "%u hops\n", hops); | 136 | // fprintf(stdout, "%u hops\n", hops); |
135 | fprintf(stderr, "time for update stressmark = %f seconds.\n", | 137 | fprintf(stderr, "time for update stressmark = %f seconds.\n", |
136 | difftime(endTime, startTime)); | 138 | difftime(endTime, startTime)); |
137 | free(field); | 139 | free(field); |
138 | WRITE_TO_FILE | 140 | WRITE_TO_FILE |
139 | return(1); | 141 | return (1); |
140 | } | 142 | } |