diff options
author | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-17 14:43:46 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-17 14:43:46 -0400 |
commit | a3886552003d031acb9039e920b7c9ddce946ad6 (patch) | |
tree | c3b6a400a9ba31e744e6218365d63bdfbbc45a83 /dis | |
parent | 917499f6257ac51c05e8302af877d56a22f28cb5 (diff) |
DIS fixes used for (rejected) RTSS'20 submission
- All: Output times to stderr and nothing to stdout
- Field, Update, Pointer: change definition of a job to match other
stressmark execution times more closely
- Matrix: move all allocations into main()
- Update: Use volatile to prevent computations from being optimized out
- Transitive: Use volatile to prevent computations from being optimized out
- Neighborhood: Use working version of drawLineSegment from original DIS
sample code
Diffstat (limited to 'dis')
-rw-r--r-- | dis/Field/field.c | 27 | ||||
-rwxr-xr-x | dis/Matrix/ver2/matrix.c | 79 | ||||
-rw-r--r-- | dis/Neighborhood/initializeImage.c | 371 | ||||
-rw-r--r-- | dis/Neighborhood/neighborhood.c | 14 | ||||
-rw-r--r-- | dis/Neighborhood/utili.h | 161 | ||||
-rw-r--r-- | dis/Pointer/pointer.c | 32 | ||||
-rw-r--r-- | dis/Transitive/transitive.c | 92 | ||||
-rw-r--r-- | dis/Update/update.c | 14 |
8 files changed, 560 insertions, 230 deletions
diff --git a/dis/Field/field.c b/dis/Field/field.c index 8565e8c..f83a403 100644 --- a/dis/Field/field.c +++ b/dis/Field/field.c | |||
@@ -47,7 +47,7 @@ int main(int argc, char** argv){ | |||
47 | int mod_offset; | 47 | int mod_offset; |
48 | unsigned int n; | 48 | unsigned int n; |
49 | 49 | ||
50 | time_t startTime; | 50 | time_t startTime, endTime; |
51 | 51 | ||
52 | struct tokenS{ | 52 | struct tokenS{ |
53 | unsigned char delimiter[MAX_TOKEN_LENGTH]; | 53 | unsigned char delimiter[MAX_TOKEN_LENGTH]; |
@@ -92,9 +92,9 @@ int main(int argc, char** argv){ | |||
92 | } | 92 | } |
93 | 93 | ||
94 | startTime = time(NULL); | 94 | startTime = time(NULL); |
95 | 95 | START_LOOP | |
96 | |||
96 | for (l =0; l<n; l++){ | 97 | for (l =0; l<n; l++){ |
97 | START_LOOP | ||
98 | unsigned int index; | 98 | unsigned int index; |
99 | 99 | ||
100 | token[l].subfields = 0; | 100 | token[l].subfields = 0; |
@@ -133,20 +133,25 @@ int main(int argc, char** argv){ | |||
133 | index++; | 133 | index++; |
134 | } | 134 | } |
135 | token[l].subfields++; | 135 | token[l].subfields++; |
136 | STOP_LOOP | ||
137 | } | 136 | } |
138 | 137 | ||
139 | startTime = time(NULL) - startTime; | 138 | STOP_LOOP |
139 | endTime = time(NULL); | ||
140 | 140 | ||
141 | volatile int sumAll = 0; | ||
141 | for (l = 0; l< n; l++){ | 142 | for (l = 0; l< n; l++){ |
142 | unsigned int ll; | 143 | unsigned int ll; |
143 | fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); | 144 | //fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); |
144 | for ( ll =0; ll<token[l].subfields; ll++) | 145 | sumAll += token[l].subfields + l; |
145 | fprintf(stdout, "subfields %d:\tcount = %d\tmin= %x\tsum= %x\n", | 146 | for ( ll =0; ll<token[l].subfields; ll++) { |
146 | ll, token[l].stat[ll].count, | 147 | sumAll += ll + token[l].stat[ll].count + token[l].stat[ll].min + token[l].stat[ll].sum; |
147 | token[l].stat[ll].min, token[l].stat[ll].sum); | 148 | /*fprintf(stdout, "subfields %d:\tcount = %d\tmin= %x\tsum= %x\n", |
149 | ll, token[l].stat[ll].count, | ||
150 | token[l].stat[ll].min, token[l].stat[ll].sum);*/ | ||
151 | } | ||
148 | } | 152 | } |
149 | fprintf(stdout, "total time = %d seconds.\n", (int)startTime); | 153 | fprintf(stderr, "time for field stressmark = %f seconds.\n", |
154 | difftime(endTime, startTime)); | ||
150 | free(field); | 155 | free(field); |
151 | WRITE_TO_FILE | 156 | WRITE_TO_FILE |
152 | return(0); | 157 | return(0); |
diff --git a/dis/Matrix/ver2/matrix.c b/dis/Matrix/ver2/matrix.c index 957d7c5..ffa7cb7 100755 --- a/dis/Matrix/ver2/matrix.c +++ b/dis/Matrix/ver2/matrix.c | |||
@@ -48,7 +48,7 @@ | |||
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 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 |
@@ -61,8 +61,6 @@ | |||
61 | */ | 61 | */ |
62 | 62 | ||
63 | static int dim; | 63 | static int dim; |
64 | int argc; | ||
65 | char** argv; | ||
66 | 64 | ||
67 | /* | 65 | /* |
68 | * matrix * vector | 66 | * matrix * vector |
@@ -312,7 +310,14 @@ void biConjugateGradient(double *value, | |||
312 | int maxIterations, | 310 | int maxIterations, |
313 | double *actualError, | 311 | double *actualError, |
314 | int *actualIteration, | 312 | int *actualIteration, |
315 | int dim) | 313 | int dim, |
314 | // Start internal matrixes | ||
315 | double *vectorP, | ||
316 | double *vectorR, | ||
317 | double *nextVectorR, | ||
318 | double *tmpVector1, | ||
319 | double *tmpVector2, | ||
320 | double *tmpVector3) | ||
316 | /* | 321 | /* |
317 | * in the code, we use a lot of temparary vectors and variables | 322 | * in the code, we use a lot of temparary vectors and variables |
318 | * this is just for simple and clear | 323 | * this is just for simple and clear |
@@ -321,31 +326,18 @@ void biConjugateGradient(double *value, | |||
321 | * | 326 | * |
322 | */ | 327 | */ |
323 | { | 328 | { |
324 | double *vectorR; | ||
325 | double *vectorP, *matrixAvectorP, *nextVectorR; | ||
326 | double error; | 329 | double error; |
327 | int iteration; | 330 | int iteration; |
328 | double alpha, beta; | 331 | double alpha, beta; |
329 | 332 | ||
330 | double *tmpVector1, *tmpVector2, *tmpVector3; | ||
331 | double tmpValue1, tmpValue2; | 333 | double tmpValue1, tmpValue2; |
332 | int i; | 334 | int i; |
333 | int l; | 335 | int l; |
334 | int ll; | 336 | int ll; |
335 | SET_UP | ||
336 | 337 | ||
337 | alpha = 0; | 338 | alpha = 0; |
338 | beta = 0; | 339 | beta = 0; |
339 | 340 | ||
340 | vectorP = (double *)malloc(dim*sizeof(double)); | ||
341 | vectorR = (double *)malloc(dim*sizeof(double)); | ||
342 | nextVectorR = (double *)malloc(dim*sizeof(double)); | ||
343 | vectorX = (double *)malloc(dim*sizeof(double)); | ||
344 | |||
345 | tmpVector1 = (double *)malloc(dim*sizeof(double)); | ||
346 | tmpVector2 = (double *)malloc(dim*sizeof(double)); | ||
347 | tmpVector3 = (double *)malloc(dim*sizeof(double)); | ||
348 | |||
349 | /* | 341 | /* |
350 | * vectorR = vectorB - matrixA*vectorX | 342 | * vectorR = vectorB - matrixA*vectorX |
351 | */ | 343 | */ |
@@ -369,7 +361,6 @@ void biConjugateGradient(double *value, | |||
369 | iteration = 0; | 361 | iteration = 0; |
370 | 362 | ||
371 | while ((iteration < maxIterations) && (error > errorTolerance)){ | 363 | while ((iteration < maxIterations) && (error > errorTolerance)){ |
372 | START_LOOP | ||
373 | 364 | ||
374 | /* | 365 | /* |
375 | * alpha = (transpose(vectorR) * vectorR) / | 366 | * alpha = (transpose(vectorR) * vectorR) / |
@@ -434,7 +425,6 @@ void biConjugateGradient(double *value, | |||
434 | error = vectorValue(tmpVector1)/vectorValue(vectorB); | 425 | error = vectorValue(tmpVector1)/vectorValue(vectorB); |
435 | 426 | ||
436 | iteration++; | 427 | iteration++; |
437 | STOP_LOOP | ||
438 | } | 428 | } |
439 | 429 | ||
440 | *actualError = error; | 430 | *actualError = error; |
@@ -446,7 +436,6 @@ void biConjugateGradient(double *value, | |||
446 | 436 | ||
447 | free(vectorR); | 437 | free(vectorR); |
448 | free(vectorP); | 438 | free(vectorP); |
449 | WRITE_TO_FILE | ||
450 | 439 | ||
451 | return; | 440 | return; |
452 | } | 441 | } |
@@ -515,10 +504,8 @@ void create_CRS(double *matrixA, | |||
515 | } | 504 | } |
516 | 505 | ||
517 | 506 | ||
518 | int main(int _argc, char** _argv) | 507 | int main(int argc, char** argv) |
519 | { | 508 | { |
520 | argc = _argc; | ||
521 | argv = _argv; | ||
522 | int seed; | 509 | int seed; |
523 | int numberNonzero; | 510 | int numberNonzero; |
524 | int maxIterations; | 511 | int maxIterations; |
@@ -536,18 +523,22 @@ int main(int _argc, char** _argv) | |||
536 | double *value; | 523 | double *value; |
537 | int *col_ind; | 524 | int *col_ind; |
538 | int *row_start; | 525 | int *row_start; |
539 | int sum; | 526 | double sum; |
540 | int k; | 527 | int k; |
528 | // Internal vects for biConj | ||
529 | double *vectorR, *vectorP, *nextVectorR; | ||
530 | double *tmpVector1, *tmpVector2, *tmpVector3; | ||
531 | SET_UP | ||
541 | 532 | ||
542 | fscanf(stdin, "%d %d %d %d %f", | 533 | assert(fscanf(stdin, "%d %d %d %d %f", |
543 | &seed, &dim, &numberNonzero,&maxIterations,&errorTolerance); | 534 | &seed, &dim, &numberNonzero,&maxIterations,&errorTolerance) == 5); |
544 | assert((seed > MIN_SEED) && (seed < MAX_SEED)); | 535 | assert((seed > MIN_SEED) && (seed < MAX_SEED)); |
545 | assert((dim > MIN_DIM) && (dim < MAX_DIM)); | 536 | assert((dim > MIN_DIM) && (dim < MAX_DIM)); |
546 | assert((numberNonzero > dim) && (numberNonzero < dim*dim)); | 537 | assert((numberNonzero > dim) && (numberNonzero < dim*dim)); |
547 | assert((maxIterations > 0) && (maxIterations < MAX_ITERATIONS)); | 538 | assert((maxIterations > 0) && (maxIterations < MAX_ITERATIONS)); |
548 | assert((errorTolerance > MIN_TOLERANCE) && (errorTolerance < MAX_TOLERANCE)); | 539 | assert((errorTolerance > MIN_TOLERANCE) && (errorTolerance < MAX_TOLERANCE)); |
549 | 540 | ||
550 | matrixA = (double *)malloc(dim*dim*sizeof(double )); | 541 | matrixA = (double *)malloc(dim*dim*sizeof(double)); |
551 | vectorB = (double *)malloc(dim*sizeof(double)); | 542 | vectorB = (double *)malloc(dim*sizeof(double)); |
552 | vectorX = (double *)malloc(dim*sizeof(double)); | 543 | vectorX = (double *)malloc(dim*sizeof(double)); |
553 | 544 | ||
@@ -555,40 +546,46 @@ int main(int _argc, char** _argv) | |||
555 | col_ind = (int *)malloc((numberNonzero+dim)*sizeof(int)); | 546 | col_ind = (int *)malloc((numberNonzero+dim)*sizeof(int)); |
556 | row_start = (int *)malloc((dim+1)*sizeof(int)); | 547 | row_start = (int *)malloc((dim+1)*sizeof(int)); |
557 | 548 | ||
549 | // Internal matricies for biConj | ||
550 | vectorP = (double *)malloc(dim*sizeof(double)); | ||
551 | vectorR = (double *)malloc(dim*sizeof(double)); | ||
552 | nextVectorR = (double *)malloc(dim*sizeof(double)); | ||
553 | tmpVector1 = (double *)malloc(dim*sizeof(double)); | ||
554 | tmpVector2 = (double *)malloc(dim*sizeof(double)); | ||
555 | tmpVector3 = (double *)malloc(dim*sizeof(double)); | ||
556 | |||
558 | randInit(seed); | 557 | randInit(seed); |
559 | 558 | ||
559 | START_LOOP | ||
560 | initMatrix(matrixA, dim, numberNonzero); | 560 | initMatrix(matrixA, dim, numberNonzero); |
561 | 561 | ||
562 | create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); | 562 | create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); |
563 | 563 | ||
564 | initVector(vectorB, dim); | 564 | initVector(vectorB, dim); |
565 | zeroVector(vectorX, dim); | 565 | zeroVector(vectorX, dim); |
566 | printf(" after init\n"); | ||
567 | 566 | ||
568 | beginTime = time(NULL); | 567 | beginTime = time(NULL); |
569 | 568 | ||
570 | actualError = 0; | 569 | actualError = 0; |
571 | actualIteration = 0; | 570 | actualIteration = 0; |
572 | 571 | ||
573 | biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, errorTolerance, | 572 | biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, errorTolerance, |
574 | maxIterations, | 573 | maxIterations, |
575 | &actualError, &actualIteration, dim); | 574 | &actualError, &actualIteration, dim, |
576 | 575 | vectorP, vectorR, nextVectorR, tmpVector1, tmpVector2, tmpVector3); | |
577 | |||
578 | |||
579 | endTime = time(NULL) - beginTime; | ||
580 | |||
581 | 576 | ||
577 | STOP_LOOP | ||
578 | endTime = time(NULL); | ||
582 | 579 | ||
583 | sum = 0; | 580 | sum = 0; |
584 | for (k=1; k<dim; k++){ | 581 | for (k=1; k<dim; k++){ |
585 | sum += sum + *(vectorX + k); | 582 | sum += sum + *(vectorX + k); |
586 | } | 583 | } |
587 | 584 | ||
588 | fprintf(stdout, "sum = %d, actualError = %e, actualIteration = %d\n", sum, actualError, actualIteration); | 585 | fprintf(stdout, "sum = %f, actualError = %e, actualIteration = %d\n", sum, actualError, actualIteration); |
589 | fprintf(stdout, "total time = %u sec. \n", (unsigned int)endTime); | 586 | fprintf(stderr, "time for matrix stressmark = %f seconds.\n", difftime(endTime, beginTime)); |
590 | 587 | ||
588 | WRITE_TO_FILE | ||
591 | return(0); | 589 | return(0); |
592 | } | 590 | } |
593 | 591 | ||
594 | |||
diff --git a/dis/Neighborhood/initializeImage.c b/dis/Neighborhood/initializeImage.c new file mode 100644 index 0000000..a030a1a --- /dev/null +++ b/dis/Neighborhood/initializeImage.c | |||
@@ -0,0 +1,371 @@ | |||
1 | /* Copyright 2000, Atlantic Aerospace Electronics Corp */ | ||
2 | /* | ||
3 | * Name: initializeImage | ||
4 | * Input: dimension dimension of image | ||
5 | * maxImageValue max legal image value | ||
6 | * numberLines number line segments for image | ||
7 | * minThickness min thickness for line segment | ||
8 | * maxThickness max thickness for line segment | ||
9 | * Output: image image initialized | ||
10 | * Comment: This routine allocates memory to store an image and fills | ||
11 | * in the image structure except for the image data. The | ||
12 | * pixels of the image are of type ShortInt. If there | ||
13 | * is an error allocating memory, than a NULL pointer is | ||
14 | * returned. Assumptions: the image dimensions given are | ||
15 | * positive. | ||
16 | * Calls: errorMessage() | ||
17 | * (system) malloc() | ||
18 | * free() | ||
19 | * Return: image structure pointer (partially filled in - no data - | ||
20 | * and allocated) | ||
21 | * NULL (error allocating memory for image/image structure) | ||
22 | * | ||
23 | * Revision History: | ||
24 | * Date Name Revision | ||
25 | * --------- ----------- ----------------------------- | ||
26 | * 25May2000 May Leung Created | ||
27 | * 05Jun2000 May Leung Add maxImageValue as input to initializeImage() | ||
28 | * XXMay2020 Joshua Bakita Commented out significant portions to allow this to | ||
29 | * be #include(d) elsewhere. | ||
30 | */ | ||
31 | typedef int Int; | ||
32 | typedef short int ShortInt; | ||
33 | typedef float Float; | ||
34 | void drawRowPoint (Int value, | ||
35 | Int pointThickness, | ||
36 | Int row, | ||
37 | Int column, | ||
38 | Image *image); | ||
39 | void drawColumnPoint (Int value, | ||
40 | Int pointThickness, | ||
41 | Int row, | ||
42 | Int column, | ||
43 | Image *image); | ||
44 | #define MIN_RANDOM_VALUE 0 | ||
45 | #if 0 | ||
46 | #ifndef NDEBUG | ||
47 | #include <stdio.h> | ||
48 | #endif /* NDEBUG */ | ||
49 | #include <assert.h> /* define assert() */ | ||
50 | #include <stdlib.h> /* define NULL, malloc(), free() */ | ||
51 | #include "stressmark.h" /* system include file */ | ||
52 | #include "neighborhood.h" /* define types, structures, etc */ | ||
53 | #include "errorMessage.h" /* define errorMessage() */ | ||
54 | #include "random.h" /* define randomUInt() */ | ||
55 | #include "initializeImage.h" /* define initializeImage() */ | ||
56 | |||
57 | Image *initializeImage (Int dimension, /* dimension of image */ | ||
58 | Int maxImageValue, /* max legal image value */ | ||
59 | Int numberLines, /* number line segments for image */ | ||
60 | Int minThickness, /* min thickness for line segment */ | ||
61 | Int maxThickness) /* max thickness for line segment */ | ||
62 | { /* beginning of initializeImage() */ | ||
63 | |||
64 | Image *image; /* pointer to image structure to allocate */ | ||
65 | ShortInt *data; /* pointer to the data for the image structure*/ | ||
66 | Int lineIndex; /* loop index variable for line segments */ | ||
67 | Int pixelIndex; /* loop index variable for pixels */ | ||
68 | Int limit; /* limit for loop using pixelIndex */ | ||
69 | |||
70 | Coord startPoint; /* starting point for a line segment */ | ||
71 | Coord endPoint; /* ending point for a line segment */ | ||
72 | Int lineThickness; /* thickness for a line segment */ | ||
73 | Int startValue; /* starting value for a line segment */ | ||
74 | Int endValue; /* ending value for a line segment */ | ||
75 | |||
76 | /* | ||
77 | * Assert the assumptions that the number of columns and number of rows | ||
78 | * are positive values. No test on the maximum possible value is done since | ||
79 | * numColumns and numRows are of type Int and the maximum value of an Int | ||
80 | * type is possible. | ||
81 | */ | ||
82 | assert(dimension > 0); | ||
83 | assert(numberLines > 0); | ||
84 | assert((minThickness > 0) && (minThickness < dimension)); | ||
85 | assert((maxThickness > 0) && (maxThickness < dimension)); | ||
86 | assert(minThickness <= maxThickness); | ||
87 | |||
88 | /* create image */ | ||
89 | image = createImage(dimension,dimension,maxImageValue); | ||
90 | if (image == NULL) { | ||
91 | return(NULL); | ||
92 | } /* end error check from createImage */ | ||
93 | |||
94 | /* zero out the image */ | ||
95 | limit = dimension * dimension; | ||
96 | data = image->data; | ||
97 | for (pixelIndex = 0; pixelIndex < limit; pixelIndex++) { | ||
98 | *data++ = 0; | ||
99 | } /* end for loop */ | ||
100 | |||
101 | /* | ||
102 | * Populate the image with line segments where the endpoints, values, and | ||
103 | * thickness of each line segment are randomly generated. | ||
104 | */ | ||
105 | for (lineIndex = 0; lineIndex < numberLines; lineIndex++) { | ||
106 | randomImageLocation(image, &startPoint); | ||
107 | randomImageLocation(image, &endPoint); | ||
108 | lineThickness = randomUInt(minThickness,maxThickness); | ||
109 | startValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue); | ||
110 | endValue = randomUInt(MIN_RANDOM_VALUE, maxImageValue); | ||
111 | |||
112 | /* add line segment to the image */ | ||
113 | drawLineSegment(&startPoint, &endPoint, startValue, endValue, lineThickness, | ||
114 | image); | ||
115 | |||
116 | } /* end for loop */ | ||
117 | |||
118 | return(image); | ||
119 | } /* end initializeImage() */ | ||
120 | #endif | ||
121 | |||
122 | /* | ||
123 | * drawLineSegment() This routine draws a line segment into the given image | ||
124 | * starting at the coordinate startPoint and ending at the | ||
125 | * coordinate endPoint. The values along this line segment | ||
126 | * vary linearly from the given starting value startValue to | ||
127 | * the end value endValue and have a lineThickness associated | ||
128 | * to it. | ||
129 | * | ||
130 | * This routine is modeled after the routine draw_line() from | ||
131 | * "Practical Computer Vision using C", by J.R. Parker, Wiley, 1994, pp 114-116. | ||
132 | * It has been enhanced to have values on the line segment vary and to have | ||
133 | * a thickness to the line segment. | ||
134 | */ | ||
135 | void drawLineSegment (Coord *startPoint, /* starting point for line segment */ | ||
136 | Coord *endPoint, /* ending point for line segment */ | ||
137 | Int startValue, /* starting value for line segment */ | ||
138 | Int endValue, /* ending value for line segment */ | ||
139 | Int lineThickness, /* thickness for line segment */ | ||
140 | Image *image) /* image to add line segment to */ | ||
141 | { /* beginning of drawLineSegment() */ | ||
142 | |||
143 | /* | ||
144 | * Modeled after draw_line() from "Practical Computer Vision using C", | ||
145 | * by J.R. Parker, Wiley, 1994, pp 114-116. Enhanced to have values | ||
146 | * on the line segment vary and to have a thickness to the line segment. | ||
147 | * The value along the line segment is kept in a float variable so that | ||
148 | * fractional increments along the line segment can accumulate to integer | ||
149 | * values. | ||
150 | */ | ||
151 | Int changeColumn, changeRow; /* change along line segment in col/row */ | ||
152 | Int absColumn, absRow; /* absolute value of change in col/row */ | ||
153 | Int signColumn, signRow; /* sign of change along line segment col/row */ | ||
154 | Int delta; /* increment alone line segment */ | ||
155 | Int column, row; /* column & row of coordinate along line seg */ | ||
156 | Float value, valueDelta; /* value & value change along line segment */ | ||
157 | |||
158 | // assert(validImage(image)); | ||
159 | assert(startPoint != NULL); | ||
160 | assert(endPoint != NULL); | ||
161 | |||
162 | #ifdef DEBUG0 | ||
163 | fprintf(stderr, | ||
164 | "drawLineSegment: start row %6ld col %6ld\tend row %6ld col %6ld\n", | ||
165 | startPoint->row,startPoint->column,endPoint->row,endPoint->column); | ||
166 | fprintf(stderr," startVal %6ld endVal %6ld thickness %6ld\n", | ||
167 | startValue, endValue, lineThickness); | ||
168 | #endif /* DEBUG0 */ | ||
169 | |||
170 | changeColumn = endPoint->column - startPoint->column; | ||
171 | if (changeColumn < 0) { | ||
172 | absColumn = - changeColumn; | ||
173 | signColumn = - 1; | ||
174 | } /* end changeColumn < 0 */ | ||
175 | else { /* changeColumn >= 0 */ | ||
176 | absColumn = changeColumn; | ||
177 | signColumn = 1; | ||
178 | } /* end changeColumn >= 0 */ | ||
179 | absColumn *= 2; | ||
180 | |||
181 | changeRow = endPoint->row - startPoint->row; | ||
182 | if (changeRow < 0) { | ||
183 | absRow = - changeRow; | ||
184 | signRow = - 1; | ||
185 | } /* end changeRow < 0 */ | ||
186 | else { /* changeRow >= 0 */ | ||
187 | absRow = changeRow; | ||
188 | signRow = 1; | ||
189 | } /* end changeRow >= 0 */ | ||
190 | absRow *= 2; | ||
191 | |||
192 | column = startPoint->column; | ||
193 | row = startPoint->row; | ||
194 | value = startValue; /* add changing value to algorithm */ | ||
195 | |||
196 | if (signColumn * changeColumn > signRow * changeRow) { /* column dominant */ | ||
197 | /* determine the change in value for each step (added to algorithm) */ | ||
198 | valueDelta = ((Float) endValue - startValue) / | ||
199 | ((Float) changeColumn * signColumn); | ||
200 | |||
201 | delta = absRow - (absColumn / 2); | ||
202 | while (TRUE) { /* inifinite loop */ | ||
203 | /* | ||
204 | * Line is column dominant, so line thickness will be along rows. Make | ||
205 | * sure the ending value doesn't go beyond endValue. (Added to algorithm) | ||
206 | */ | ||
207 | drawRowPoint((Int) value, lineThickness, row, column, image); | ||
208 | if (valueDelta >=0) { | ||
209 | value = MIN(endValue, value+valueDelta); | ||
210 | } /* values are incrementing */ | ||
211 | else { /* valueDelta < 0 */ | ||
212 | value = MAX(endValue, value+valueDelta); | ||
213 | } /* values are decreasing */ | ||
214 | |||
215 | if (column == endPoint->column) { | ||
216 | return; /* done with line segment exit routine */ | ||
217 | } /* end exit criteria */ | ||
218 | if (delta >= 0) { | ||
219 | row += signRow; | ||
220 | delta -= absColumn; | ||
221 | } /* end if delta >= 0 */ | ||
222 | column += signColumn; | ||
223 | delta += absRow; | ||
224 | } /* end while infinite loop */ | ||
225 | } /* end row dominant case */ | ||
226 | else { /* row dominant case */ | ||
227 | /* determine the change in value for each step (added to algorithm) */ | ||
228 | if (changeRow == 0) { | ||
229 | valueDelta = 0; | ||
230 | assert(changeColumn == 0); | ||
231 | } /* end if changeRow == 0 */ | ||
232 | else { | ||
233 | valueDelta = ((Float) endValue - startValue) / | ||
234 | ((Float) changeRow * signRow); | ||
235 | } /* end else */ | ||
236 | |||
237 | delta = absColumn - (absRow / 2); | ||
238 | while (TRUE) { /* inifinite loop */ | ||
239 | /* | ||
240 | * Line is row dominant, so line thickness will be along columns. Make | ||
241 | * sure the ending value doesn't go beyond endValue. (Added to algorithm) | ||
242 | */ | ||
243 | drawColumnPoint((Int) value, lineThickness, row, column, image); | ||
244 | if (valueDelta >=0) { | ||
245 | value = MIN(endValue, value+valueDelta); | ||
246 | } /* values are incrementing */ | ||
247 | else { /* valueDelta < 0 */ | ||
248 | value = MAX(endValue, value+valueDelta); | ||
249 | } /* values are decreasing */ | ||
250 | |||
251 | if (row == endPoint->row) { | ||
252 | return; /* done with line segment exit routine */ | ||
253 | } /* end exit criteria */ | ||
254 | if (delta >= 0) { | ||
255 | column += signColumn; | ||
256 | delta -= absRow; | ||
257 | } /* end if delta >= 0 */ | ||
258 | row += signRow; | ||
259 | delta += absColumn; | ||
260 | } /* end while infinite loop */ | ||
261 | } /* end column dominant case */ | ||
262 | |||
263 | return; | ||
264 | } /* end of drawLineSegment() */ | ||
265 | |||
266 | /* | ||
267 | * drawRowPoint() This routine draws a point with a row thickness onto the | ||
268 | * given image for the coordinate and value provided. | ||
269 | */ | ||
270 | void drawRowPoint (Int value, /* value for point */ | ||
271 | Int pointThickness, /* thickness for point */ | ||
272 | Int row, /* row coordinate of point */ | ||
273 | Int column, /* column coordinate of point */ | ||
274 | Image *image) /* image to draw point onto */ | ||
275 | { /* beginning of drawRowPoint() */ | ||
276 | Int halfThickness; /* half the point thickness */ | ||
277 | Int lowerRow, upperRow, rowIndex; /* loop boundaries and index for row */ | ||
278 | ShortInt *data; /* image data pointer */ | ||
279 | |||
280 | // assert(validImage(image)); | ||
281 | assert(value >= MIN_RANDOM_VALUE); | ||
282 | assert(value <= image->maxImageValue); | ||
283 | assert(pointThickness > 0); | ||
284 | |||
285 | #ifdef DEBUG0 | ||
286 | fprintf(stderr, | ||
287 | "drawRowPoint: value %5ld, thickness %6ld, row %6ld, column %6ld\n", | ||
288 | value,pointThickness,row,column); | ||
289 | #endif /* DEBUG0 */ | ||
290 | |||
291 | halfThickness = (Int) pointThickness / 2; /* use integer division */ | ||
292 | lowerRow = MAX(0, row - halfThickness); | ||
293 | upperRow = MIN(image->numRows, row + pointThickness - halfThickness); | ||
294 | |||
295 | data = image->data + (lowerRow * image->numColumns) + column; | ||
296 | for (rowIndex = lowerRow; rowIndex < upperRow; rowIndex++) { | ||
297 | *data = (ShortInt) value; | ||
298 | data += image->numColumns; /* increment pointer to next row */ | ||
299 | } /* end for loop */ | ||
300 | |||
301 | return; | ||
302 | } /* end of drawRowPoint() */ | ||
303 | |||
304 | /* | ||
305 | * drawColumnPoint() This routine draws a point with a column thickness onto the | ||
306 | * given image for the coordinate and value provided. | ||
307 | */ | ||
308 | void drawColumnPoint (Int value, /* value for point */ | ||
309 | Int pointThickness, /* thickness for point */ | ||
310 | Int row, /* row coordinate of point */ | ||
311 | Int column, /* column coordinate of point */ | ||
312 | Image *image) /* image to draw point onto */ | ||
313 | { /* beginning of drawColumnPoint() */ | ||
314 | Int halfThickness; /* half the point thickness */ | ||
315 | Int leftColumn, rightColumn, columnIndex; /* col loop boundaries&index*/ | ||
316 | ShortInt *data; /* image data pointer */ | ||
317 | |||
318 | // assert(validImage(image)); | ||
319 | assert(value >= MIN_RANDOM_VALUE); | ||
320 | assert(value <= image->maxImageValue); | ||
321 | assert(pointThickness > 0); | ||
322 | |||
323 | #ifdef DEBUG0 | ||
324 | fprintf(stderr, | ||
325 | "drawColumnPoint: value %5ld, thickness %6ld, row %6ld, column %6ld\n", | ||
326 | value,pointThickness,row,column); | ||
327 | #endif /* DEBUG0 */ | ||
328 | |||
329 | halfThickness = (Int) pointThickness / 2; /* use integer division */ | ||
330 | leftColumn = MAX(0, column - halfThickness); | ||
331 | rightColumn = MIN(image->numColumns, column + pointThickness - halfThickness); | ||
332 | |||
333 | data = image->data + (row * image->numColumns) + leftColumn; | ||
334 | for (columnIndex = leftColumn; columnIndex < rightColumn; columnIndex++) { | ||
335 | *data = (ShortInt) value; | ||
336 | data++; /* increment pointer to next column */ | ||
337 | } /* end for loop */ | ||
338 | |||
339 | return; | ||
340 | } /* end of drawColumnPoint() */ | ||
341 | |||
342 | /* | ||
343 | * randomImageLocation() This routine generates a random coordinate yielding a | ||
344 | * coordinate in the given image using randomUInt(). | ||
345 | */ | ||
346 | #if 0 | ||
347 | #include "random.h" | ||
348 | |||
349 | void randomImageLocation (Image *image, /* image in question */ | ||
350 | Coord *location) /* random location generated */ | ||
351 | { /* beginning of randomImageLocation() */ | ||
352 | Int index; /* random location in image */ | ||
353 | Int maxIndex; /* maximum index in image */ | ||
354 | |||
355 | assert(validImage(image)); | ||
356 | assert(location != NULL); | ||
357 | |||
358 | maxIndex = image->numColumns * image->numRows - 1; | ||
359 | index = randomUInt(0, maxIndex); | ||
360 | |||
361 | /* use integer division to clip to closest integer value */ | ||
362 | location->row = (Int) index / image->numColumns; | ||
363 | location->column = index - (location->row * image->numColumns); | ||
364 | |||
365 | assert((location->row >= 0) && (location->row < image->numRows)); | ||
366 | assert((location->column >= 0) && (location->column < image->numColumns)); | ||
367 | assert(index = location->column + (location->row * image->numColumns)); | ||
368 | |||
369 | return; | ||
370 | } /* end of randomImageLocation() */ | ||
371 | #endif | ||
diff --git a/dis/Neighborhood/neighborhood.c b/dis/Neighborhood/neighborhood.c index 1736d38..23f3a8e 100644 --- a/dis/Neighborhood/neighborhood.c +++ b/dis/Neighborhood/neighborhood.c | |||
@@ -11,6 +11,10 @@ | |||
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 | * | ||
15 | * Change log: | ||
16 | * ------- ---------------- --------------------------------------------------- | ||
17 | * 06/2020 Joshua Bakita Include image creation time in timing | ||
14 | */ | 18 | */ |
15 | 19 | ||
16 | #include <stdio.h> | 20 | #include <stdio.h> |
@@ -58,12 +62,14 @@ int main(int argc, char** argv) | |||
58 | 62 | ||
59 | randInit(seed); | 63 | randInit(seed); |
60 | maxPixel = (1 << bitDepth) - 1; | 64 | maxPixel = (1 << bitDepth) - 1; |
61 | image = createImage(dimension, maxPixel, numberLines, | 65 | image = malloc(sizeof(Pixel) * dimension * dimension); |
62 | minThickness, maxThickness); | 66 | assert(image != NULL); |
63 | assert (image != NULL); | ||
64 | 67 | ||
65 | beginTime = time(NULL); | 68 | beginTime = time(NULL); |
66 | START_LOOP | 69 | START_LOOP |
70 | createImage(image, dimension, maxPixel, numberLines, | ||
71 | minThickness, maxThickness); | ||
72 | |||
67 | neighborhoodCalculation(image, dimension, | 73 | neighborhoodCalculation(image, dimension, |
68 | distanceShort, distanceLong, &values, maxPixel); | 74 | distanceShort, distanceLong, &values, maxPixel); |
69 | STOP_LOOP | 75 | STOP_LOOP |
@@ -91,7 +97,7 @@ int main(int argc, char** argv) | |||
91 | values.distLong.deg135.entropy, | 97 | values.distLong.deg135.entropy, |
92 | values.distLong.deg135.energy); | 98 | values.distLong.deg135.energy); |
93 | 99 | ||
94 | fprintf(stderr, "time for neghborhood stressmark = %f\n", | 100 | fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n", |
95 | difftime(endTime, beginTime)); | 101 | difftime(endTime, beginTime)); |
96 | 102 | ||
97 | free((Pixel *)image); | 103 | free((Pixel *)image); |
diff --git a/dis/Neighborhood/utili.h b/dis/Neighborhood/utili.h index 2a8e2a0..5b54d9b 100644 --- a/dis/Neighborhood/utili.h +++ b/dis/Neighborhood/utili.h | |||
@@ -56,81 +56,23 @@ typedef struct { | |||
56 | 56 | ||
57 | typedef short int Pixel; /* short int;*/ | 57 | typedef short int Pixel; /* short int;*/ |
58 | 58 | ||
59 | typedef struct { | ||
60 | int numColumns; /* number of columns in image */ | ||
61 | int numRows; /* number of rows in image */ | ||
62 | Pixel maxImageValue; /* max legal image value */ | ||
63 | Pixel *data; /* data pointer */ | ||
64 | } Image; | ||
59 | 65 | ||
60 | void drawLineSegment(Pixel *image, | 66 | // For correct implementation of drawLineSegment |
61 | Coord startPoint, | 67 | #include "initializeImage.c" |
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 | 68 | ||
127 | Pixel *createImage (int dimension, | 69 | Pixel *createImage (Pixel *image, |
70 | int dimension, | ||
128 | Pixel maxPixel, | 71 | Pixel maxPixel, |
129 | int numberLines, | 72 | int numberLines, |
130 | int minThickness, | 73 | int minThickness, |
131 | int maxThickness) | 74 | int maxThickness) |
132 | { | 75 | { |
133 | Pixel *image; | ||
134 | int i; | 76 | int i; |
135 | 77 | ||
136 | Coord startPoint; | 78 | Coord startPoint; |
@@ -138,9 +80,12 @@ Pixel *createImage (int dimension, | |||
138 | int thickness; | 80 | int thickness; |
139 | int startValue; | 81 | int startValue; |
140 | int endValue; | 82 | int endValue; |
83 | Image img; | ||
84 | img.numColumns = dimension; | ||
85 | img.numRows = dimension; | ||
86 | img.maxImageValue = maxPixel; | ||
87 | img.data = image; | ||
141 | 88 | ||
142 | image = (Pixel *)malloc(sizeof(Pixel) * dimension * dimension); | ||
143 | assert (image != NULL); | ||
144 | for (i=0; i<dimension*dimension; i++){ | 89 | for (i=0; i<dimension*dimension; i++){ |
145 | image[i] = 0; | 90 | image[i] = 0; |
146 | } | 91 | } |
@@ -154,6 +99,7 @@ Pixel *createImage (int dimension, | |||
154 | startPoint.column = (int) temp % dimension; | 99 | startPoint.column = (int) temp % dimension; |
155 | prev = temp; | 100 | prev = temp; |
156 | 101 | ||
102 | // Make sure that the end is different than the start | ||
157 | while((temp = randomUInt(0, dimension*dimension -1)) == prev); | 103 | while((temp = randomUInt(0, dimension*dimension -1)) == prev); |
158 | 104 | ||
159 | endPoint.row = (int) temp/dimension; | 105 | endPoint.row = (int) temp/dimension; |
@@ -163,11 +109,11 @@ Pixel *createImage (int dimension, | |||
163 | startValue = randomUInt(MIN_PIXEL, maxPixel); | 109 | startValue = randomUInt(MIN_PIXEL, maxPixel); |
164 | endValue = randomUInt(MIN_PIXEL, maxPixel); | 110 | endValue = randomUInt(MIN_PIXEL, maxPixel); |
165 | 111 | ||
166 | drawLineSegment(image, startPoint, endPoint, | 112 | drawLineSegment(&startPoint, &endPoint, |
167 | startValue, endValue, thickness, dimension); | 113 | startValue, endValue, thickness, &img); |
168 | } | 114 | } |
169 | return(image); | 115 | return(image); |
170 | } | 116 | } |
171 | 117 | ||
172 | 118 | ||
173 | void calcEntropyEnergy( | 119 | void calcEntropyEnergy( |
@@ -214,10 +160,10 @@ void calcEntropyEnergy( | |||
214 | columnHigh = dimension; | 160 | columnHigh = dimension; |
215 | } | 161 | } |
216 | else | 162 | else |
217 | { | 163 | { |
218 | columnLow = 0; | 164 | columnLow = 0; |
219 | columnHigh = dimension - dx; | 165 | columnHigh = dimension - dx; |
220 | } | 166 | } |
221 | 167 | ||
222 | totalNumPixels = 0; | 168 | totalNumPixels = 0; |
223 | value0RowOffset = rowLow * dimension; | 169 | value0RowOffset = rowLow * dimension; |
@@ -225,27 +171,27 @@ void calcEntropyEnergy( | |||
225 | 171 | ||
226 | for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){ | 172 | for (rowIndex = rowLow; rowIndex<rowHigh; rowIndex++){ |
227 | for (columnIndex= columnLow; columnIndex<columnHigh; | 173 | for (columnIndex= columnLow; columnIndex<columnHigh; |
228 | columnIndex++){ | 174 | columnIndex++){ |
229 | int value0; | 175 | int value0; |
230 | int value1; | 176 | int value1; |
231 | int binIndex; | 177 | int binIndex; |
232 | 178 | ||
233 | rowForPixelAtDistance = rowIndex + dy; | 179 | rowForPixelAtDistance = rowIndex + dy; |
234 | columnForPixelAtDistance = columnIndex + dx; | 180 | columnForPixelAtDistance = columnIndex + dx; |
235 | 181 | ||
236 | value0 = *(image + value0RowOffset + columnIndex); | 182 | value0 = *(image + value0RowOffset + columnIndex); |
237 | value1 = *(image + value1RowOffset + | 183 | value1 = *(image + value1RowOffset + |
238 | columnForPixelAtDistance); | 184 | columnForPixelAtDistance); |
239 | 185 | ||
240 | binIndex = value0 + value1 - 2*MIN_PIXEL; | 186 | binIndex = value0 + value1 - 2*MIN_PIXEL; |
241 | assert((binIndex >= 0) && (binIndex < numBins)); | 187 | assert((binIndex >= 0) && (binIndex < numBins)); |
242 | sumHist[binIndex] += 1; | 188 | sumHist[binIndex] += 1; |
243 | binIndex = value0 - value1 + maxPixel - MIN_PIXEL; | 189 | binIndex = value0 - value1 + maxPixel - MIN_PIXEL; |
244 | 190 | ||
245 | assert((binIndex >= 0) && (binIndex < numBins)); | 191 | assert((binIndex >= 0) && (binIndex < numBins)); |
246 | 192 | ||
247 | diffHist[binIndex] += 1; | 193 | diffHist[binIndex] += 1; |
248 | totalNumPixels += 1; | 194 | totalNumPixels += 1; |
249 | 195 | ||
250 | } | 196 | } |
251 | 197 | ||
@@ -269,26 +215,26 @@ void calcEntropyEnergy( | |||
269 | entropyValue = (double) 0; | 215 | entropyValue = (double) 0; |
270 | scale = 1.e0/totalNumPixels; | 216 | scale = 1.e0/totalNumPixels; |
271 | for (index = 0; index<numBins; index++){ | 217 | for (index = 0; index<numBins; index++){ |
272 | if (sumHist[index] > 0){ | 218 | if (sumHist[index] > 0){ |
273 | sumNormalized = (double) sumHist[index]*scale; | 219 | sumNormalized = (double) sumHist[index]*scale; |
274 | entropyValue = entropyValue - sumNormalized * | 220 | entropyValue = entropyValue - sumNormalized * |
275 | log((double)sumNormalized); | 221 | log((double)sumNormalized); |
276 | energySum = energySum + sumNormalized * sumNormalized ; | 222 | energySum = energySum + sumNormalized * sumNormalized ; |
277 | } | 223 | } |
278 | if (diffHist[index] > 0){ | 224 | if (diffHist[index] > 0){ |
279 | diffNormalized = (double)diffHist[index]*scale; | 225 | diffNormalized = (double)diffHist[index]*scale; |
280 | entropyValue = entropyValue - diffNormalized * log(diffNormalized); | 226 | entropyValue = entropyValue - diffNormalized * log(diffNormalized); |
281 | energyDifference = energyDifference + | 227 | energyDifference = energyDifference + |
282 | diffNormalized * diffNormalized; | 228 | diffNormalized * diffNormalized; |
283 | } | 229 | } |
284 | } | 230 | } |
285 | *energy = energySum * energyDifference; | 231 | *energy = energySum * energyDifference; |
286 | *entropy = entropyValue; | 232 | *entropy = entropyValue; |
287 | } | 233 | } |
288 | return; | 234 | return; |
289 | } | 235 | } |
236 | |||
290 | 237 | ||
291 | |||
292 | void neighborhoodCalculation | 238 | void neighborhoodCalculation |
293 | (Pixel *image, | 239 | (Pixel *image, |
294 | int dimension, | 240 | int dimension, |
@@ -306,7 +252,6 @@ void neighborhoodCalculation | |||
306 | diffHist = (int *)malloc(numBins * sizeof(int)); | 252 | diffHist = (int *)malloc(numBins * sizeof(int)); |
307 | assert(diffHist != NULL); | 253 | assert(diffHist != NULL); |
308 | 254 | ||
309 | printf(" before short calc deg0\n"); | ||
310 | calcEntropyEnergy(sumHist, diffHist, image, numBins, | 255 | calcEntropyEnergy(sumHist, diffHist, image, numBins, |
311 | distanceShort, 0, | 256 | distanceShort, 0, |
312 | &(neighborhood->distShort.deg0.entropy), | 257 | &(neighborhood->distShort.deg0.entropy), |
diff --git a/dis/Pointer/pointer.c b/dis/Pointer/pointer.c index 5671697..3fc7248 100644 --- a/dis/Pointer/pointer.c +++ b/dis/Pointer/pointer.c | |||
@@ -38,19 +38,19 @@ | |||
38 | int main(int argc, char** argv){ | 38 | int main(int argc, char** argv){ |
39 | 39 | ||
40 | unsigned int *field; | 40 | unsigned int *field; |
41 | unsigned int f; | 41 | unsigned long f; |
42 | unsigned short int w; | 42 | unsigned short int w; |
43 | unsigned int maxhops; | 43 | unsigned long maxhops; |
44 | int seed; | 44 | long seed; |
45 | unsigned int n; | 45 | unsigned int n; |
46 | 46 | ||
47 | clock_t startTime; | 47 | clock_t startTime, endTime; |
48 | 48 | ||
49 | struct threadS{ | 49 | struct threadS{ |
50 | unsigned int initial; | 50 | unsigned long initial; |
51 | unsigned int minStop; | 51 | unsigned long minStop; |
52 | unsigned int maxStop; | 52 | unsigned long maxStop; |
53 | unsigned int hops; | 53 | unsigned long hops; |
54 | }*thread; | 54 | }*thread; |
55 | 55 | ||
56 | unsigned int l; | 56 | unsigned int l; |
@@ -72,7 +72,7 @@ int main(int argc, char** argv){ | |||
72 | return (-1); | 72 | return (-1); |
73 | 73 | ||
74 | for (l=0; l<n; l++){ | 74 | for (l=0; l<n; l++){ |
75 | assert(fscanf(stdin, "%lu %lu %lu", | 75 | assert(fscanf(stdin, "%lu %lu %lu", |
76 | &(thread[l].initial), &(thread[l].minStop), &(thread[l].maxStop)) == 3); | 76 | &(thread[l].initial), &(thread[l].minStop), &(thread[l].maxStop)) == 3); |
77 | assert ((thread[l].initial >= 0) && (thread[l].initial < f)); | 77 | assert ((thread[l].initial >= 0) && (thread[l].initial < f)); |
78 | assert ((thread[l].minStop >= 0) && (thread[l].minStop < f)); | 78 | assert ((thread[l].minStop >= 0) && (thread[l].minStop < f)); |
@@ -89,9 +89,9 @@ int main(int argc, char** argv){ | |||
89 | startTime = time(NULL); | 89 | startTime = time(NULL); |
90 | clock(); | 90 | clock(); |
91 | 91 | ||
92 | START_LOOP | ||
92 | for (l=0; l<n; l++) | 93 | for (l=0; l<n; l++) |
93 | { | 94 | { |
94 | START_LOOP | ||
95 | unsigned int index; | 95 | unsigned int index; |
96 | unsigned int minStop, maxStop; | 96 | unsigned int minStop, maxStop; |
97 | unsigned int hops; | 97 | unsigned int hops; |
@@ -142,16 +142,18 @@ for (l=0; l<n; l++) | |||
142 | hops++; | 142 | hops++; |
143 | }/* end loop ll */ | 143 | }/* end loop ll */ |
144 | thread[l].hops = hops; | 144 | thread[l].hops = hops; |
145 | STOP_LOOP | ||
146 | } /* end while */ | 145 | } /* end while */ |
146 | STOP_LOOP | ||
147 | 147 | ||
148 | startTime = time(NULL) - startTime; | 148 | endTime = time(NULL); |
149 | 149 | ||
150 | for (l=0; l<n; l++){ | 150 | volatile int _stop_optimizer = thread[l].hops + l; |
151 | /*for (l=0; l<n; l++){ | ||
151 | fprintf(stdout, "%lu hops on thread %d\n", thread[l].hops, l); | 152 | fprintf(stdout, "%lu hops on thread %d\n", thread[l].hops, l); |
152 | } | 153 | }*/ |
153 | 154 | ||
154 | fprintf(stderr, "total time = %u seconds.\n", (unsigned int)startTime); | 155 | fprintf(stderr, "time for pointer stressmark = %f seconds.\n", |
156 | difftime(endTime, startTime)); | ||
155 | free (field); | 157 | free (field); |
156 | free (thread); | 158 | free (thread); |
157 | WRITE_TO_FILE | 159 | WRITE_TO_FILE |
diff --git a/dis/Transitive/transitive.c b/dis/Transitive/transitive.c index 5fa52e8..303216f 100644 --- a/dis/Transitive/transitive.c +++ b/dis/Transitive/transitive.c | |||
@@ -45,20 +45,21 @@ int main(int argc, char** argv){ | |||
45 | unsigned int i, j, k; | 45 | unsigned int i, j, k; |
46 | int seed; | 46 | int seed; |
47 | 47 | ||
48 | time_t startTime; | 48 | time_t startTime, stopTime; |
49 | unsigned int sum; | 49 | unsigned int sum; |
50 | 50 | volatile int realRes = 0; | |
51 | fscanf(stdin,"%d %d %d", &n, &m, &seed); | 51 | |
52 | assert(fscanf(stdin,"%d %d %d", &n, &m, &seed) == 3); | ||
52 | 53 | ||
53 | assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES)); | 54 | assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES)); |
54 | assert((m >= MIN_EDGES) && (m <= MAX_EDGES)); | 55 | assert((m >= MIN_EDGES) && (m <= MAX_EDGES)); |
55 | assert (m <= n*n); | 56 | assert(m <= n*n); |
56 | assert ((seed >= MIN_SEED) && (seed <= MAX_SEED)); | 57 | assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); |
57 | 58 | ||
58 | if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | 59 | if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) |
59 | return (-1); | 60 | return (-1); |
60 | if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) | 61 | if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) |
61 | return (-1); | 62 | return (-1); |
62 | 63 | ||
63 | for (i=0; i<n*n; i++){ | 64 | for (i=0; i<n*n; i++){ |
64 | *(din + i) = NO_PATH; | 65 | *(din + i) = NO_PATH; |
@@ -75,53 +76,54 @@ int main(int argc, char** argv){ | |||
75 | SET_UP | 76 | SET_UP |
76 | startTime = time(NULL); | 77 | startTime = time(NULL); |
77 | 78 | ||
79 | START_LOOP | ||
78 | for (k=0; k<n; k++){ | 80 | for (k=0; k<n; k++){ |
79 | unsigned int old; | 81 | unsigned int old; |
80 | unsigned int new1; | 82 | unsigned int new1; |
81 | unsigned int *dtemp; | 83 | unsigned int *dtemp; |
82 | START_LOOP | 84 | |
83 | |||
84 | for (i=0; i<n; i++){ | 85 | for (i=0; i<n; i++){ |
85 | for (j=0; j<n; j++){ | 86 | for (j=0; j<n; j++){ |
86 | old = *(din + j*n + i); | 87 | old = *(din + j*n + i); |
87 | new1 = *(din + j*n + k) + *(din + k*n + i); | 88 | new1 = *(din + j*n + k) + *(din + k*n + i); |
88 | *(dout + j*n + i) = (new1 < old ? new1: old); | 89 | *(dout + j*n + i) = (new1 < old ? new1: old); |
89 | assert (*(dout + j*n + i) <= NO_PATH); | 90 | assert(*(dout + j*n + i) <= NO_PATH); |
90 | assert (*(dout + j*n + i) <= *(din + j*n + i)); | 91 | assert(*(dout + j*n + i) <= *(din + j*n + i)); |
91 | } | 92 | } |
92 | } | 93 | } |
93 | dtemp = dout; | 94 | dtemp = dout; |
94 | dout = din; | 95 | dout = din; |
95 | din = dtemp; | 96 | din = dtemp; |
96 | STOP_LOOP | 97 | } |
97 | } | ||
98 | 98 | ||
99 | startTime = time(NULL) - startTime; | 99 | STOP_LOOP |
100 | 100 | stopTime = time(NULL); | |
101 | for (j=0; j<n; j++){ | 101 | |
102 | sum = 0; | 102 | for (j=0; j<n; j++){ |
103 | for (i=0; i<n; i++){ | 103 | sum = 0; |
104 | if (*(din + j*n + i) != NO_PATH) | ||
105 | sum += *(din + j*n + i); | ||
106 | } | ||
107 | fprintf(stdout, "%u\n", sum); | ||
108 | } | ||
109 | for (i=0; i<n; i++){ | 104 | for (i=0; i<n; i++){ |
110 | sum = 0; | 105 | if (*(din + j*n + i) != NO_PATH) |
111 | for (j=0; j<n; j++){ | 106 | sum += *(din + j*n + i); |
112 | if (*(din + j*n + i) != NO_PATH) | ||
113 | sum += *(din+j*n+i); | ||
114 | } | ||
115 | |||
116 | fprintf(stdout, "%u\n", sum); | ||
117 | } | 107 | } |
118 | 108 | realRes+=sum; | |
119 | fprintf(stdout, " total time = %u seconds. \n", (unsigned int)startTime); | 109 | //fprintf(stdout, "%u ", sum); |
120 | free(din); | 110 | } |
121 | free(dout); | 111 | for (i=0; i<n; i++){ |
122 | WRITE_TO_FILE | 112 | sum = 0; |
123 | return(0); | 113 | for (j=0; j<n; j++){ |
114 | if (*(din + j*n + i) != NO_PATH) | ||
115 | sum += *(din+j*n+i); | ||
116 | } | ||
117 | realRes+=sum; | ||
118 | //fprintf(stdout, "%u ", sum); | ||
124 | } | 119 | } |
120 | fprintf(stderr, "time for transitive stressmark = %f seconds.\n", | ||
121 | difftime(stopTime, startTime)); | ||
122 | free(din); | ||
123 | free(dout); | ||
124 | WRITE_TO_FILE | ||
125 | return(0); | ||
126 | } | ||
125 | 127 | ||
126 | 128 | ||
127 | 129 | ||
diff --git a/dis/Update/update.c b/dis/Update/update.c index 1fd8197..f5e770a 100644 --- a/dis/Update/update.c +++ b/dis/Update/update.c | |||
@@ -48,7 +48,7 @@ int main(int argc, char** argv){ | |||
48 | unsigned short int w; | 48 | unsigned short int w; |
49 | unsigned int maxhops; | 49 | unsigned int maxhops; |
50 | int seed; | 50 | int seed; |
51 | time_t startTime; | 51 | time_t startTime, endTime; |
52 | unsigned int initial; | 52 | unsigned int initial; |
53 | unsigned int minStop; | 53 | unsigned int minStop; |
54 | unsigned int maxStop; | 54 | unsigned int maxStop; |
@@ -83,6 +83,7 @@ int main(int argc, char** argv){ | |||
83 | hops = 0; | 83 | hops = 0; |
84 | index = initial; | 84 | index = initial; |
85 | 85 | ||
86 | START_LOOP | ||
86 | while ((hops < maxhops) && | 87 | while ((hops < maxhops) && |
87 | (!((index >= minStop) && | 88 | (!((index >= minStop) && |
88 | (index < maxStop)))){ | 89 | (index < maxStop)))){ |
@@ -92,7 +93,6 @@ int main(int argc, char** argv){ | |||
92 | unsigned int max, min; | 93 | unsigned int max, min; |
93 | unsigned int partition; | 94 | unsigned int partition; |
94 | unsigned int high; | 95 | unsigned int high; |
95 | if (hops % 100 == 0) {START_LOOP} // These loops are too quick to sample individually | ||
96 | max = MAX_FIELD_SIZE; | 96 | max = MAX_FIELD_SIZE; |
97 | min = 0; | 97 | min = 0; |
98 | high = 0; | 98 | high = 0; |
@@ -125,13 +125,15 @@ int main(int argc, char** argv){ | |||
125 | field[index] = sum % (f-w); | 125 | field[index] = sum % (f-w); |
126 | index = (partition+hops)%(f-w); | 126 | index = (partition+hops)%(f-w); |
127 | hops++; | 127 | hops++; |
128 | if (hops % 100 == 0) {STOP_LOOP} // These loops are too quick to sample individually | ||
129 | }/* end for loop */ | 128 | }/* end for loop */ |
129 | STOP_LOOP | ||
130 | 130 | ||
131 | startTime = time(NULL) - startTime; | 131 | endTime = time(NULL); |
132 | 132 | ||
133 | fprintf(stdout, "%u hops\n", hops); | 133 | volatile int _stop_optimizer = hops; |
134 | fprintf(stderr, "total time = %u seconds.\n", (unsigned int)startTime); | 134 | //fprintf(stdout, "%u hops\n", hops); |
135 | fprintf(stderr, "time for update stressmark = %f seconds.\n", | ||
136 | difftime(endTime, startTime)); | ||
135 | free(field); | 137 | free(field); |
136 | WRITE_TO_FILE | 138 | WRITE_TO_FILE |
137 | return(1); | 139 | return(1); |