diff options
Diffstat (limited to 'dis/Pointer/pointer.c')
-rw-r--r-- | dis/Pointer/pointer.c | 225 |
1 files changed, 112 insertions, 113 deletions
diff --git a/dis/Pointer/pointer.c b/dis/Pointer/pointer.c index 3fc7248..3f3eefb 100644 --- a/dis/Pointer/pointer.c +++ b/dis/Pointer/pointer.c | |||
@@ -1,26 +1,26 @@ | |||
1 | /* | 1 | /* |
2 | * Sample code for the DIS Pointer Stressmark | 2 | * Sample code for the DIS Pointer 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 | #include <stdio.h> | ||
16 | #include <time.h> | ||
17 | #include <assert.h> | ||
18 | #include <stdlib.h> | ||
19 | #include "DISstressmarkRNG.h" | 15 | #include "DISstressmarkRNG.h" |
20 | #include "extra.h" | 16 | #include "extra.h" |
17 | #include <assert.h> | ||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <time.h> | ||
21 | 21 | ||
22 | #define MIN_FIELD_SIZE 16 | 22 | #define MIN_FIELD_SIZE 16 |
23 | #define MAX_FIELD_SIZE (16777216*4) // Modifed from original | 23 | #define MAX_FIELD_SIZE (16777216 * 4) // Modifed from original |
24 | #define MIN_WINDOW_SIZE 1 | 24 | #define MIN_WINDOW_SIZE 1 |
25 | #define MAX_WINDOW_SIZE 15 | 25 | #define MAX_WINDOW_SIZE 15 |
26 | #define MIN_HOP_LIMIT 1 | 26 | #define MIN_HOP_LIMIT 1 |
@@ -35,7 +35,7 @@ | |||
35 | /* | 35 | /* |
36 | * main() | 36 | * main() |
37 | */ | 37 | */ |
38 | int main(int argc, char** argv){ | 38 | int main(int argc, char **argv) { |
39 | 39 | ||
40 | unsigned int *field; | 40 | unsigned int *field; |
41 | unsigned long f; | 41 | unsigned long f; |
@@ -46,116 +46,115 @@ int main(int argc, char** argv){ | |||
46 | 46 | ||
47 | clock_t startTime, endTime; | 47 | clock_t startTime, endTime; |
48 | 48 | ||
49 | struct threadS{ | 49 | struct threadS { |
50 | unsigned long initial; | 50 | unsigned long initial; |
51 | unsigned long minStop; | 51 | unsigned long minStop; |
52 | unsigned long maxStop; | 52 | unsigned long maxStop; |
53 | unsigned long hops; | 53 | unsigned long hops; |
54 | }*thread; | 54 | } * thread; |
55 | 55 | ||
56 | unsigned int l; | 56 | unsigned int l; |
57 | SET_UP | 57 | SET_UP |
58 | 58 | ||
59 | assert(fscanf(stdin, "%lu %u %lu %ld %u", | 59 | assert(fscanf(stdin, "%lu %u %lu %ld %u", &f, &l, &maxhops, &seed, &n) == 5); |
60 | &f, &l, &maxhops, &seed, &n) == 5); | 60 | |
61 | 61 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | |
62 | assert ((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | 62 | w = (unsigned int)l; |
63 | w = (unsigned int) l; | 63 | assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); |
64 | assert ((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); | 64 | assert(w % 2 == 1); |
65 | assert (w % 2 == 1); | 65 | assert(f > w); |
66 | assert (f > w); | 66 | assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); |
67 | assert ((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); | 67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); |
68 | assert ((seed >= MIN_SEED) && (seed <= MAX_SEED)); | 68 | |
69 | 69 | assert((n >= MIN_THREADS) && (n <= MAX_THREADS)); | |
70 | assert ((n >= MIN_THREADS) && (n <= MAX_THREADS)); | 70 | if ((thread = (struct threadS *)malloc(n * sizeof(struct threadS))) == NULL) |
71 | if ((thread = (struct threadS *)malloc(n*sizeof(struct threadS))) == NULL) | 71 | return (-1); |
72 | return (-1); | 72 | |
73 | 73 | for (l = 0; l < n; l++) { | |
74 | for (l=0; l<n; l++){ | 74 | assert(fscanf(stdin, "%lu %lu %lu", &(thread[l].initial), |
75 | assert(fscanf(stdin, "%lu %lu %lu", | 75 | &(thread[l].minStop), &(thread[l].maxStop)) == 3); |
76 | &(thread[l].initial), &(thread[l].minStop), &(thread[l].maxStop)) == 3); | 76 | assert((thread[l].initial >= 0) && (thread[l].initial < f)); |
77 | assert ((thread[l].initial >= 0) && (thread[l].initial < f)); | 77 | assert((thread[l].minStop >= 0) && (thread[l].minStop < f)); |
78 | assert ((thread[l].minStop >= 0) && (thread[l].minStop < f)); | 78 | assert((thread[l].maxStop >= 0) && (thread[l].maxStop < f)); |
79 | assert ((thread[l].maxStop >= 0) && (thread[l].maxStop < f)); | ||
80 | } | ||
81 | |||
82 | if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) | ||
83 | return (-1); | ||
84 | |||
85 | randInit(seed); | ||
86 | for (l=0; l<f; l++){ | ||
87 | field[l] = randInt(0, f-w); | ||
88 | } | ||
89 | startTime = time(NULL); | ||
90 | clock(); | ||
91 | |||
92 | START_LOOP | ||
93 | for (l=0; l<n; l++) | ||
94 | { | ||
95 | unsigned int index; | ||
96 | unsigned int minStop, maxStop; | ||
97 | unsigned int hops; | ||
98 | |||
99 | hops = 0; | ||
100 | minStop = thread[l].minStop; | ||
101 | maxStop = thread[l].maxStop; | ||
102 | index = thread[l].initial; | ||
103 | while ((hops < maxhops) && | ||
104 | (!((index >= minStop) && | ||
105 | (index < maxStop)))){ | ||
106 | |||
107 | unsigned int ll, lll; | ||
108 | unsigned int max, min; | ||
109 | unsigned int partition; | ||
110 | unsigned int high; | ||
111 | |||
112 | partition = field[index]; | ||
113 | max = MAX_FIELD_SIZE; | ||
114 | min = 0; | ||
115 | high = 0; | ||
116 | |||
117 | for (ll=0; ll<w; ll++){ | ||
118 | unsigned int balance; | ||
119 | unsigned int x; | ||
120 | x = field[index+ll]; | ||
121 | |||
122 | if (x > max) high++; | ||
123 | else if (x > min){ /* start else* */ | ||
124 | partition = x; | ||
125 | balance = 0; | ||
126 | for (lll=ll+1; lll<w; lll++){ | ||
127 | if (field[index+lll] > partition) balance++; | ||
128 | }/* end for loop */ | ||
129 | |||
130 | if (balance+high == w/2) break; | ||
131 | else if (balance+high > w/2){ | ||
132 | min = partition; | ||
133 | }/* end if */ | ||
134 | else { | ||
135 | max = partition; | ||
136 | high++; | ||
137 | }/* end else */ | ||
138 | } | 79 | } |
139 | if (min == max) break; | ||
140 | } /* end else* */ | ||
141 | index = (partition+hops)%(f-w); | ||
142 | hops++; | ||
143 | }/* end loop ll */ | ||
144 | thread[l].hops = hops; | ||
145 | } /* end while */ | ||
146 | STOP_LOOP | ||
147 | |||
148 | endTime = time(NULL); | ||
149 | |||
150 | volatile int _stop_optimizer = thread[l].hops + l; | ||
151 | /*for (l=0; l<n; l++){ | ||
152 | fprintf(stdout, "%lu hops on thread %d\n", thread[l].hops, l); | ||
153 | }*/ | ||
154 | |||
155 | fprintf(stderr, "time for pointer stressmark = %f seconds.\n", | ||
156 | difftime(endTime, startTime)); | ||
157 | free (field); | ||
158 | free (thread); | ||
159 | WRITE_TO_FILE | ||
160 | 80 | ||
81 | if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) | ||
82 | return (-1); | ||
83 | |||
84 | randInit(seed); | ||
85 | for (l = 0; l < f; l++) { | ||
86 | field[l] = randInt(0, f - w); | ||
87 | } | ||
88 | startTime = time(NULL); | ||
89 | clock(); | ||
90 | |||
91 | START_LOOP | ||
92 | for (l = 0; l < n; l++) { | ||
93 | unsigned int index; | ||
94 | unsigned int minStop, maxStop; | ||
95 | unsigned int hops; | ||
96 | |||
97 | hops = 0; | ||
98 | minStop = thread[l].minStop; | ||
99 | maxStop = thread[l].maxStop; | ||
100 | index = thread[l].initial; | ||
101 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { | ||
102 | |||
103 | unsigned int ll, lll; | ||
104 | unsigned int max, min; | ||
105 | unsigned int partition; | ||
106 | unsigned int high; | ||
107 | |||
108 | partition = field[index]; | ||
109 | max = MAX_FIELD_SIZE; | ||
110 | min = 0; | ||
111 | high = 0; | ||
112 | |||
113 | for (ll = 0; ll < w; ll++) { | ||
114 | unsigned int balance; | ||
115 | unsigned int x; | ||
116 | x = field[index + ll]; | ||
117 | |||
118 | if (x > max) | ||
119 | high++; | ||
120 | else if (x > min) { /* start else* */ | ||
121 | partition = x; | ||
122 | balance = 0; | ||
123 | for (lll = ll + 1; lll < w; lll++) { | ||
124 | if (field[index + lll] > partition) | ||
125 | balance++; | ||
126 | } /* end for loop */ | ||
127 | |||
128 | if (balance + high == w / 2) | ||
129 | break; | ||
130 | else if (balance + high > w / 2) { | ||
131 | min = partition; | ||
132 | } /* end if */ | ||
133 | else { | ||
134 | max = partition; | ||
135 | high++; | ||
136 | } /* end else */ | ||
137 | } | ||
138 | if (min == max) | ||
139 | break; | ||
140 | } /* end else* */ | ||
141 | index = (partition + hops) % (f - w); | ||
142 | hops++; | ||
143 | } /* end loop ll */ | ||
144 | thread[l].hops = hops; | ||
145 | } /* end while */ | ||
146 | STOP_LOOP | ||
147 | |||
148 | endTime = time(NULL); | ||
149 | |||
150 | volatile int _stop_optimizer = thread[l].hops + l; | ||
151 | /*for (l=0; l<n; l++){ | ||
152 | fprintf(stdout, "%lu hops on thread %d\n", thread[l].hops, l); | ||
153 | }*/ | ||
154 | |||
155 | fprintf(stderr, "time for pointer stressmark = %f seconds.\n", | ||
156 | difftime(endTime, startTime)); | ||
157 | free(field); | ||
158 | free(thread); | ||
159 | WRITE_TO_FILE | ||
161 | } | 160 | } |