diff options
Diffstat (limited to 'dis/original/Pointer/pointer.c')
-rw-r--r-- | dis/original/Pointer/pointer.c | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/dis/original/Pointer/pointer.c b/dis/original/Pointer/pointer.c new file mode 100644 index 0000000..0c4966f --- /dev/null +++ b/dis/original/Pointer/pointer.c | |||
@@ -0,0 +1,155 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Pointer 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 | #include <stdio.h> | ||
16 | #include <time.h> | ||
17 | #include <assert.h> | ||
18 | #include <stdlib.h> | ||
19 | #include "DISstressmarkRNG.h" | ||
20 | |||
21 | #define MIN_FIELD_SIZE 16 | ||
22 | #define MAX_FIELD_SIZE 16777216 | ||
23 | #define MIN_WINDOW_SIZE 1 | ||
24 | #define MAX_WINDOW_SIZE 15 | ||
25 | #define MIN_HOP_LIMIT 1 | ||
26 | |||
27 | #define MAX_HOP_LIMIT 4294967295U | ||
28 | |||
29 | #define MIN_SEED -2147483647 | ||
30 | #define MAX_SEED -1 | ||
31 | #define MIN_THREADS 1 | ||
32 | #define MAX_THREADS 256 | ||
33 | |||
34 | /* | ||
35 | * main() | ||
36 | */ | ||
37 | int main(){ | ||
38 | |||
39 | unsigned int *field; | ||
40 | unsigned int f; | ||
41 | unsigned short int w; | ||
42 | unsigned int maxhops; | ||
43 | int seed; | ||
44 | unsigned int n; | ||
45 | |||
46 | clock_t startTime; | ||
47 | |||
48 | struct threadS{ | ||
49 | unsigned int initial; | ||
50 | unsigned int minStop; | ||
51 | unsigned int maxStop; | ||
52 | unsigned int hops; | ||
53 | }*thread; | ||
54 | |||
55 | unsigned int l; | ||
56 | |||
57 | fscanf(stdin, "%lu %u %lu %ld %u", | ||
58 | &f, &l, &maxhops, &seed, &n); | ||
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 | |||
68 | assert ((n >= MIN_THREADS) && (n <= MAX_THREADS)); | ||
69 | if ((thread = (struct threadS *)malloc(n*sizeof(struct threadS))) == NULL) | ||
70 | return (-1); | ||
71 | |||
72 | for (l=0; l<n; l++){ | ||
73 | fscanf(stdin, "%lu %lu %lu", | ||
74 | &(thread[l].initial), &(thread[l].minStop), &(thread[l].maxStop)); | ||
75 | assert ((thread[l].initial >= 0) && (thread[l].initial < f)); | ||
76 | assert ((thread[l].minStop >= 0) && (thread[l].minStop < f)); | ||
77 | assert ((thread[l].maxStop >= 0) && (thread[l].maxStop < f)); | ||
78 | } | ||
79 | |||
80 | if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) | ||
81 | return (-1); | ||
82 | |||
83 | randInit(seed); | ||
84 | for (l=0; l<f; l++){ | ||
85 | field[l] = randInt(0, f-w); | ||
86 | } | ||
87 | |||
88 | startTime = time(NULL); | ||
89 | clock(); | ||
90 | |||
91 | for (l=0; l<n; l++) | ||
92 | { | ||
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) && | ||
102 | (!((index >= minStop) && | ||
103 | (index < maxStop)))){ | ||
104 | |||
105 | unsigned int ll, lll; | ||
106 | unsigned int max, min; | ||
107 | unsigned int partition; | ||
108 | unsigned int high; | ||
109 | |||
110 | partition = field[index]; | ||
111 | max = MAX_FIELD_SIZE; | ||
112 | min = 0; | ||
113 | high = 0; | ||
114 | |||
115 | for (ll=0; ll<w; ll++){ | ||
116 | unsigned int balance; | ||
117 | unsigned int x; | ||
118 | x = field[index+ll]; | ||
119 | |||
120 | if (x > max) high++; | ||
121 | else if (x > min){ /* start else* */ | ||
122 | partition = x; | ||
123 | balance = 0; | ||
124 | for (lll=ll+1; lll<w; lll++){ | ||
125 | if (field[index+lll] > partition) balance++; | ||
126 | }/* end for loop */ | ||
127 | |||
128 | if (balance+high == w/2) break; | ||
129 | else if (balance+high > w/2){ | ||
130 | min = partition; | ||
131 | }/* end if */ | ||
132 | else { | ||
133 | max = partition; | ||
134 | high++; | ||
135 | }/* end else */ | ||
136 | } | ||
137 | if (min == max) break; | ||
138 | } /* end else* */ | ||
139 | index = (partition+hops)%(f-w); | ||
140 | hops++; | ||
141 | }/* end loop ll */ | ||
142 | thread[l].hops = hops; | ||
143 | } /* end while */ | ||
144 | |||
145 | startTime = time(NULL) - startTime; | ||
146 | |||
147 | for (l=0; l<n; l++){ | ||
148 | fprintf(stdout, "%lu hops on thread %d\n", thread[l].hops, l); | ||
149 | } | ||
150 | |||
151 | fprintf(stderr, "total time = %u seconds.\n", (unsigned int)startTime); | ||
152 | free (field); | ||
153 | free (thread); | ||
154 | |||
155 | } | ||