diff options
-rw-r--r-- | dis/original/Field/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/original/Field/field.c | 148 | ||||
-rw-r--r-- | dis/original/Makefile | 24 | ||||
-rwxr-xr-x | dis/original/Matrix/ver1/DISstressmarkRNG.h | 190 | ||||
-rwxr-xr-x | dis/original/Matrix/ver1/matrix.c | 600 | ||||
-rwxr-xr-x | dis/original/Matrix/ver2/DISstressmarkRNG.h | 190 | ||||
-rwxr-xr-x | dis/original/Matrix/ver2/matrix.c | 586 | ||||
-rw-r--r-- | dis/original/Neighborhood/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/original/Neighborhood/neighborhood.c | 100 | ||||
-rw-r--r-- | dis/original/Neighborhood/utili.h | 363 | ||||
-rw-r--r-- | dis/original/Pointer/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/original/Pointer/pointer.c | 155 | ||||
-rw-r--r-- | dis/original/Transitive/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/original/Transitive/transitive.c | 123 | ||||
-rw-r--r-- | dis/original/Update/DISstressmarkRNG.h | 190 | ||||
-rw-r--r-- | dis/original/Update/update.c | 133 |
16 files changed, 3562 insertions, 0 deletions
diff --git a/dis/original/Field/DISstressmarkRNG.h b/dis/original/Field/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Field/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/original/Field/field.c b/dis/original/Field/field.c new file mode 100644 index 0000000..7d26d37 --- /dev/null +++ b/dis/original/Field/field.c | |||
@@ -0,0 +1,148 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Field 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 <time.h> | ||
18 | #include <assert.h> | ||
19 | #include <stdlib.h> | ||
20 | #include "DISstressmarkRNG.h" | ||
21 | |||
22 | |||
23 | #define MIN_FIELD_SIZE 16 | ||
24 | #define MAX_FIELD_SIZE 16777216 | ||
25 | #define MIN_SEED -2147483647 | ||
26 | #define MAX_SEED -1 | ||
27 | #define MIN_MOD_OFFSET 0 | ||
28 | #define MAX_MOD_OFFSET 65535 | ||
29 | #define MIN_TOKENS 1 | ||
30 | #define MAX_TOKENS 256 | ||
31 | #define MIN_TOKEN_LENGTH 1 | ||
32 | #define MAX_TOKEN_LENGTH 8 | ||
33 | #define MIN_TOKEN_VALUE 0 | ||
34 | #define MAX_TOKEN_VALUE 255 | ||
35 | #define MAX_SUBFIELDS 256 | ||
36 | |||
37 | /* | ||
38 | * main() | ||
39 | */ | ||
40 | |||
41 | int main(){ | ||
42 | |||
43 | unsigned char *field; | ||
44 | unsigned int f; | ||
45 | int seed; | ||
46 | int mod_offset; | ||
47 | unsigned int n; | ||
48 | |||
49 | time_t startTime; | ||
50 | |||
51 | struct tokenS{ | ||
52 | unsigned char delimiter[MAX_TOKEN_LENGTH]; | ||
53 | unsigned char length; | ||
54 | struct statisticS{ | ||
55 | unsigned int count; | ||
56 | unsigned char min; | ||
57 | unsigned char sum; | ||
58 | }stat[MAX_SUBFIELDS]; | ||
59 | unsigned char subfields; | ||
60 | }token[MAX_TOKENS]; | ||
61 | |||
62 | unsigned int l; | ||
63 | |||
64 | fscanf(stdin, "%d %d %d %d", &f, &seed, &mod_offset, &n); | ||
65 | |||
66 | assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); | ||
67 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
68 | assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET)); | ||
69 | assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS)); | ||
70 | for (l=0; l<n; l++){ | ||
71 | int x; | ||
72 | int index; | ||
73 | index = 0; | ||
74 | fscanf(stdin,"%x", &x); | ||
75 | while(x!=0){ | ||
76 | assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE)); | ||
77 | token[l].delimiter[index] = (unsigned char )x; | ||
78 | index++; | ||
79 | fscanf(stdin,"%x", &x); | ||
80 | } | ||
81 | assert((index >= MIN_TOKEN_LENGTH) && (index <= MAX_TOKEN_LENGTH)); | ||
82 | token[l].length = index; | ||
83 | } | ||
84 | |||
85 | if ((field = (unsigned char*)malloc(f*sizeof(unsigned char))) == NULL) | ||
86 | return (-1); | ||
87 | |||
88 | randInit(seed); | ||
89 | for (l =0; l<f; l++){ | ||
90 | field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE); | ||
91 | } | ||
92 | |||
93 | startTime = time(NULL); | ||
94 | |||
95 | for (l =0; l<n; l++){ | ||
96 | unsigned int index; | ||
97 | |||
98 | token[l].subfields = 0; | ||
99 | token[l].stat[0].count = 0; | ||
100 | token[l].stat[0].sum = 0; | ||
101 | token[l].stat[0].min = MAX_TOKEN_VALUE; | ||
102 | |||
103 | index = 0; | ||
104 | while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)){ | ||
105 | unsigned char offset; | ||
106 | offset = 0; | ||
107 | while ((field[index+offset] == token[l].delimiter[offset]) && | ||
108 | (offset < token[l].length)){ | ||
109 | offset++; | ||
110 | } | ||
111 | |||
112 | if (offset == token[l].length){ | ||
113 | for (offset=0; offset<token[l].length; offset++){ | ||
114 | field[index+offset] = (field[index+offset] + | ||
115 | field[(index+offset+mod_offset) % f]) | ||
116 | %(MAX_TOKEN_VALUE+1); | ||
117 | } | ||
118 | index += token[l].length-1; | ||
119 | token[l].subfields++; | ||
120 | token[l].stat[token[l].subfields].count = 0; | ||
121 | token[l].stat[token[l].subfields].sum = 0; | ||
122 | token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE; | ||
123 | } | ||
124 | |||
125 | else{ | ||
126 | token[l].stat[token[l].subfields].count++; | ||
127 | token[l].stat[token[l].subfields].sum += field[index]; | ||
128 | if (token[l].stat[token[l].subfields].min > field[index]) | ||
129 | token[l].stat[token[l].subfields].min = field[index]; | ||
130 | } | ||
131 | index++; | ||
132 | } | ||
133 | } | ||
134 | |||
135 | startTime = time(NULL) - startTime; | ||
136 | |||
137 | for (l = 0; l< n; l++){ | ||
138 | unsigned int ll; | ||
139 | fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); | ||
140 | for ( ll =0; ll<token[l].subfields; ll++) | ||
141 | fprintf(stdout, "subfields %d:\tcount = %d\tmin= %x\tsum= %x\n", | ||
142 | ll, token[l].stat[ll].count, | ||
143 | token[l].stat[ll].min, token[l].stat[ll].sum); | ||
144 | } | ||
145 | fprintf(stdout, "total time = %d seconds.\n", (int)startTime); | ||
146 | free(field); | ||
147 | return(0); | ||
148 | } | ||
diff --git a/dis/original/Makefile b/dis/original/Makefile new file mode 100644 index 0000000..98634ac --- /dev/null +++ b/dis/original/Makefile | |||
@@ -0,0 +1,24 @@ | |||
1 | LIBLITMUS ?= /media/speedy/litmus/liblitmus | ||
2 | CC ?= gcc | ||
3 | CFLAGS = -pthread -O2 -I${LIBLITMUS}/include -I${LIBLITMUS}/arch/arm/include -I/playpen/jbakita/HRTSMT-RTSS19/FinalBenchmarkSetup/baseline/source | ||
4 | LDFLAGS = -lrt -lm -L${LIBLITMUS} -llitmus | ||
5 | COMMON = /playpen/jbakita/HRTSMT-RTSS19/FinalBenchmarkSetup/baseline/source/extra.h /media/speedy/litmus/tools/mmdc/mmdc.c | ||
6 | |||
7 | all: field matrix neighborhood pointer transitive update | ||
8 | |||
9 | .PHONY: clean | ||
10 | clean: | ||
11 | rm field matrix neighborhood pointer transitive update | ||
12 | |||
13 | field: ${COMMON} ./Field/field.c | ||
14 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
15 | matrix: ${COMMON} ./Matrix/ver2/matrix.c | ||
16 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
17 | neighborhood: ${COMMON} ./Neighborhood/neighborhood.c | ||
18 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
19 | pointer: ${COMMON} ./Pointer/pointer.c | ||
20 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
21 | transitive: ${COMMON} ./Transitive/transitive.c | ||
22 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
23 | update: ${COMMON} ./Update/update.c | ||
24 | $(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) | ||
diff --git a/dis/original/Matrix/ver1/DISstressmarkRNG.h b/dis/original/Matrix/ver1/DISstressmarkRNG.h new file mode 100755 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Matrix/ver1/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/original/Matrix/ver1/matrix.c b/dis/original/Matrix/ver1/matrix.c new file mode 100755 index 0000000..518a638 --- /dev/null +++ b/dis/original/Matrix/ver1/matrix.c | |||
@@ -0,0 +1,600 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Matrix 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 | /* | ||
17 | * The Sparse Matrix Storage is implemented by Compact Row Storage Scheme | ||
18 | * In the code, the data is first generated by randomNonzeroFloat() | ||
19 | * the data is first stored in a full-space matrix with size of dim*dim | ||
20 | * then the data is transfered to the Compact Row Matrix, | ||
21 | * the data value is kept in *value, | ||
22 | * the columns corresponding to the value are stored in *col_ind, | ||
23 | * the start element of each row is stored in *row_start. | ||
24 | */ | ||
25 | |||
26 | /* | ||
27 | * Please note: | ||
28 | * the total number of data is numberNonzero +dim | ||
29 | * among which, NumberNonzero because this is symmetric matrix | ||
30 | * dim because the diagonal elements | ||
31 | */ | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include <math.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <time.h> | ||
37 | #include <assert.h> | ||
38 | #include "DISstressmarkRNG.h" | ||
39 | |||
40 | #define MIN_SEED -2147483647 | ||
41 | #define MAX_SEED -1 | ||
42 | #define MIN_DIM 1 | ||
43 | #define MAX_DIM 32768 | ||
44 | #define MAX_ITERATIONS 65536 | ||
45 | #define MIN_TOLERANCE 0.000007 | ||
46 | #define MAX_TOLERANCE 0.5 | ||
47 | #define MIN_NUMBER -3.4e10/dim | ||
48 | #define MAX_NUMBER 3.4e10/dim | ||
49 | #define EPSI 1.0e-10 | ||
50 | #define MIN_DIG_NUMBER 1.0e-10 | ||
51 | #define MAX_DIG_NUMBER 3.4e10 | ||
52 | |||
53 | /* | ||
54 | * External variable, dimension | ||
55 | */ | ||
56 | |||
57 | static int dim; | ||
58 | |||
59 | /* | ||
60 | * matrix * vector | ||
61 | */ | ||
62 | |||
63 | double *matrixMulvector(double *value, | ||
64 | int *col_ind, | ||
65 | int *row_start, | ||
66 | double *vector) | ||
67 | { | ||
68 | int l, ll; | ||
69 | double *out; | ||
70 | double sum; | ||
71 | int tmp_rs, tmp_re; | ||
72 | |||
73 | out = (double *)malloc(dim*sizeof(double)); | ||
74 | |||
75 | for (l=0; l<dim; l++){ | ||
76 | *(out + l) = 0; | ||
77 | tmp_rs = row_start[l]; | ||
78 | |||
79 | if (tmp_rs != -1){ | ||
80 | tmp_re = row_start[l+1]; /* | ||
81 | *get the start and ending elements of | ||
82 | * each row | ||
83 | */ | ||
84 | for (ll=tmp_rs; ll<tmp_re; ll++){ | ||
85 | *(out + l) += value[ll]*vector[col_ind[ll]]; | ||
86 | } | ||
87 | } | ||
88 | } | ||
89 | return out; | ||
90 | } | ||
91 | |||
92 | |||
93 | /* | ||
94 | * vector1 - vector2 | ||
95 | */ | ||
96 | |||
97 | double *vectorSub(double *vector1, double *vector2){ | ||
98 | |||
99 | int l; | ||
100 | double *vector; | ||
101 | vector = (double *)malloc(dim*sizeof(double )); | ||
102 | for (l=0; l<dim; l++){ | ||
103 | *(vector + l) = *(vector1 + l) - *(vector2 + l); | ||
104 | } | ||
105 | return vector; | ||
106 | } | ||
107 | |||
108 | |||
109 | /* | ||
110 | * vector1 + vector2 | ||
111 | */ | ||
112 | |||
113 | double *vectorAdd(double *vector1, double *vector2){ | ||
114 | |||
115 | int l; | ||
116 | double *vector; | ||
117 | |||
118 | vector = (double *)malloc(dim*sizeof(double )); | ||
119 | |||
120 | for (l=0; l<dim; l++){ | ||
121 | *(vector + l) = *(vector1 + l) + *(vector2 + l); | ||
122 | } | ||
123 | return vector; | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * vector1 * vector2 | ||
128 | */ | ||
129 | |||
130 | double vectorMul(double *vector1, double *vector2){ | ||
131 | |||
132 | int l; | ||
133 | double product; | ||
134 | |||
135 | product = 0; | ||
136 | |||
137 | for (l=0; l<dim; l++){ | ||
138 | product += (*(vector1 + l))*(*(vector2 + l)); | ||
139 | |||
140 | } | ||
141 | return product; | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * /vector/ | ||
146 | */ | ||
147 | |||
148 | double vectorValue(double *vector){ | ||
149 | |||
150 | double value; | ||
151 | int l; | ||
152 | |||
153 | value = 0; | ||
154 | |||
155 | for (l=0; l<dim; l++){ | ||
156 | value += (*(vector + l)) * (*(vector + l)); | ||
157 | } | ||
158 | |||
159 | return (sqrt(value)); | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * transpose(vector) | ||
164 | * In fact, we return the original vector here | ||
165 | */ | ||
166 | |||
167 | double *transpose(double *vector){ | ||
168 | |||
169 | double *vect; | ||
170 | int l; | ||
171 | |||
172 | vect = (double *)malloc(dim*sizeof(double )); | ||
173 | |||
174 | for (l=0; l<dim; l++){ | ||
175 | *(vect+l) = *(vector+l); | ||
176 | } | ||
177 | return vect; | ||
178 | } | ||
179 | |||
180 | /* | ||
181 | * value * <vector> | ||
182 | */ | ||
183 | double *valueMulvector(double value, double *vector){ | ||
184 | |||
185 | int l; | ||
186 | double *vect; | ||
187 | int lll; | ||
188 | double sum; | ||
189 | |||
190 | vect = (double *) malloc(dim * sizeof(double )); | ||
191 | |||
192 | for (l=0; l<dim; l++){ | ||
193 | *(vect + l) = (*(vector + l)) * value; | ||
194 | } | ||
195 | |||
196 | return vect; | ||
197 | } | ||
198 | |||
199 | /* | ||
200 | * generate the data distributed sparsely in matrix | ||
201 | */ | ||
202 | |||
203 | void initMatrix(double *matrix, int dim, int numberNonzero){ | ||
204 | |||
205 | int k, l, ll; | ||
206 | int i, j; | ||
207 | |||
208 | int lll; | ||
209 | double sum; | ||
210 | |||
211 | for (k=0; k< dim*dim; k++){ | ||
212 | *(matrix + k) = 0; | ||
213 | } | ||
214 | |||
215 | for (l=0; l<numberNonzero/2; l++){ | ||
216 | |||
217 | i = randomUInt(1, dim-1); | ||
218 | j = randomUInt(0, i-1); | ||
219 | |||
220 | while (*(matrix + i*dim + j) != 0){ | ||
221 | |||
222 | i++; | ||
223 | if (i == dim){ | ||
224 | j++; | ||
225 | if (j == dim-1){ | ||
226 | j = 0; | ||
227 | i = 1; | ||
228 | } | ||
229 | else{ | ||
230 | i = j+1; | ||
231 | } | ||
232 | } | ||
233 | } | ||
234 | |||
235 | if (*(matrix + i*dim + j) == 0){ | ||
236 | *(matrix + i*dim + j) = (double )randomNonZeroFloat(MIN_NUMBER, | ||
237 | MAX_NUMBER, | ||
238 | EPSI); | ||
239 | *(matrix + j*dim + i) = *(matrix + i*dim + j); | ||
240 | } | ||
241 | } | ||
242 | |||
243 | for (ll=0; ll<dim; ll++){ | ||
244 | |||
245 | |||
246 | |||
247 | *(matrix + ll*dim + ll) = (double )randomNonZeroFloat(-MAX_DIG_NUMBER, | ||
248 | MAX_DIG_NUMBER, | ||
249 | MIN_DIG_NUMBER); | ||
250 | |||
251 | sum = 0; | ||
252 | |||
253 | for (lll=0; lll<dim; lll++){ | ||
254 | if (lll != ll){ | ||
255 | sum += *(matrix + lll*dim + ll); | ||
256 | } | ||
257 | } | ||
258 | |||
259 | if (*(matrix + ll*dim + ll) < sum ){ | ||
260 | *(matrix + ll*dim + ll) += sum; | ||
261 | } | ||
262 | } | ||
263 | |||
264 | return; | ||
265 | } | ||
266 | |||
267 | /* | ||
268 | * generate the data value in the vectors | ||
269 | */ | ||
270 | |||
271 | void initVector(double *vector, int dim){ | ||
272 | |||
273 | int l; | ||
274 | |||
275 | for (l=0; l<dim; l++){ | ||
276 | *(vector + l) = (double )randomFloat (MIN_NUMBER, MAX_NUMBER); | ||
277 | } | ||
278 | |||
279 | return; | ||
280 | } | ||
281 | |||
282 | /* | ||
283 | * make a vector contains value of zero | ||
284 | */ | ||
285 | |||
286 | void zeroVector(double *vector, int dim){ | ||
287 | int l; | ||
288 | |||
289 | for (l=0; l<dim; l++){ | ||
290 | *(vector + l) = 0; | ||
291 | } | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | /* | ||
296 | * return a vector which is the copy of the vect | ||
297 | */ | ||
298 | |||
299 | double *equalVector(double *vect){ | ||
300 | |||
301 | int l; | ||
302 | double *vect1; | ||
303 | |||
304 | vect1 = (double *)malloc(dim*sizeof(double )); | ||
305 | |||
306 | for (l=0; l<dim; l++){ | ||
307 | *(vect1+l) = *(vect+l); | ||
308 | } | ||
309 | return vect1; | ||
310 | } | ||
311 | |||
312 | |||
313 | |||
314 | void biConjugateGradient(double *value, | ||
315 | int *col_ind, | ||
316 | int *row_start, | ||
317 | double *vectorB, | ||
318 | double *vectorX, | ||
319 | double errorTolerance, | ||
320 | int maxIterations, | ||
321 | double *actualError, | ||
322 | int *actualIteration, | ||
323 | int dim) | ||
324 | /* | ||
325 | * in the code, we use a lot of temparary vectors and variables | ||
326 | * this is just for simple and clear | ||
327 | * you can optimize these temporary variables and vectors | ||
328 | * based on your need | ||
329 | * | ||
330 | */ | ||
331 | { | ||
332 | double *vectorR; | ||
333 | double *vectorP, *matrixAvectorP, *nextVectorR; | ||
334 | double error; | ||
335 | int iteration; | ||
336 | double alpha, beta; | ||
337 | |||
338 | double *temp0, *temp1,*temp2, *temp3; | ||
339 | double *temp4, temp5, temp6, *temp7 ; | ||
340 | double *temp8, *temp9, temp10, *temp11; | ||
341 | double temp12, *temp13, *temp14; | ||
342 | double *temp15, *temp16, *temp17; | ||
343 | |||
344 | int l; | ||
345 | int ll; | ||
346 | |||
347 | alpha = 0; | ||
348 | beta = 0; | ||
349 | |||
350 | /* | ||
351 | * vectorR = vectorB - matrixA*vectorX | ||
352 | */ | ||
353 | temp0 = matrixMulvector(value,col_ind, row_start, vectorX); | ||
354 | vectorR = vectorSub(vectorB, temp0); | ||
355 | |||
356 | /* | ||
357 | * vectorP = vectorR | ||
358 | */ | ||
359 | vectorP = equalVector(vectorR); | ||
360 | |||
361 | /* | ||
362 | * error = |matrixA * vectorX - vectorB| / |vectorB| | ||
363 | */ | ||
364 | temp2 = vectorSub(temp0, vectorB); | ||
365 | error = vectorValue(temp2)/vectorValue(vectorB); | ||
366 | |||
367 | free(temp0); | ||
368 | free (temp2); | ||
369 | |||
370 | iteration = 0; | ||
371 | |||
372 | |||
373 | while ((iteration < maxIterations) && (error > errorTolerance)){ | ||
374 | |||
375 | /* | ||
376 | * alpha = (transpose(vectorR) * vectorR) / | ||
377 | * (transpose(vectorP) * (matrixA * vectorP) | ||
378 | */ | ||
379 | temp1 = matrixMulvector(value, col_ind, row_start, vectorP); | ||
380 | temp3 = transpose(vectorR); | ||
381 | temp4 = transpose(vectorP); | ||
382 | temp5 = vectorMul(temp4, temp1); | ||
383 | temp6 = vectorMul(temp3, vectorR); | ||
384 | alpha = temp6/temp5; | ||
385 | |||
386 | /* | ||
387 | * nextVectorR = vectorR - alpha*(matrixA * vectorP) | ||
388 | */ | ||
389 | |||
390 | temp7 = valueMulvector(alpha, temp1); | ||
391 | temp8 = vectorSub(vectorR, temp7); | ||
392 | nextVectorR = equalVector(temp8); | ||
393 | |||
394 | /* | ||
395 | * beta = (transpose(nextVectorR) * nextVectorR) / | ||
396 | * (transpose(vectorR) * vectorR) | ||
397 | */ | ||
398 | temp9 = transpose(nextVectorR); | ||
399 | temp10 = vectorMul(temp9, nextVectorR); | ||
400 | temp11 = transpose(vectorR); | ||
401 | temp12 = vectorMul(temp11, vectorR); | ||
402 | beta = temp10/temp12; | ||
403 | |||
404 | /* | ||
405 | * vectorX = vectorX + alpha * vectorP | ||
406 | */ | ||
407 | temp13 = valueMulvector(alpha, vectorP); | ||
408 | vectorX = vectorAdd(vectorX,temp13); | ||
409 | |||
410 | /* | ||
411 | *vectorP = nextVectorR + beta*vectorP | ||
412 | */ | ||
413 | temp14 = valueMulvector(beta, vectorP); | ||
414 | temp17 = vectorAdd(nextVectorR, temp14); | ||
415 | |||
416 | for (ll=0; ll<dim; ll++){ | ||
417 | *(vectorP + ll) = *(temp17 + ll); | ||
418 | } | ||
419 | |||
420 | /* | ||
421 | * vectorR = nextVectorR | ||
422 | */ | ||
423 | |||
424 | for (l=0; l<dim; l++){ | ||
425 | *(vectorR+l) = *(nextVectorR+l); | ||
426 | } | ||
427 | |||
428 | /* | ||
429 | * error = |matrixA * vectorX - vectorB| / |vectorB| | ||
430 | */ | ||
431 | temp15 = matrixMulvector(value, col_ind,row_start, vectorX); | ||
432 | temp16 = vectorSub(temp15,vectorB); | ||
433 | error = vectorValue(temp16)/vectorValue(vectorB); | ||
434 | |||
435 | free(temp1); | ||
436 | free(temp3); | ||
437 | free(temp4); | ||
438 | free(temp7); | ||
439 | free(temp8); | ||
440 | free(temp9); | ||
441 | free(temp11); | ||
442 | free(nextVectorR); | ||
443 | free(temp13); | ||
444 | free(temp14); | ||
445 | free(temp15); | ||
446 | free(temp16); | ||
447 | free(temp17); | ||
448 | |||
449 | iteration++; | ||
450 | } | ||
451 | |||
452 | *actualError = error; | ||
453 | *actualIteration = iteration; | ||
454 | |||
455 | free(vectorR); | ||
456 | free(vectorP); | ||
457 | |||
458 | return; | ||
459 | } | ||
460 | |||
461 | /* | ||
462 | * This is the function to transfer the data from the matrix of dense storage | ||
463 | * to Compact Row Storage | ||
464 | */ | ||
465 | void create_CRS(double *matrixA, | ||
466 | double *value, | ||
467 | int *col_ind, | ||
468 | int *row_start, | ||
469 | int dim, | ||
470 | int numberNonzero) | ||
471 | { | ||
472 | |||
473 | int i, j, k; | ||
474 | int cnt; | ||
475 | double tmp; | ||
476 | |||
477 | /* | ||
478 | *initialize the row_start | ||
479 | */ | ||
480 | |||
481 | for(k=0; k<dim; k++){ | ||
482 | row_start[k] = -1; | ||
483 | } | ||
484 | |||
485 | /* | ||
486 | * make the end of the last row to be numberNonzero + dim. | ||
487 | */ | ||
488 | |||
489 | row_start[dim] = numberNonzero+dim; | ||
490 | |||
491 | /* | ||
492 | * initialize the col_ind | ||
493 | */ | ||
494 | |||
495 | for (k=0; k<numberNonzero+dim; k++){ | ||
496 | col_ind[k] = -1; | ||
497 | } | ||
498 | |||
499 | |||
500 | cnt = 0; | ||
501 | |||
502 | for (i=0; (cnt<numberNonzero+dim)&&(i<dim); i++){ | ||
503 | for (j=0; (cnt<numberNonzero+dim)&&(j<dim); j++){ | ||
504 | |||
505 | tmp = *(matrixA + i*dim + j); | ||
506 | |||
507 | if (tmp!=0){ | ||
508 | |||
509 | value[cnt] = tmp; | ||
510 | col_ind[cnt] = j; | ||
511 | |||
512 | if (row_start[i] == -1) | ||
513 | row_start[i] = cnt; | ||
514 | |||
515 | cnt += 1; | ||
516 | } | ||
517 | } | ||
518 | } | ||
519 | row_start[i] = cnt; | ||
520 | |||
521 | return; | ||
522 | } | ||
523 | |||
524 | |||
525 | |||
526 | int main() | ||
527 | { | ||
528 | int seed; | ||
529 | int numberNonzero; | ||
530 | int maxIterations; | ||
531 | float errorTolerance; | ||
532 | double actualError; | ||
533 | int actualIteration; | ||
534 | |||
535 | time_t beginTime; | ||
536 | time_t endTime; | ||
537 | |||
538 | double *matrixA; | ||
539 | double *vectorB; | ||
540 | double *vectorX; | ||
541 | |||
542 | double *value; | ||
543 | int *col_ind; | ||
544 | int *row_start; | ||
545 | int sum; | ||
546 | int k; | ||
547 | |||
548 | fscanf(stdin, "%d %d %d %d %f", | ||
549 | &seed, &dim, &numberNonzero,&maxIterations,&errorTolerance); | ||
550 | assert((seed > MIN_SEED) && (seed < MAX_SEED)); | ||
551 | assert((dim > MIN_DIM) && (dim < MAX_DIM)); | ||
552 | assert((numberNonzero > dim) && (numberNonzero < dim*dim)); | ||
553 | assert((maxIterations > 0) && (maxIterations < MAX_ITERATIONS)); | ||
554 | assert((errorTolerance > MIN_TOLERANCE) && (errorTolerance < MAX_TOLERANCE)); | ||
555 | |||
556 | matrixA = (double *)malloc(dim*dim*sizeof(double )); | ||
557 | vectorB = (double *)malloc(dim*sizeof(double)); | ||
558 | vectorX = (double *)malloc(dim*sizeof(double)); | ||
559 | |||
560 | value = (double *)malloc((numberNonzero+dim)*sizeof(double)); | ||
561 | col_ind = (int *)malloc((numberNonzero+dim)*sizeof(int)); | ||
562 | row_start = (int *)malloc((dim+1)*sizeof(int)); | ||
563 | |||
564 | randInit(seed); | ||
565 | |||
566 | initMatrix(matrixA, dim, numberNonzero); | ||
567 | |||
568 | create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); | ||
569 | |||
570 | initVector(vectorB, dim); | ||
571 | zeroVector(vectorX, dim); | ||
572 | printf(" after init\n"); | ||
573 | |||
574 | beginTime = time(NULL); | ||
575 | |||
576 | actualError = 0; | ||
577 | actualIteration = 0; | ||
578 | |||
579 | biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, errorTolerance, | ||
580 | maxIterations, | ||
581 | &actualError, &actualIteration, dim); | ||
582 | |||
583 | |||
584 | |||
585 | endTime = time(NULL) - beginTime; | ||
586 | |||
587 | |||
588 | |||
589 | sum = 0; | ||
590 | for (k=1; k<dim; k++){ | ||
591 | sum += sum + *(vectorX + k); | ||
592 | } | ||
593 | |||
594 | fprintf(stdout, "sum = %d, actualError = %e, actualIteration = %d\n", sum, actualError, actualIteration); | ||
595 | fprintf(stdout, "total time = %u sec. \n", (unsigned int)endTime); | ||
596 | |||
597 | return(0); | ||
598 | } | ||
599 | |||
600 | |||
diff --git a/dis/original/Matrix/ver2/DISstressmarkRNG.h b/dis/original/Matrix/ver2/DISstressmarkRNG.h new file mode 100755 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Matrix/ver2/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/original/Matrix/ver2/matrix.c b/dis/original/Matrix/ver2/matrix.c new file mode 100755 index 0000000..56245a6 --- /dev/null +++ b/dis/original/Matrix/ver2/matrix.c | |||
@@ -0,0 +1,586 @@ | |||
1 | /* Please note: | ||
2 | * This code is the optimized version of the first version of Matrix | ||
3 | * Stressmark. It uses less temporary vectors and vsariables, thus reduce | ||
4 | * memory allocation/deallocation overhead. the simulation is faster | ||
5 | */ | ||
6 | /* | ||
7 | * Sample code for the DIS Matrix Stressmark | ||
8 | * | ||
9 | * This source code is the completely correct source code based on | ||
10 | * the example codes provided by Atlantic Aerospace Division, Titan | ||
11 | * Systems Corporation, 2000. | ||
12 | * | ||
13 | * If you just compile and generate the executables from this source | ||
14 | * code, this code would be enough. However, if you wish to get a complete | ||
15 | * understanding of this stressmark, it is strongly suggested that you | ||
16 | * read the Benchmark Analysis and Specifications Document Version 1.0 | ||
17 | * before going on since the detailed comments are given in this documents. | ||
18 | * the comments are not repeated here. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | * The Sparse Matrix Storage is implemented by Compact Row Storage Scheme | ||
23 | * In the code, the data is first generated by randomNonzeroFloat() | ||
24 | * the data is first stored in a full-space matrix with size of dim*dim | ||
25 | * then the data is transfered to the Compact Row Matrix, | ||
26 | * the data value is kept in *value, | ||
27 | * the columns corresponding to the value are stored in *col_ind, | ||
28 | * the start element of each row is stored in *row_start. | ||
29 | */ | ||
30 | |||
31 | /* | ||
32 | * Please note: | ||
33 | * the total number of data is numberNonzero +dim | ||
34 | * among which, NumberNonzero because this is symmetric matrix | ||
35 | * dim because the diagonal elements | ||
36 | */ | ||
37 | |||
38 | #include <stdio.h> | ||
39 | #include <math.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <time.h> | ||
42 | #include <assert.h> | ||
43 | #include "DISstressmarkRNG.h" | ||
44 | |||
45 | #define MIN_SEED -2147483647 | ||
46 | #define MAX_SEED -1 | ||
47 | #define MIN_DIM 1 | ||
48 | #define MAX_DIM 32768 | ||
49 | #define MAX_ITERATIONS 65536 | ||
50 | #define MIN_TOLERANCE 0.000007 | ||
51 | #define MAX_TOLERANCE 0.5 | ||
52 | #define MIN_NUMBER -3.4e10/dim | ||
53 | #define MAX_NUMBER 3.4e10/dim | ||
54 | #define EPSI 1.0e-10 | ||
55 | #define MIN_DIG_NUMBER 1.0e-10 | ||
56 | #define MAX_DIG_NUMBER 3.4e10 | ||
57 | |||
58 | /* | ||
59 | * External variable, dimension | ||
60 | */ | ||
61 | |||
62 | static int dim; | ||
63 | |||
64 | /* | ||
65 | * matrix * vector | ||
66 | */ | ||
67 | |||
68 | void matrixMulvector(double *value, | ||
69 | int *col_ind, | ||
70 | int *row_start, | ||
71 | double *vector, | ||
72 | double *out) | ||
73 | { | ||
74 | int l, ll; | ||
75 | double sum; | ||
76 | int tmp_rs, tmp_re; | ||
77 | |||
78 | for (l=0; l<dim; l++){ | ||
79 | *(out + l) = 0; | ||
80 | tmp_rs = row_start[l]; | ||
81 | |||
82 | if (tmp_rs != -1){ | ||
83 | tmp_re = row_start[l+1]; /* | ||
84 | *get the start and ending elements of | ||
85 | * each row | ||
86 | */ | ||
87 | for (ll=tmp_rs; ll<tmp_re; ll++){ | ||
88 | *(out + l) += value[ll]*vector[col_ind[ll]]; | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | |||
96 | /* | ||
97 | * vector1 - vector2 | ||
98 | */ | ||
99 | |||
100 | void vectorSub(double *vector1, double *vector2, double *vector){ | ||
101 | |||
102 | int l; | ||
103 | |||
104 | for (l=0; l<dim; l++){ | ||
105 | *(vector + l) = *(vector1 + l) - *(vector2 + l); | ||
106 | } | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | |||
111 | /* | ||
112 | * vector1 + vector2 | ||
113 | */ | ||
114 | |||
115 | void vectorAdd(double *vector1, double *vector2, double *vector){ | ||
116 | |||
117 | int l; | ||
118 | |||
119 | for (l=0; l<dim; l++){ | ||
120 | *(vector + l) = *(vector1 + l) + *(vector2 + l); | ||
121 | } | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * vector1 * vector2 | ||
127 | */ | ||
128 | |||
129 | double vectorMul(double *vector1, double *vector2){ | ||
130 | |||
131 | int l; | ||
132 | double product; | ||
133 | |||
134 | product = 0; | ||
135 | |||
136 | for (l=0; l<dim; l++){ | ||
137 | product += (*(vector1 + l))*(*(vector2 + l)); | ||
138 | |||
139 | } | ||
140 | return product; | ||
141 | } | ||
142 | |||
143 | /* | ||
144 | * /vector/ | ||
145 | */ | ||
146 | |||
147 | double vectorValue(double *vector){ | ||
148 | |||
149 | double value; | ||
150 | int l; | ||
151 | |||
152 | value = 0; | ||
153 | |||
154 | for (l=0; l<dim; l++){ | ||
155 | value += (*(vector + l)) * (*(vector + l)); | ||
156 | } | ||
157 | |||
158 | return (sqrt(value)); | ||
159 | } | ||
160 | |||
161 | /* | ||
162 | * transpose(vector) | ||
163 | * In fact, we return the original vector here | ||
164 | */ | ||
165 | |||
166 | void transpose(double *vector, double *vect){ | ||
167 | |||
168 | int l; | ||
169 | |||
170 | for (l=0; l<dim; l++){ | ||
171 | *(vect+l) = *(vector+l); | ||
172 | } | ||
173 | return; | ||
174 | } | ||
175 | |||
176 | /* | ||
177 | * value * <vector> | ||
178 | */ | ||
179 | void valueMulvector(double value, double *vector, double *vect){ | ||
180 | |||
181 | int l; | ||
182 | int lll, i; | ||
183 | double tmp; | ||
184 | |||
185 | for (l=0; l<dim; l++){ | ||
186 | *(vect + l) = *(vector + l) * value; | ||
187 | } | ||
188 | return; | ||
189 | } | ||
190 | |||
191 | /* | ||
192 | * generate the data distributed sparsely in matrix | ||
193 | */ | ||
194 | |||
195 | void initMatrix(double *matrix, int dim, int numberNonzero){ | ||
196 | |||
197 | int k, l, ll; | ||
198 | int i, j; | ||
199 | |||
200 | int lll; | ||
201 | double sum; | ||
202 | |||
203 | for (k=0; k< dim*dim; k++){ | ||
204 | *(matrix + k) = 0; | ||
205 | } | ||
206 | |||
207 | for (l=0; l<numberNonzero/2; l++){ | ||
208 | |||
209 | i = randomUInt(1, dim-1); | ||
210 | j = randomUInt(0, i-1); | ||
211 | |||
212 | while (*(matrix + i*dim + j) != 0){ | ||
213 | |||
214 | i++; | ||
215 | if (i == dim){ | ||
216 | j++; | ||
217 | if (j == dim-1){ | ||
218 | j = 0; | ||
219 | i = 1; | ||
220 | } | ||
221 | else{ | ||
222 | i = j+1; | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | if (*(matrix + i*dim + j) == 0){ | ||
228 | *(matrix + i*dim + j) = (double )randomNonZeroFloat(MIN_NUMBER, | ||
229 | MAX_NUMBER, | ||
230 | EPSI); | ||
231 | *(matrix + j*dim + i) = *(matrix + i*dim + j); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | for (ll=0; ll<dim; ll++){ | ||
236 | |||
237 | |||
238 | |||
239 | *(matrix + ll*dim + ll) = (double )randomNonZeroFloat(-MAX_DIG_NUMBER, | ||
240 | MAX_DIG_NUMBER, | ||
241 | MIN_DIG_NUMBER); | ||
242 | |||
243 | sum = 0; | ||
244 | |||
245 | for (lll=0; lll<dim; lll++){ | ||
246 | if (lll != ll){ | ||
247 | sum += *(matrix + lll*dim + ll); | ||
248 | } | ||
249 | } | ||
250 | |||
251 | if (*(matrix + ll*dim + ll) < sum ){ | ||
252 | *(matrix + ll*dim + ll) += sum; | ||
253 | } | ||
254 | } | ||
255 | |||
256 | return; | ||
257 | } | ||
258 | |||
259 | /* | ||
260 | * generate the data value in the vectors | ||
261 | */ | ||
262 | |||
263 | void initVector(double *vector, int dim){ | ||
264 | |||
265 | int l; | ||
266 | |||
267 | for (l=0; l<dim; l++){ | ||
268 | *(vector + l) = (double )randomFloat (MIN_NUMBER, MAX_NUMBER); | ||
269 | } | ||
270 | |||
271 | return; | ||
272 | } | ||
273 | |||
274 | /* | ||
275 | * make a vector contains value of zero | ||
276 | */ | ||
277 | |||
278 | void zeroVector(double *vector, int dim){ | ||
279 | int l; | ||
280 | |||
281 | for (l=0; l<dim; l++){ | ||
282 | *(vector + l) = 0; | ||
283 | } | ||
284 | return; | ||
285 | } | ||
286 | |||
287 | /* | ||
288 | * return a vector which is the copy of the vect | ||
289 | */ | ||
290 | |||
291 | void equalVector(double *vect, double *vect1){ | ||
292 | |||
293 | int l; | ||
294 | |||
295 | for (l=0; l<dim; l++){ | ||
296 | *(vect1+l) = *(vect+l); | ||
297 | } | ||
298 | return; | ||
299 | } | ||
300 | |||
301 | |||
302 | |||
303 | void biConjugateGradient(double *value, | ||
304 | int *col_ind, | ||
305 | int *row_start, | ||
306 | double *vectorB, | ||
307 | double *vectorX, | ||
308 | double errorTolerance, | ||
309 | int maxIterations, | ||
310 | double *actualError, | ||
311 | int *actualIteration, | ||
312 | int dim) | ||
313 | /* | ||
314 | * in the code, we use a lot of temparary vectors and variables | ||
315 | * this is just for simple and clear | ||
316 | * you can optimize these temporary variables and vectors | ||
317 | * based on your need | ||
318 | * | ||
319 | */ | ||
320 | { | ||
321 | double *vectorR; | ||
322 | double *vectorP, *matrixAvectorP, *nextVectorR; | ||
323 | double error; | ||
324 | int iteration; | ||
325 | double alpha, beta; | ||
326 | |||
327 | double *tmpVector1, *tmpVector2, *tmpVector3; | ||
328 | double tmpValue1, tmpValue2; | ||
329 | int i; | ||
330 | int l; | ||
331 | int ll; | ||
332 | |||
333 | alpha = 0; | ||
334 | beta = 0; | ||
335 | |||
336 | vectorP = (double *)malloc(dim*sizeof(double)); | ||
337 | vectorR = (double *)malloc(dim*sizeof(double)); | ||
338 | nextVectorR = (double *)malloc(dim*sizeof(double)); | ||
339 | vectorX = (double *)malloc(dim*sizeof(double)); | ||
340 | |||
341 | tmpVector1 = (double *)malloc(dim*sizeof(double)); | ||
342 | tmpVector2 = (double *)malloc(dim*sizeof(double)); | ||
343 | tmpVector3 = (double *)malloc(dim*sizeof(double)); | ||
344 | |||
345 | /* | ||
346 | * vectorR = vectorB - matrixA*vectorX | ||
347 | */ | ||
348 | matrixMulvector(value,col_ind, row_start, vectorX, tmpVector1); | ||
349 | |||
350 | vectorSub(vectorB, tmpVector1, vectorR); | ||
351 | |||
352 | /* | ||
353 | * vectorP = vectorR | ||
354 | */ | ||
355 | |||
356 | equalVector(vectorR, vectorP); | ||
357 | |||
358 | /* | ||
359 | * error = |matrixA * vectorX - vectorB| / |vectorB| | ||
360 | */ | ||
361 | vectorSub(tmpVector1, vectorB, tmpVector1); | ||
362 | |||
363 | error = vectorValue(tmpVector1)/vectorValue(vectorB); | ||
364 | |||
365 | iteration = 0; | ||
366 | |||
367 | while ((iteration < maxIterations) && (error > errorTolerance)){ | ||
368 | |||
369 | /* | ||
370 | * alpha = (transpose(vectorR) * vectorR) / | ||
371 | * (transpose(vectorP) * (matrixA * vectorP) | ||
372 | */ | ||
373 | |||
374 | matrixMulvector(value, col_ind, row_start, vectorP, tmpVector1); | ||
375 | transpose(vectorR, tmpVector2); | ||
376 | transpose(vectorP, tmpVector3); | ||
377 | tmpValue1 = vectorMul(tmpVector3, tmpVector1); | ||
378 | tmpValue2 = vectorMul(tmpVector2, vectorR); | ||
379 | alpha = tmpValue2/tmpValue1; | ||
380 | |||
381 | /* | ||
382 | * nextVectorR = vectorR - alpha*(matrixA * vectorP) | ||
383 | */ | ||
384 | |||
385 | valueMulvector(alpha, tmpVector1, tmpVector2); | ||
386 | vectorSub(vectorR, tmpVector2, tmpVector1); | ||
387 | equalVector(tmpVector1, nextVectorR); | ||
388 | |||
389 | /* | ||
390 | * beta = (transpose(nextVectorR) * nextVectorR) / | ||
391 | * (transpose(vectorR) * vectorR) | ||
392 | */ | ||
393 | |||
394 | transpose(nextVectorR, tmpVector3); | ||
395 | tmpValue1 = vectorMul(tmpVector3, nextVectorR); | ||
396 | transpose(vectorR, tmpVector2); | ||
397 | tmpValue2 = vectorMul(tmpVector2, vectorR); | ||
398 | beta = tmpValue1/tmpValue2; | ||
399 | |||
400 | /* | ||
401 | * vectorX = vectorX + alpha * vectorP | ||
402 | */ | ||
403 | valueMulvector(alpha, vectorP, tmpVector1); | ||
404 | vectorAdd(vectorX,tmpVector1, vectorX); | ||
405 | |||
406 | /* | ||
407 | *vectorP = nextVectorR + beta*vectorP | ||
408 | */ | ||
409 | valueMulvector(beta, vectorP, tmpVector1); | ||
410 | vectorAdd(nextVectorR, tmpVector1, tmpVector1); | ||
411 | |||
412 | for (ll=0; ll<dim; ll++){ | ||
413 | *(vectorP + ll) = *(tmpVector1 + ll); | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * vectorR = nextVectorR | ||
418 | */ | ||
419 | |||
420 | for (l=0; l<dim; l++){ | ||
421 | *(vectorR+l) = *(nextVectorR+l); | ||
422 | } | ||
423 | |||
424 | /* | ||
425 | * error = |matrixA * vectorX - vectorB| / |vectorB| | ||
426 | */ | ||
427 | matrixMulvector(value, col_ind,row_start, vectorX, tmpVector1); | ||
428 | vectorSub(tmpVector1,vectorB,tmpVector1); | ||
429 | error = vectorValue(tmpVector1)/vectorValue(vectorB); | ||
430 | |||
431 | iteration++; | ||
432 | } | ||
433 | |||
434 | *actualError = error; | ||
435 | *actualIteration = iteration; | ||
436 | |||
437 | free(tmpVector1); | ||
438 | free(tmpVector2); | ||
439 | free(tmpVector3); | ||
440 | |||
441 | free(vectorR); | ||
442 | free(vectorP); | ||
443 | |||
444 | return; | ||
445 | } | ||
446 | |||
447 | /* | ||
448 | * This is the function to transfer the data from the matrix of dense storage | ||
449 | * to Compact Row Storage | ||
450 | */ | ||
451 | void create_CRS(double *matrixA, | ||
452 | double *value, | ||
453 | int *col_ind, | ||
454 | int *row_start, | ||
455 | int dim, | ||
456 | int numberNonzero) | ||
457 | { | ||
458 | |||
459 | int i, j, k; | ||
460 | int cnt; | ||
461 | double tmp; | ||
462 | |||
463 | /* | ||
464 | *initialize the row_start | ||
465 | */ | ||
466 | |||
467 | for(k=0; k<dim; k++){ | ||
468 | row_start[k] = -1; | ||
469 | } | ||
470 | |||
471 | /* | ||
472 | * make the end of the last row to be numberNonzero + dim. | ||
473 | */ | ||
474 | |||
475 | row_start[dim] = numberNonzero+dim; | ||
476 | |||
477 | /* | ||
478 | * initialize the col_ind | ||
479 | */ | ||
480 | |||
481 | for (k=0; k<numberNonzero+dim; k++){ | ||
482 | col_ind[k] = -1; | ||
483 | } | ||
484 | |||
485 | |||
486 | cnt = 0; | ||
487 | |||
488 | for (i=0; (cnt<numberNonzero+dim)&&(i<dim); i++){ | ||
489 | for (j=0; (cnt<numberNonzero+dim)&&(j<dim); j++){ | ||
490 | |||
491 | tmp = *(matrixA + i*dim + j); | ||
492 | |||
493 | if (tmp!=0){ | ||
494 | |||
495 | value[cnt] = tmp; | ||
496 | col_ind[cnt] = j; | ||
497 | |||
498 | if (row_start[i] == -1) | ||
499 | row_start[i] = cnt; | ||
500 | |||
501 | cnt += 1; | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | row_start[i] = cnt; | ||
506 | |||
507 | return; | ||
508 | } | ||
509 | |||
510 | |||
511 | |||
512 | int main() | ||
513 | { | ||
514 | int seed; | ||
515 | int numberNonzero; | ||
516 | int maxIterations; | ||
517 | float errorTolerance; | ||
518 | double actualError; | ||
519 | int actualIteration; | ||
520 | |||
521 | time_t beginTime; | ||
522 | time_t endTime; | ||
523 | |||
524 | double *matrixA; | ||
525 | double *vectorB; | ||
526 | double *vectorX; | ||
527 | |||
528 | double *value; | ||
529 | int *col_ind; | ||
530 | int *row_start; | ||
531 | int sum; | ||
532 | int k; | ||
533 | |||
534 | fscanf(stdin, "%d %d %d %d %f", | ||
535 | &seed, &dim, &numberNonzero,&maxIterations,&errorTolerance); | ||
536 | assert((seed > MIN_SEED) && (seed < MAX_SEED)); | ||
537 | assert((dim > MIN_DIM) && (dim < MAX_DIM)); | ||
538 | assert((numberNonzero > dim) && (numberNonzero < dim*dim)); | ||
539 | assert((maxIterations > 0) && (maxIterations < MAX_ITERATIONS)); | ||
540 | assert((errorTolerance > MIN_TOLERANCE) && (errorTolerance < MAX_TOLERANCE)); | ||
541 | |||
542 | matrixA = (double *)malloc(dim*dim*sizeof(double )); | ||
543 | vectorB = (double *)malloc(dim*sizeof(double)); | ||
544 | vectorX = (double *)malloc(dim*sizeof(double)); | ||
545 | |||
546 | value = (double *)malloc((numberNonzero+dim)*sizeof(double)); | ||
547 | col_ind = (int *)malloc((numberNonzero+dim)*sizeof(int)); | ||
548 | row_start = (int *)malloc((dim+1)*sizeof(int)); | ||
549 | |||
550 | randInit(seed); | ||
551 | |||
552 | initMatrix(matrixA, dim, numberNonzero); | ||
553 | |||
554 | create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); | ||
555 | |||
556 | initVector(vectorB, dim); | ||
557 | zeroVector(vectorX, dim); | ||
558 | printf(" after init\n"); | ||
559 | |||
560 | beginTime = time(NULL); | ||
561 | |||
562 | actualError = 0; | ||
563 | actualIteration = 0; | ||
564 | |||
565 | biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, errorTolerance, | ||
566 | maxIterations, | ||
567 | &actualError, &actualIteration, dim); | ||
568 | |||
569 | |||
570 | |||
571 | endTime = time(NULL) - beginTime; | ||
572 | |||
573 | |||
574 | |||
575 | sum = 0; | ||
576 | for (k=1; k<dim; k++){ | ||
577 | sum += sum + *(vectorX + k); | ||
578 | } | ||
579 | |||
580 | fprintf(stdout, "sum = %d, actualError = %e, actualIteration = %d\n", sum, actualError, actualIteration); | ||
581 | fprintf(stdout, "total time = %u sec. \n", (unsigned int)endTime); | ||
582 | |||
583 | return(0); | ||
584 | } | ||
585 | |||
586 | |||
diff --git a/dis/original/Neighborhood/DISstressmarkRNG.h b/dis/original/Neighborhood/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Neighborhood/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/original/Neighborhood/neighborhood.c b/dis/original/Neighborhood/neighborhood.c new file mode 100644 index 0000000..e3d4f69 --- /dev/null +++ b/dis/original/Neighborhood/neighborhood.c | |||
@@ -0,0 +1,100 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Neighborhood 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 "utili.h" | ||
22 | |||
23 | /* | ||
24 | * main() | ||
25 | */ | ||
26 | int main() | ||
27 | { | ||
28 | long int seed; | ||
29 | int dimension; | ||
30 | int numberLines; | ||
31 | int minThickness; | ||
32 | int maxThickness; | ||
33 | int distanceShort; | ||
34 | int distanceLong; | ||
35 | int bitDepth; | ||
36 | int maxPixel; | ||
37 | Pixel *image; | ||
38 | Neighborhood values; | ||
39 | |||
40 | time_t beginTime; | ||
41 | time_t endTime; | ||
42 | |||
43 | fscanf(stdin, "%ld %d %d %d %d %d %d %d", | ||
44 | &seed, &bitDepth, &dimension, &numberLines, | ||
45 | &minThickness, &maxThickness, | ||
46 | &distanceShort, &distanceLong); | ||
47 | |||
48 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
49 | assert((dimension > 0) && (dimension <= MAX_DIMENSION)); | ||
50 | assert((numberLines > 0) && (numberLines <= MAX_NUMBER_LINES)); | ||
51 | assert((minThickness > 0) && (minThickness < dimension)); | ||
52 | assert((maxThickness >= minThickness) && (maxThickness < dimension)); | ||
53 | assert((distanceShort > 0) && (distanceShort < dimension)); | ||
54 | assert((distanceLong > 0) && (distanceLong < dimension)); | ||
55 | assert((bitDepth >= MIN_BIT_DEPTH) && (bitDepth <= MAX_BIT_DEPTH)); | ||
56 | |||
57 | randInit(seed); | ||
58 | maxPixel = (1 << bitDepth) - 1; | ||
59 | image = createImage(dimension, maxPixel, numberLines, | ||
60 | minThickness, maxThickness); | ||
61 | assert (image != NULL); | ||
62 | |||
63 | beginTime = time(NULL); | ||
64 | |||
65 | neighborhoodCalculation(image, dimension, | ||
66 | distanceShort, distanceLong, &values, maxPixel); | ||
67 | |||
68 | endTime = time(NULL); | ||
69 | |||
70 | printf(" end time is %d\n", endTime); | ||
71 | |||
72 | fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", | ||
73 | values.distShort.deg0.entropy, | ||
74 | values.distShort.deg0.energy, | ||
75 | values.distShort.deg45.entropy, | ||
76 | values.distShort.deg45.energy, | ||
77 | values.distShort.deg90.entropy, | ||
78 | values.distShort.deg90.energy, | ||
79 | values.distShort.deg135.entropy, | ||
80 | values.distShort.deg135.energy); | ||
81 | |||
82 | fprintf(stdout,"%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", | ||
83 | values.distLong.deg0.entropy, | ||
84 | values.distLong.deg0.energy,values.distShort.deg45.entropy, | ||
85 | values.distLong.deg45.energy, | ||
86 | values.distLong.deg90.entropy, | ||
87 | values.distLong.deg90.energy, | ||
88 | values.distLong.deg135.entropy, | ||
89 | values.distLong.deg135.energy); | ||
90 | |||
91 | fprintf(stderr, "time for neghborhood stressmark = %f\n", | ||
92 | difftime(endTime, beginTime)); | ||
93 | |||
94 | free((Pixel *)image); | ||
95 | return (SUCCESS); | ||
96 | } | ||
97 | |||
98 | |||
99 | |||
100 | |||
diff --git a/dis/original/Neighborhood/utili.h b/dis/original/Neighborhood/utili.h new file mode 100644 index 0000000..2a8e2a0 --- /dev/null +++ b/dis/original/Neighborhood/utili.h | |||
@@ -0,0 +1,363 @@ | |||
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 | |||
16 | #include <math.h> | ||
17 | |||
18 | #define TRUE 1 | ||
19 | #define FALSE !TRUE | ||
20 | #define SUCCESS TRUE | ||
21 | #define ERROR FLASE | ||
22 | |||
23 | #define MIN_PIXEL 0 | ||
24 | #define MAX_DIMENSION 32768 | ||
25 | #define MIN_SEED -2147483647 | ||
26 | #define MAX_SEED -1 | ||
27 | #define MAX_NUMBER_LINES 65536 | ||
28 | #define MIN_BIT_DEPTH 7 | ||
29 | #define MAX_BIT_DEPTH 15 | ||
30 | |||
31 | typedef struct { | ||
32 | int column; | ||
33 | int row; | ||
34 | }Coord; | ||
35 | |||
36 | /* | ||
37 | * Neighborhood structure consists of the GLCM descriptors entropy and | ||
38 | * energy for each of 2 distance and 4 angels | ||
39 | */ | ||
40 | typedef struct { | ||
41 | float entropy; | ||
42 | float energy; | ||
43 | }Descriptors; | ||
44 | |||
45 | typedef struct { | ||
46 | Descriptors deg0; | ||
47 | Descriptors deg45; | ||
48 | Descriptors deg90; | ||
49 | Descriptors deg135; | ||
50 | }Angeles; | ||
51 | |||
52 | typedef struct { | ||
53 | Angeles distShort; | ||
54 | Angeles distLong; | ||
55 | }Neighborhood; | ||
56 | |||
57 | typedef short int Pixel; /* short int;*/ | ||
58 | |||
59 | |||
60 | void drawLineSegment(Pixel *image, | ||
61 | Coord startPoint, | ||
62 | Coord endPoint, | ||
63 | int startValue, | ||
64 | int endValue, | ||
65 | int thickness, | ||
66 | int dimension) | ||
67 | { | ||
68 | int changeColumn, changeRow; | ||
69 | int delta; | ||
70 | int column, row; | ||
71 | float value, valueDelta; | ||
72 | int t; | ||
73 | |||
74 | changeColumn = endPoint.column - startPoint.column; | ||
75 | changeRow = endPoint.row - startPoint.row; | ||
76 | |||
77 | assert((changeRow != 0) || (changeColumn != 0)); | ||
78 | |||
79 | column = startPoint.column; | ||
80 | row = startPoint.row; | ||
81 | value = startValue; | ||
82 | |||
83 | if (ABS(changeColumn) > ABS(changeRow)){ | ||
84 | valueDelta = ((float) endValue - startValue)/ | ||
85 | ((float) ABS(changeColumn)); | ||
86 | delta = 2*ABS(row) - ABS(column); | ||
87 | for (column = startPoint.column; | ||
88 | column == endPoint.column+sign(changeColumn); | ||
89 | column += sign(changeColumn)){ | ||
90 | for (t = MAX(0, row-thickness/2); | ||
91 | t < MIN(dimension, row+thickness - thickness/2); | ||
92 | t++) | ||
93 | image[t*dimension + column] = (int)value; | ||
94 | value += valueDelta; | ||
95 | if (delta >= 0){ | ||
96 | row += sign(changeRow); | ||
97 | delta -= 2*ABS(changeColumn); | ||
98 | } | ||
99 | column += sign(changeColumn); | ||
100 | delta += 2*ABS(changeRow); | ||
101 | } | ||
102 | } | ||
103 | else { | ||
104 | valueDelta = ((float) endValue - startValue)/ | ||
105 | ((float) ABS(changeRow)); | ||
106 | delta = 2* ABS(column) - ABS(row); | ||
107 | for (row = startPoint.row; | ||
108 | row == endPoint.row + sign(changeRow); | ||
109 | row += sign(changeRow)){ | ||
110 | for (t = MAX(0, column-thickness/2); | ||
111 | t < MIN(dimension, row + thickness - thickness/2); | ||
112 | t++) | ||
113 | image[row*dimension + t] = (int)value; | ||
114 | if (delta >= 0){ | ||
115 | column += sign(changeColumn); | ||
116 | delta -= 2*ABS(changeRow); | ||
117 | } | ||
118 | row += sign(changeRow); | ||
119 | delta += 2*ABS(changeColumn); | ||
120 | } | ||
121 | } | ||
122 | return; | ||
123 | } | ||
124 | |||
125 | |||
126 | |||
127 | Pixel *createImage (int dimension, | ||
128 | Pixel maxPixel, | ||
129 | int numberLines, | ||
130 | int minThickness, | ||
131 | int maxThickness) | ||
132 | { | ||
133 | Pixel *image; | ||
134 | int i; | ||
135 | |||
136 | Coord startPoint; | ||
137 | Coord endPoint; | ||
138 | int thickness; | ||
139 | int startValue; | ||
140 | int endValue; | ||
141 | |||
142 | image = (Pixel *)malloc(sizeof(Pixel) * dimension * dimension); | ||
143 | assert (image != NULL); | ||
144 | for (i=0; i<dimension*dimension; i++){ | ||
145 | image[i] = 0; | ||
146 | } | ||
147 | |||
148 | for (i=0; i<numberLines; i++){ | ||
149 | float temp; | ||
150 | float prev; | ||
151 | |||
152 | temp = randomUInt(0, dimension*dimension - 1); | ||
153 | startPoint.row = (int) temp/dimension; | ||
154 | startPoint.column = (int) temp % dimension; | ||
155 | prev = temp; | ||
156 | |||
157 | while((temp = randomUInt(0, dimension*dimension -1)) == prev); | ||
158 | |||
159 | endPoint.row = (int) temp/dimension; | ||
160 | endPoint.column = (int) temp% dimension; | ||
161 | |||
162 | thickness = randomUInt(minThickness, maxThickness); | ||
163 | startValue = randomUInt(MIN_PIXEL, maxPixel); | ||
164 | endValue = randomUInt(MIN_PIXEL, maxPixel); | ||
165 | |||
166 | drawLineSegment(image, startPoint, endPoint, | ||
167 | startValue, endValue, thickness, dimension); | ||
168 | } | ||
169 | return(image); | ||
170 | } | ||
171 | |||
172 | |||
173 | void calcEntropyEnergy( | ||
174 | int *sumHist, | ||
175 | int *diffHist, | ||
176 | Pixel *image, | ||
177 | int numBins, | ||
178 | int dx, | ||
179 | int dy, | ||
180 | float *entropy, | ||
181 | float *energy, | ||
182 | int dimension, | ||
183 | Pixel maxPixel) | ||
184 | { | ||
185 | int index; | ||
186 | int totalNumPixels; | ||
187 | int rowIndex; | ||
188 | int rowLow, rowHigh; | ||
189 | int columnIndex; | ||
190 | int columnLow, columnHigh; | ||
191 | int columnForPixelAtDistance; | ||
192 | int rowForPixelAtDistance; | ||
193 | int value0RowOffset; | ||
194 | int value1RowOffset; | ||
195 | |||
196 | *entropy = 0.0; | ||
197 | *energy = 0.0; | ||
198 | |||
199 | for (index = 0; index < numBins; index++){ | ||
200 | sumHist[index] = 0; | ||
201 | diffHist[index] = 0; | ||
202 | } | ||
203 | |||
204 | if (dy < 0){ | ||
205 | rowLow = -dy; | ||
206 | rowHigh = dimension; | ||
207 | } | ||
208 | else { | ||
209 | rowLow = 0; | ||
210 | rowHigh = dimension - dy; | ||
211 | } | ||
212 | if (dx < 0){ | ||
213 | columnLow = -dx; | ||
214 | columnHigh = dimension; | ||
215 | } | ||
216 | else | ||
217 | { | ||
218 | columnLow = 0; | ||
219 | columnHigh = dimension - dx; | ||
220 | } | ||
221 | |||
222 | totalNumPixels = 0; | ||
223 | value0RowOffset = rowLow * dimension; | ||
224 | value1RowOffset = (rowLow + dy) * dimension; | ||
225 | |||
226 | for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){ | ||
227 | for (columnIndex= columnLow; columnIndex<columnHigh; | ||
228 | columnIndex++){ | ||
229 | int value0; | ||
230 | int value1; | ||
231 | int binIndex; | ||
232 | |||
233 | rowForPixelAtDistance = rowIndex + dy; | ||
234 | columnForPixelAtDistance = columnIndex + dx; | ||
235 | |||
236 | value0 = *(image + value0RowOffset + columnIndex); | ||
237 | value1 = *(image + value1RowOffset + | ||
238 | columnForPixelAtDistance); | ||
239 | |||
240 | binIndex = value0 + value1 - 2*MIN_PIXEL; | ||
241 | assert((binIndex >= 0) && (binIndex < numBins)); | ||
242 | sumHist[binIndex] += 1; | ||
243 | binIndex = value0 - value1 + maxPixel - MIN_PIXEL; | ||
244 | |||
245 | assert((binIndex >= 0) && (binIndex < numBins)); | ||
246 | |||
247 | diffHist[binIndex] += 1; | ||
248 | totalNumPixels += 1; | ||
249 | |||
250 | } | ||
251 | |||
252 | value0RowOffset += dimension; | ||
253 | value1RowOffset += dimension; | ||
254 | |||
255 | } | ||
256 | |||
257 | |||
258 | if (totalNumPixels > 0){ | ||
259 | int index; | ||
260 | double energySum; | ||
261 | double energyDifference; | ||
262 | double entropyValue; | ||
263 | double sumNormalized; | ||
264 | double diffNormalized; | ||
265 | double scale; | ||
266 | |||
267 | energySum = (double) 0; | ||
268 | energyDifference = (double) 0; | ||
269 | entropyValue = (double) 0; | ||
270 | scale = 1.e0/totalNumPixels; | ||
271 | for (index = 0; index<numBins; index++){ | ||
272 | if (sumHist[index] > 0){ | ||
273 | sumNormalized = (double) sumHist[index]*scale; | ||
274 | entropyValue = entropyValue - sumNormalized * | ||
275 | log((double)sumNormalized); | ||
276 | energySum = energySum + sumNormalized * sumNormalized ; | ||
277 | } | ||
278 | if (diffHist[index] > 0){ | ||
279 | diffNormalized = (double)diffHist[index]*scale; | ||
280 | entropyValue = entropyValue - diffNormalized * log(diffNormalized); | ||
281 | energyDifference = energyDifference + | ||
282 | diffNormalized * diffNormalized; | ||
283 | } | ||
284 | } | ||
285 | *energy = energySum * energyDifference; | ||
286 | *entropy = entropyValue; | ||
287 | } | ||
288 | return; | ||
289 | } | ||
290 | |||
291 | |||
292 | void neighborhoodCalculation | ||
293 | (Pixel *image, | ||
294 | int dimension, | ||
295 | int distanceShort, | ||
296 | int distanceLong, | ||
297 | Neighborhood *neighborhood, | ||
298 | Pixel maxPixel) | ||
299 | { | ||
300 | int *sumHist, *diffHist; | ||
301 | int numBins; | ||
302 | |||
303 | numBins = (2 * (maxPixel - MIN_PIXEL + 1) -1); | ||
304 | sumHist = (int *) malloc(numBins * sizeof(int)); | ||
305 | assert (sumHist != NULL); | ||
306 | diffHist = (int *)malloc(numBins * sizeof(int)); | ||
307 | assert(diffHist != NULL); | ||
308 | |||
309 | printf(" before short calc deg0\n"); | ||
310 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
311 | distanceShort, 0, | ||
312 | &(neighborhood->distShort.deg0.entropy), | ||
313 | &(neighborhood->distShort.deg0.energy), dimension, | ||
314 | maxPixel); | ||
315 | |||
316 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
317 | distanceShort, distanceShort, | ||
318 | &(neighborhood->distShort.deg45.entropy), | ||
319 | &(neighborhood->distShort.deg45.energy), dimension, | ||
320 | maxPixel); | ||
321 | |||
322 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
323 | 0, distanceShort, | ||
324 | &(neighborhood->distShort.deg90.entropy), | ||
325 | &(neighborhood->distShort.deg90.energy), dimension, | ||
326 | maxPixel); | ||
327 | |||
328 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
329 | -distanceShort, distanceShort, | ||
330 | &(neighborhood->distShort.deg135.entropy), | ||
331 | &(neighborhood->distShort.deg135.energy), dimension, | ||
332 | maxPixel); | ||
333 | |||
334 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
335 | distanceLong, 0, | ||
336 | &(neighborhood->distLong.deg0.entropy), | ||
337 | &(neighborhood->distLong.deg0.energy), dimension, | ||
338 | maxPixel); | ||
339 | |||
340 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
341 | distanceLong, distanceLong, | ||
342 | &(neighborhood->distLong.deg45.entropy), | ||
343 | &(neighborhood->distLong.deg45.energy), dimension, | ||
344 | maxPixel); | ||
345 | |||
346 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
347 | 0, distanceLong, | ||
348 | &(neighborhood->distLong.deg90.entropy), | ||
349 | &(neighborhood->distLong.deg90.energy), dimension, | ||
350 | maxPixel); | ||
351 | |||
352 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | ||
353 | -distanceLong, distanceLong, | ||
354 | &(neighborhood->distLong.deg135.entropy), | ||
355 | &(neighborhood->distLong.deg135.energy), dimension, | ||
356 | maxPixel); | ||
357 | |||
358 | free(sumHist); | ||
359 | free(diffHist); | ||
360 | |||
361 | return; | ||
362 | } | ||
363 | |||
diff --git a/dis/original/Pointer/DISstressmarkRNG.h b/dis/original/Pointer/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Pointer/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
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 | } | ||
diff --git a/dis/original/Transitive/DISstressmarkRNG.h b/dis/original/Transitive/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Transitive/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
diff --git a/dis/original/Transitive/transitive.c b/dis/original/Transitive/transitive.c new file mode 100644 index 0000000..854d57c --- /dev/null +++ b/dis/original/Transitive/transitive.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * Sample code for the DIS Transitive 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 <time.h> | ||
18 | #include <assert.h> | ||
19 | #include <stdlib.h> | ||
20 | #include "DISstressmarkRNG.h" | ||
21 | |||
22 | #define MIN_VERTICES 8 | ||
23 | #define MAX_VERTICES 16384 | ||
24 | #define MIN_EDGES 0 | ||
25 | #define MAX_EDGES 268435456 | ||
26 | #define MIN_SEED -2147483647 | ||
27 | #define MAX_SEED -1 | ||
28 | #define NO_PATH 2147483647 | ||
29 | |||
30 | #define MIN_EDGS 0 | ||
31 | #define MAX_EDGE 255 | ||
32 | |||
33 | /* | ||
34 | * main() | ||
35 | */ | ||
36 | |||
37 | int main(){ | ||
38 | unsigned int *din, *dout; | ||
39 | unsigned int n; | ||
40 | unsigned int m; | ||
41 | unsigned int i, j, k; | ||
42 | int seed; | ||
43 | |||
44 | time_t startTime; | ||
45 | unsigned int sum; | ||
46 | |||
47 | fscanf(stdin,"%d %d %d", &n, &m, &seed); | ||
48 | |||
49 | assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES)); | ||
50 | assert((m >= MIN_EDGES) && (m <= MAX_EDGES)); | ||
51 | assert (m <= n*n); | ||
52 | assert ((seed >= MIN_SEED) && (seed <= MAX_SEED)); | ||
53 | |||
54 | if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | ||
55 | return (-1); | ||
56 | if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | ||
57 | return (-1); | ||
58 | |||
59 | for (i=0; i<n*n; i++){ | ||
60 | *(din + i) = NO_PATH; | ||
61 | *(dout + i) = NO_PATH; | ||
62 | } | ||
63 | |||
64 | randInit(seed); | ||
65 | for (k=0; k<m; k++){ | ||
66 | i = randInt(0, n); | ||
67 | j = randInt(0, n); | ||
68 | *(din + j*n + i) = randInt(MIN_EDGES, MAX_EDGES); | ||
69 | } | ||
70 | |||
71 | startTime = time(NULL); | ||
72 | |||
73 | for (k=0; k<n; k++){ | ||
74 | unsigned int old; | ||
75 | unsigned int new1; | ||
76 | unsigned int *dtemp; | ||
77 | |||
78 | for (i=0; i<n; i++){ | ||
79 | for (j=0; j<n; j++){ | ||
80 | old = *(din + j*n + i); | ||
81 | new1 = *(din + j*n + k) + *(din + k*n + i); | ||
82 | *(dout + j*n + i) = (new1 < old ? new1: old); | ||
83 | assert (*(dout + j*n + i) <= NO_PATH); | ||
84 | assert (*(dout + j*n + i) <= *(din + j*n + i)); | ||
85 | } | ||
86 | } | ||
87 | dtemp = dout; | ||
88 | dout = din; | ||
89 | din = dtemp; | ||
90 | } | ||
91 | |||
92 | startTime = time(NULL) - startTime; | ||
93 | |||
94 | for (j=0; j<n; j++){ | ||
95 | sum = 0; | ||
96 | for (i=0; i<n; i++){ | ||
97 | if (*(din + j*n + i) != NO_PATH) | ||
98 | sum += *(din + j*n + i); | ||
99 | } | ||
100 | fprintf(stdout, "%u\n", sum); | ||
101 | } | ||
102 | for (i=0; i<n; i++){ | ||
103 | sum = 0; | ||
104 | for (j=0; j<n; j++){ | ||
105 | if (*(din + j*n + i) != NO_PATH) | ||
106 | sum += *(din+j*n+i); | ||
107 | } | ||
108 | |||
109 | fprintf(stdout, "%u\n", sum); | ||
110 | } | ||
111 | |||
112 | fprintf(stdout, " total time = %u seconds. \n", (unsigned int)startTime); | ||
113 | free(din); | ||
114 | free(dout); | ||
115 | return(0); | ||
116 | } | ||
117 | |||
118 | |||
119 | |||
120 | |||
121 | |||
122 | |||
123 | |||
diff --git a/dis/original/Update/DISstressmarkRNG.h b/dis/original/Update/DISstressmarkRNG.h new file mode 100644 index 0000000..4aa2620 --- /dev/null +++ b/dis/original/Update/DISstressmarkRNG.h | |||
@@ -0,0 +1,190 @@ | |||
1 | #include <math.h> | ||
2 | |||
3 | #define IA 16807 | ||
4 | #define IM 2147483647 | ||
5 | #define AM (1.0/IM) | ||
6 | #define IQ 127773 | ||
7 | #define IR 2836 | ||
8 | #define NTAB 32 | ||
9 | #define NDIV (1+(IM-1)/NTAB) | ||
10 | #define EPS 1.2e-7 | ||
11 | #define RNMX (1.0-EPS) | ||
12 | |||
13 | static long iy=0; | ||
14 | static long iv[NTAB]; | ||
15 | static long iseed; | ||
16 | |||
17 | int ABS(int x){ | ||
18 | if (x>= 0) return x; | ||
19 | else | ||
20 | return (-x); | ||
21 | } | ||
22 | |||
23 | int sign(int x){ | ||
24 | if (x >= 0) return 1; | ||
25 | else | ||
26 | return (-1); | ||
27 | } | ||
28 | |||
29 | int MAX(int x, int y){ | ||
30 | if (x>= y) return x; | ||
31 | else | ||
32 | return y; | ||
33 | } | ||
34 | |||
35 | int MIN(int x, int y){ | ||
36 | if (x<= y) return x; | ||
37 | else | ||
38 | return y; | ||
39 | } | ||
40 | |||
41 | void randInit(long idum) | ||
42 | { | ||
43 | long j; | ||
44 | long k; | ||
45 | |||
46 | assert (idum <= 0); | ||
47 | assert (iy == 0); | ||
48 | |||
49 | iseed = idum; | ||
50 | if (-(iseed)<1){ | ||
51 | iseed = 1; | ||
52 | } | ||
53 | else { | ||
54 | iseed = -(iseed); | ||
55 | } | ||
56 | for (j=NTAB+7; j>=0; j--){ | ||
57 | k = (iseed)/IQ; | ||
58 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
59 | if (iseed < 0){ | ||
60 | iseed += IM; | ||
61 | } | ||
62 | if (j < NTAB){ | ||
63 | iv[j] = iseed; | ||
64 | } | ||
65 | } | ||
66 | iy = iv[0]; | ||
67 | } | ||
68 | |||
69 | float randNum() | ||
70 | { | ||
71 | long j; | ||
72 | long k; | ||
73 | float temp; | ||
74 | |||
75 | assert (iy != 0); | ||
76 | |||
77 | k = (iseed)/IQ; | ||
78 | iseed = IA*(iseed-k*IQ)-IR*k; | ||
79 | |||
80 | if (iseed < 0){ | ||
81 | iseed += IM; | ||
82 | } | ||
83 | j = iy/NDIV; | ||
84 | iy = iv[j]; | ||
85 | iv[j] = iseed; | ||
86 | |||
87 | temp = AM * iy; | ||
88 | |||
89 | if (temp > RNMX){ | ||
90 | return RNMX; | ||
91 | } | ||
92 | else { | ||
93 | return temp; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | |||
98 | float randomFloat(float lowest_float, float highest_float) | ||
99 | { | ||
100 | float value; | ||
101 | float range; | ||
102 | |||
103 | assert (lowest_float < highest_float); | ||
104 | |||
105 | range = highest_float - lowest_float; | ||
106 | value = randNum()*(highest_float - lowest_float) + lowest_float; | ||
107 | assert(value >= lowest_float); | ||
108 | assert(value <= highest_float); | ||
109 | |||
110 | return value; | ||
111 | |||
112 | } | ||
113 | |||
114 | float randomNonZeroFloat(float lowest_float, float highest_float, float epsilon) | ||
115 | { | ||
116 | |||
117 | double range; | ||
118 | float value; | ||
119 | |||
120 | |||
121 | assert (lowest_float < 0); | ||
122 | assert (highest_float > 0); | ||
123 | assert (epsilon > 0); | ||
124 | assert ((epsilon < -lowest_float) && (epsilon < highest_float)); | ||
125 | |||
126 | range = highest_float - lowest_float; | ||
127 | value = (randNum() * range)+lowest_float; | ||
128 | |||
129 | if (ABS(value) < epsilon) | ||
130 | { | ||
131 | if (value > 0) value = value + epsilon; | ||
132 | else if (value < 0) value = value - epsilon; | ||
133 | |||
134 | } | ||
135 | |||
136 | assert (value >= lowest_float); | ||
137 | assert (value <= highest_float); | ||
138 | |||
139 | return value; | ||
140 | } | ||
141 | |||
142 | unsigned int randomUInt(int lowest_uint, int highest_uint) | ||
143 | { | ||
144 | float range; | ||
145 | unsigned int value; | ||
146 | float temp; | ||
147 | |||
148 | range =(float)(highest_uint - lowest_uint + 1); | ||
149 | temp = randNum(); | ||
150 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
151 | |||
152 | assert (value >= lowest_uint); | ||
153 | assert (value <= highest_uint); | ||
154 | |||
155 | return value; | ||
156 | } | ||
157 | |||
158 | unsigned int randomNonZeroUInt(int lowest_uint, int highest_uint) | ||
159 | { | ||
160 | float range; | ||
161 | unsigned int value; | ||
162 | float temp; | ||
163 | |||
164 | range =(float)(highest_uint - lowest_uint + 1); | ||
165 | value = 0; | ||
166 | while(value == 0){ | ||
167 | temp = randNum(); | ||
168 | |||
169 | value =(unsigned int)( floor(temp * range) + lowest_uint); | ||
170 | } | ||
171 | |||
172 | assert (value >= lowest_uint); | ||
173 | assert (value <= highest_uint); | ||
174 | |||
175 | return value; | ||
176 | } | ||
177 | |||
178 | int randInt(int lowest_uint, int highest_uint) | ||
179 | { | ||
180 | float range; | ||
181 | int value; | ||
182 | |||
183 | range = highest_uint - lowest_uint + 1; | ||
184 | value = (int)(floor(randNum() * range) + lowest_uint); | ||
185 | |||
186 | assert (value >= lowest_uint); | ||
187 | assert (value <= highest_uint); | ||
188 | |||
189 | return value; | ||
190 | } | ||
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 | |||
42 | int 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 | } | ||