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