From 1120161286ee5c855b630bccc9e0b37bb8a3ee65 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Sat, 17 Oct 2020 19:07:11 -0400 Subject: Fix DIS coding style by running them all through clang-format Also fixes a missing header in DISstressmarkRNG.h and the "all" make target. No functional changes. --- dis/Field/DISstressmarkRNG.h | 1 + dis/Field/field.c | 162 ++++++------- dis/Makefile | 2 +- dis/Matrix/ver2/DISstressmarkRNG.h | 1 + dis/Matrix/ver2/matrix.c | 468 +++++++++++++++++------------------- dis/Neighborhood/DISstressmarkRNG.h | 1 + dis/Neighborhood/neighborhood.c | 77 +++--- dis/Neighborhood/utili.h | 435 +++++++++++++++------------------ dis/Pointer/DISstressmarkRNG.h | 1 + dis/Pointer/pointer.c | 225 +++++++++-------- dis/Transitive/DISstressmarkRNG.h | 1 + dis/Transitive/transitive.c | 103 ++++---- dis/Update/DISstressmarkRNG.h | 1 + dis/Update/update.c | 98 ++++---- 14 files changed, 747 insertions(+), 829 deletions(-) (limited to 'dis') 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 @@ +#include #include #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 @@ /* * Sample code for the DIS Field Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. * the comments are not repeated here. */ -#include -#include -#include -#include #include "DISstressmarkRNG.h" #include "extra.h" - +#include +#include +#include +#include #define MIN_FIELD_SIZE 16 -#define MAX_FIELD_SIZE (16777216*4) // This has been quadrupled from original +#define MAX_FIELD_SIZE (16777216 * 4) // This has been quadrupled from original #define MIN_SEED -2147483647 #define MAX_SEED -1 #define MIN_MOD_OFFSET 0 @@ -39,7 +38,7 @@ * main() */ -int main(int argc, char** argv){ +int main(int argc, char **argv) { SET_UP unsigned char *field; unsigned int f; @@ -48,17 +47,17 @@ int main(int argc, char** argv){ unsigned int n; time_t startTime, endTime; - - struct tokenS{ - unsigned char delimiter[MAX_TOKEN_LENGTH]; - unsigned char length; - struct statisticS{ + + struct tokenS { + unsigned char delimiter[MAX_TOKEN_LENGTH]; + unsigned char length; + struct statisticS { unsigned int count; unsigned char min; unsigned char sum; - }stat[MAX_SUBFIELDS]; + } stat[MAX_SUBFIELDS]; unsigned char subfields; - }token[MAX_TOKENS]; + } token[MAX_TOKENS]; unsigned int l; @@ -68,91 +67,92 @@ int main(int argc, char** argv){ assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); assert((mod_offset >= MIN_MOD_OFFSET) && (mod_offset <= MAX_MOD_OFFSET)); assert((n >= MIN_TOKENS) && (n <= MAX_TOKENS)); - for (l=0; l= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE)); - token[l].delimiter[index] = (unsigned char )x; - index++; - assert(fscanf(stdin,"%x", &x) == 1); - } - assert((index >= MIN_TOKEN_LENGTH) && (index <= MAX_TOKEN_LENGTH)); - token[l].length = index; + for (l = 0; l < n; l++) { + int x; + int index; + index = 0; + assert(fscanf(stdin, "%x", &x) == 1); + while (x != 0) { + assert((x >= MIN_TOKEN_VALUE) && (x <= MAX_TOKEN_VALUE)); + token[l].delimiter[index] = (unsigned char)x; + index++; + assert(fscanf(stdin, "%x", &x) == 1); } + assert((index >= MIN_TOKEN_LENGTH) && (index <= MAX_TOKEN_LENGTH)); + token[l].length = index; + } - if ((field = (unsigned char*)malloc(f*sizeof(unsigned char))) == NULL) + if ((field = (unsigned char *)malloc(f * sizeof(unsigned char))) == NULL) return (-1); randInit(seed); - for (l =0; l field[index]) - token[l].stat[token[l].subfields].min = field[index]; - } - index++; + if (offset == token[l].length) { + for (offset = 0; offset < token[l].length; offset++) { + field[index + offset] = (field[index + offset] + + field[(index + offset + mod_offset) % f]) % + (MAX_TOKEN_VALUE + 1); + } + index += token[l].length - 1; + token[l].subfields++; + token[l].stat[token[l].subfields].count = 0; + token[l].stat[token[l].subfields].sum = 0; + token[l].stat[token[l].subfields].min = MAX_TOKEN_VALUE; + } + + else { + token[l].stat[token[l].subfields].count++; + token[l].stat[token[l].subfields].sum += field[index]; + if (token[l].stat[token[l].subfields].min > field[index]) + token[l].stat[token[l].subfields].min = field[index]; + } + index++; } token[l].subfields++; - } + } - STOP_LOOP - endTime = time(NULL); - - volatile int sumAll = 0; - for (l = 0; l< n; l++){ - unsigned int ll; - //fprintf(stdout, "%d subfields for token %d \n", token[l].subfields, l); - sumAll += token[l].subfields + l; - for ( ll =0; ll #include #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 @@ /* Please note: - * This code is the optimized version of the first version of Matrix - * Stressmark. It uses less temporary vectors and vsariables, thus reduce - * memory allocation/deallocation overhead. the simulation is faster + * This code is the optimized version of the first version of Matrix + * Stressmark. It uses less temporary vectors and vsariables, thus reduce + * memory allocation/deallocation overhead. the simulation is faster */ /* * Sample code for the DIS Matrix Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. @@ -22,37 +22,37 @@ * The Sparse Matrix Storage is implemented by Compact Row Storage Scheme * In the code, the data is first generated by randomNonzeroFloat() * the data is first stored in a full-space matrix with size of dim*dim - * then the data is transfered to the Compact Row Matrix, + * then the data is transfered to the Compact Row Matrix, * the data value is kept in *value, * the columns corresponding to the value are stored in *col_ind, * the start element of each row is stored in *row_start. */ - -/* - * Please note: + +/* + * Please note: * the total number of data is numberNonzero +dim * among which, NumberNonzero because this is symmetric matrix * dim because the diagonal elements */ -#include +#include "DISstressmarkRNG.h" +#include "extra.h" +#include #include +#include #include #include -#include -#include "DISstressmarkRNG.h" -#include "extra.h" #define MIN_SEED -2147483647 #define MAX_SEED -1 -#define MIN_DIM 1 -#define MAX_DIM 32768 +#define MIN_DIM 1 +#define MAX_DIM 32768 #define MAX_ITERATIONS 65536 -#define MIN_TOLERANCE 1e-7//0.000007 +#define MIN_TOLERANCE 1e-7 // 0.000007 #define MAX_TOLERANCE 0.5 -#define MIN_NUMBER -3.4e10/dim -#define MAX_NUMBER 3.4e10/dim -#define EPSI 1.0e-10 +#define MIN_NUMBER -3.4e10 / dim +#define MAX_NUMBER 3.4e10 / dim +#define EPSI 1.0e-10 #define MIN_DIG_NUMBER 1.0e-10 #define MAX_DIG_NUMBER 3.4e10 @@ -62,97 +62,90 @@ static int dim; -/* - * matrix * vector +/* + * matrix * vector */ -void matrixMulvector(double *value, - int *col_ind, - int *row_start, - double *vector, - double *out) -{ +void matrixMulvector(double *value, int *col_ind, int *row_start, + double *vector, double *out) { int l, ll; - double sum; + double sum; int tmp_rs, tmp_re; - - for (l=0; l */ -void valueMulvector(double value, double *vector, double *vect){ +void valueMulvector(double value, double *vector, double *vect) { int l; int lll, i; double tmp; - for (l=0; l errorTolerance)){ - - /* + while ((iteration < maxIterations) && (error > errorTolerance)) { + + /* * alpha = (transpose(vectorR) * vectorR) / * (transpose(vectorP) * (matrixA * vectorP) */ - matrixMulvector(value, col_ind, row_start, vectorP, tmpVector1); - transpose(vectorR, tmpVector2); + matrixMulvector(value, col_ind, row_start, vectorP, tmpVector1); + transpose(vectorR, tmpVector2); transpose(vectorP, tmpVector3); tmpValue1 = vectorMul(tmpVector3, tmpVector1); tmpValue2 = vectorMul(tmpVector2, vectorR); - alpha = tmpValue2/tmpValue1; - - /* + alpha = tmpValue2 / tmpValue1; + + /* * nextVectorR = vectorR - alpha*(matrixA * vectorP) */ valueMulvector(alpha, tmpVector1, tmpVector2); vectorSub(vectorR, tmpVector2, tmpVector1); equalVector(tmpVector1, nextVectorR); - - /* + + /* * beta = (transpose(nextVectorR) * nextVectorR) / * (transpose(vectorR) * vectorR) */ @@ -391,38 +368,38 @@ void biConjugateGradient(double *value, tmpValue1 = vectorMul(tmpVector3, nextVectorR); transpose(vectorR, tmpVector2); tmpValue2 = vectorMul(tmpVector2, vectorR); - beta = tmpValue1/tmpValue2; + beta = tmpValue1 / tmpValue2; /* * vectorX = vectorX + alpha * vectorP */ - valueMulvector(alpha, vectorP, tmpVector1); - vectorAdd(vectorX,tmpVector1, vectorX); + valueMulvector(alpha, vectorP, tmpVector1); + vectorAdd(vectorX, tmpVector1, vectorX); - /* + /* *vectorP = nextVectorR + beta*vectorP - */ - valueMulvector(beta, vectorP, tmpVector1); + */ + valueMulvector(beta, vectorP, tmpVector1); vectorAdd(nextVectorR, tmpVector1, tmpVector1); - for (ll=0; ll MIN_SEED) && (seed < MAX_SEED)); assert((dim > MIN_DIM) && (dim < MAX_DIM)); - assert((numberNonzero > dim) && (numberNonzero < dim*dim)); + assert((numberNonzero > dim) && (numberNonzero < dim * dim)); assert((maxIterations > 0) && (maxIterations < MAX_ITERATIONS)); assert((errorTolerance > MIN_TOLERANCE) && (errorTolerance < MAX_TOLERANCE)); - - matrixA = (double *)malloc(dim*dim*sizeof(double)); - vectorB = (double *)malloc(dim*sizeof(double)); - vectorX = (double *)malloc(dim*sizeof(double)); - value = (double *)malloc((numberNonzero+dim)*sizeof(double)); - col_ind = (int *)malloc((numberNonzero+dim)*sizeof(int)); - row_start = (int *)malloc((dim+1)*sizeof(int)); + matrixA = (double *)malloc(dim * dim * sizeof(double)); + vectorB = (double *)malloc(dim * sizeof(double)); + vectorX = (double *)malloc(dim * sizeof(double)); + + value = (double *)malloc((numberNonzero + dim) * sizeof(double)); + col_ind = (int *)malloc((numberNonzero + dim) * sizeof(int)); + row_start = (int *)malloc((dim + 1) * sizeof(int)); // Internal matricies for biConj - vectorP = (double *)malloc(dim*sizeof(double)); - vectorR = (double *)malloc(dim*sizeof(double)); - nextVectorR = (double *)malloc(dim*sizeof(double)); - tmpVector1 = (double *)malloc(dim*sizeof(double)); - tmpVector2 = (double *)malloc(dim*sizeof(double)); - tmpVector3 = (double *)malloc(dim*sizeof(double)); + vectorP = (double *)malloc(dim * sizeof(double)); + vectorR = (double *)malloc(dim * sizeof(double)); + nextVectorR = (double *)malloc(dim * sizeof(double)); + tmpVector1 = (double *)malloc(dim * sizeof(double)); + tmpVector2 = (double *)malloc(dim * sizeof(double)); + tmpVector3 = (double *)malloc(dim * sizeof(double)); randInit(seed); @@ -569,23 +538,24 @@ int main(int argc, char** argv) actualError = 0; actualIteration = 0; - biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, errorTolerance, - maxIterations, - &actualError, &actualIteration, dim, - vectorP, vectorR, nextVectorR, tmpVector1, tmpVector2, tmpVector3); + biConjugateGradient(value, col_ind, row_start, vectorB, vectorX, + errorTolerance, maxIterations, &actualError, + &actualIteration, dim, vectorP, vectorR, nextVectorR, + tmpVector1, tmpVector2, tmpVector3); STOP_LOOP endTime = time(NULL); sum = 0; - for (k=1; k #include #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 @@ /* * Sample code for the DIS Neighborhood Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. @@ -17,19 +17,18 @@ * 06/2020 Joshua Bakita Include image creation time in timing */ +#include "DISstressmarkRNG.h" +#include "extra.h" +#include "utili.h" +#include #include #include #include -#include -#include "DISstressmarkRNG.h" -#include "utili.h" -#include "extra.h" -/* +/* * main() */ -int main(int argc, char** argv) -{ +int main(int argc, char **argv) { long int seed; int dimension; int numberLines; @@ -46,10 +45,9 @@ int main(int argc, char** argv) time_t endTime; SET_UP - assert(fscanf(stdin, "%ld %d %d %d %d %d %d %d", - &seed, &bitDepth, &dimension, &numberLines, - &minThickness, &maxThickness, - &distanceShort, &distanceLong) == 8); + assert(fscanf(stdin, "%ld %d %d %d %d %d %d %d", &seed, &bitDepth, &dimension, + &numberLines, &minThickness, &maxThickness, &distanceShort, + &distanceLong) == 8); assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); assert((dimension > 0) && (dimension <= MAX_DIMENSION)); @@ -67,43 +65,32 @@ int main(int argc, char** argv) beginTime = time(NULL); START_LOOP - createImage(image, dimension, maxPixel, numberLines, - minThickness, maxThickness); + createImage(image, dimension, maxPixel, numberLines, minThickness, + maxThickness); - neighborhoodCalculation(image, dimension, - distanceShort, distanceLong, &values, maxPixel); + neighborhoodCalculation(image, dimension, distanceShort, distanceLong, + &values, maxPixel); STOP_LOOP endTime = time(NULL); WRITE_TO_FILE -// printf(" end time is %d\n", endTime); + // printf(" end time is %d\n", endTime); - fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", - values.distShort.deg0.entropy, - values.distShort.deg0.energy, - values.distShort.deg45.entropy, - values.distShort.deg45.energy, - values.distShort.deg90.entropy, - values.distShort.deg90.energy, - values.distShort.deg135.entropy, - values.distShort.deg135.energy); + fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", + values.distShort.deg0.entropy, values.distShort.deg0.energy, + values.distShort.deg45.entropy, values.distShort.deg45.energy, + values.distShort.deg90.entropy, values.distShort.deg90.energy, + values.distShort.deg135.entropy, values.distShort.deg135.energy); - fprintf(stdout,"%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", - values.distLong.deg0.entropy, - values.distLong.deg0.energy,values.distShort.deg45.entropy, - values.distLong.deg45.energy, - values.distLong.deg90.entropy, - values.distLong.deg90.energy, - values.distLong.deg135.entropy, - values.distLong.deg135.energy); + fprintf(stdout, "%9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e %9.4e", + values.distLong.deg0.entropy, values.distLong.deg0.energy, + values.distShort.deg45.entropy, values.distLong.deg45.energy, + values.distLong.deg90.entropy, values.distLong.deg90.energy, + values.distLong.deg135.entropy, values.distLong.deg135.energy); fprintf(stderr, "time for neghborhood stressmark = %f seconds.\n", - difftime(endTime, beginTime)); - + difftime(endTime, beginTime)); + free((Pixel *)image); return (SUCCESS); - } - - - - +} 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 @@ /* * Sample code for the DIS Pointer Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. @@ -22,287 +22,248 @@ #define MIN_PIXEL 0 #define MAX_DIMENSION 32768 -#define MIN_SEED -2147483647 -#define MAX_SEED -1 +#define MIN_SEED -2147483647 +#define MAX_SEED -1 #define MAX_NUMBER_LINES 65536 -#define MIN_BIT_DEPTH 7 -#define MAX_BIT_DEPTH 15 +#define MIN_BIT_DEPTH 7 +#define MAX_BIT_DEPTH 15 typedef struct { int column; int row; -}Coord; +} Coord; -/* +/* * Neighborhood structure consists of the GLCM descriptors entropy and - * energy for each of 2 distance and 4 angels + * energy for each of 2 distance and 4 angels */ typedef struct { float entropy; float energy; -}Descriptors; +} Descriptors; typedef struct { Descriptors deg0; Descriptors deg45; Descriptors deg90; Descriptors deg135; -}Angeles; +} Angeles; typedef struct { Angeles distShort; Angeles distLong; -}Neighborhood; +} Neighborhood; typedef short int Pixel; /* short int;*/ typedef struct { - int numColumns; /* number of columns in image */ - int numRows; /* number of rows in image */ - Pixel maxImageValue; /* max legal image value */ - Pixel *data; /* data pointer */ + int numColumns; /* number of columns in image */ + int numRows; /* number of rows in image */ + Pixel maxImageValue; /* max legal image value */ + Pixel *data; /* data pointer */ } Image; // For correct implementation of drawLineSegment #include "initializeImage.c" -Pixel *createImage (Pixel *image, - int dimension, - Pixel maxPixel, - int numberLines, - int minThickness, - int maxThickness) - { - int i; - - Coord startPoint; - Coord endPoint; - int thickness; - int startValue; - int endValue; - Image img; - img.numColumns = dimension; - img.numRows = dimension; - img.maxImageValue = maxPixel; - img.data = image; - - for (i=0; i= 0) && (binIndex < numBins)); - sumHist[binIndex] += 1; - binIndex = value0 - value1 + maxPixel - MIN_PIXEL; + binIndex = value0 + value1 - 2 * MIN_PIXEL; + assert((binIndex >= 0) && (binIndex < numBins)); + sumHist[binIndex] += 1; + binIndex = value0 - value1 + maxPixel - MIN_PIXEL; - assert((binIndex >= 0) && (binIndex < numBins)); + assert((binIndex >= 0) && (binIndex < numBins)); - diffHist[binIndex] += 1; - totalNumPixels += 1; + diffHist[binIndex] += 1; + totalNumPixels += 1; + } - } - - value0RowOffset += dimension; - value1RowOffset += dimension; + value0RowOffset += dimension; + value1RowOffset += dimension; + } - } - - - if (totalNumPixels > 0){ - int index; - double energySum; - double energyDifference; - double entropyValue; - double sumNormalized; - double diffNormalized; - double scale; - - energySum = (double) 0; - energyDifference = (double) 0; - entropyValue = (double) 0; - scale = 1.e0/totalNumPixels; - for (index = 0; index 0){ - sumNormalized = (double) sumHist[index]*scale; - entropyValue = entropyValue - sumNormalized * - log((double)sumNormalized); - energySum = energySum + sumNormalized * sumNormalized ; - } - if (diffHist[index] > 0){ - diffNormalized = (double)diffHist[index]*scale; - entropyValue = entropyValue - diffNormalized * log(diffNormalized); - energyDifference = energyDifference + - diffNormalized * diffNormalized; - } + if (totalNumPixels > 0) { + int index; + double energySum; + double energyDifference; + double entropyValue; + double sumNormalized; + double diffNormalized; + double scale; + + energySum = (double)0; + energyDifference = (double)0; + entropyValue = (double)0; + scale = 1.e0 / totalNumPixels; + for (index = 0; index < numBins; index++) { + if (sumHist[index] > 0) { + sumNormalized = (double)sumHist[index] * scale; + entropyValue = + entropyValue - sumNormalized * log((double)sumNormalized); + energySum = energySum + sumNormalized * sumNormalized; + } + if (diffHist[index] > 0) { + diffNormalized = (double)diffHist[index] * scale; + entropyValue = entropyValue - diffNormalized * log(diffNormalized); + energyDifference = energyDifference + diffNormalized * diffNormalized; } - *energy = energySum * energyDifference; - *entropy = entropyValue; } - return; -} - - -void neighborhoodCalculation - (Pixel *image, - int dimension, - int distanceShort, - int distanceLong, - Neighborhood *neighborhood, - Pixel maxPixel) - { - int *sumHist, *diffHist; - int numBins; - - numBins = (2 * (maxPixel - MIN_PIXEL + 1) -1); - sumHist = (int *) malloc(numBins * sizeof(int)); - assert (sumHist != NULL); - diffHist = (int *)malloc(numBins * sizeof(int)); - assert(diffHist != NULL); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - distanceShort, 0, - &(neighborhood->distShort.deg0.entropy), - &(neighborhood->distShort.deg0.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - distanceShort, distanceShort, - &(neighborhood->distShort.deg45.entropy), - &(neighborhood->distShort.deg45.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - 0, distanceShort, - &(neighborhood->distShort.deg90.entropy), - &(neighborhood->distShort.deg90.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - -distanceShort, distanceShort, - &(neighborhood->distShort.deg135.entropy), - &(neighborhood->distShort.deg135.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - distanceLong, 0, - &(neighborhood->distLong.deg0.entropy), - &(neighborhood->distLong.deg0.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - distanceLong, distanceLong, - &(neighborhood->distLong.deg45.entropy), - &(neighborhood->distLong.deg45.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - 0, distanceLong, - &(neighborhood->distLong.deg90.entropy), - &(neighborhood->distLong.deg90.energy), dimension, - maxPixel); - - calcEntropyEnergy(sumHist, diffHist, image, numBins, - -distanceLong, distanceLong, - &(neighborhood->distLong.deg135.entropy), - &(neighborhood->distLong.deg135.energy), dimension, - maxPixel); - - free(sumHist); - free(diffHist); - - return; + *energy = energySum * energyDifference; + *entropy = entropyValue; } + return; +} +void neighborhoodCalculation(Pixel *image, int dimension, int distanceShort, + int distanceLong, Neighborhood *neighborhood, + Pixel maxPixel) { + int *sumHist, *diffHist; + int numBins; + + numBins = (2 * (maxPixel - MIN_PIXEL + 1) - 1); + sumHist = (int *)malloc(numBins * sizeof(int)); + assert(sumHist != NULL); + diffHist = (int *)malloc(numBins * sizeof(int)); + assert(diffHist != NULL); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceShort, 0, + &(neighborhood->distShort.deg0.entropy), + &(neighborhood->distShort.deg0.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceShort, + distanceShort, &(neighborhood->distShort.deg45.entropy), + &(neighborhood->distShort.deg45.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, 0, distanceShort, + &(neighborhood->distShort.deg90.entropy), + &(neighborhood->distShort.deg90.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, -distanceShort, + distanceShort, &(neighborhood->distShort.deg135.entropy), + &(neighborhood->distShort.deg135.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceLong, 0, + &(neighborhood->distLong.deg0.entropy), + &(neighborhood->distLong.deg0.energy), dimension, maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, distanceLong, + distanceLong, &(neighborhood->distLong.deg45.entropy), + &(neighborhood->distLong.deg45.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, 0, distanceLong, + &(neighborhood->distLong.deg90.entropy), + &(neighborhood->distLong.deg90.energy), dimension, + maxPixel); + + calcEntropyEnergy(sumHist, diffHist, image, numBins, -distanceLong, + distanceLong, &(neighborhood->distLong.deg135.entropy), + &(neighborhood->distLong.deg135.energy), dimension, + maxPixel); + + free(sumHist); + free(diffHist); + + return; +} 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 @@ +#include #include #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 @@ /* * Sample code for the DIS Pointer Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. * the comments are not repeated here. */ -#include -#include -#include -#include #include "DISstressmarkRNG.h" #include "extra.h" +#include +#include +#include +#include #define MIN_FIELD_SIZE 16 -#define MAX_FIELD_SIZE (16777216*4) // Modifed from original +#define MAX_FIELD_SIZE (16777216 * 4) // Modifed from original #define MIN_WINDOW_SIZE 1 #define MAX_WINDOW_SIZE 15 #define MIN_HOP_LIMIT 1 @@ -35,7 +35,7 @@ /* * main() */ -int main(int argc, char** argv){ +int main(int argc, char **argv) { unsigned int *field; unsigned long f; @@ -46,116 +46,115 @@ int main(int argc, char** argv){ clock_t startTime, endTime; - struct threadS{ + struct threadS { unsigned long initial; unsigned long minStop; unsigned long maxStop; unsigned long hops; - }*thread; + } * thread; unsigned int l; SET_UP - assert(fscanf(stdin, "%lu %u %lu %ld %u", - &f, &l, &maxhops, &seed, &n) == 5); - - assert ((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); - w = (unsigned int) l; - assert ((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); - assert (w % 2 == 1); - assert (f > w); - assert ((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); - assert ((seed >= MIN_SEED) && (seed <= MAX_SEED)); - - assert ((n >= MIN_THREADS) && (n <= MAX_THREADS)); - if ((thread = (struct threadS *)malloc(n*sizeof(struct threadS))) == NULL) - return (-1); - - for (l=0; l= 0) && (thread[l].initial < f)); - assert ((thread[l].minStop >= 0) && (thread[l].minStop < f)); - assert ((thread[l].maxStop >= 0) && (thread[l].maxStop < f)); - } - - if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) - return (-1); - - randInit(seed); - for (l=0; l= minStop) && - (index < maxStop)))){ - - unsigned int ll, lll; - unsigned int max, min; - unsigned int partition; - unsigned int high; - - partition = field[index]; - max = MAX_FIELD_SIZE; - min = 0; - high = 0; - - for (ll=0; ll max) high++; - else if (x > min){ /* start else* */ - partition = x; - balance = 0; - for (lll=ll+1; lll partition) balance++; - }/* end for loop */ - - if (balance+high == w/2) break; - else if (balance+high > w/2){ - min = partition; - }/* end if */ - else { - max = partition; - high++; - }/* end else */ + assert(fscanf(stdin, "%lu %u %lu %ld %u", &f, &l, &maxhops, &seed, &n) == 5); + + assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); + w = (unsigned int)l; + assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); + assert(w % 2 == 1); + assert(f > w); + assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); + assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); + + assert((n >= MIN_THREADS) && (n <= MAX_THREADS)); + if ((thread = (struct threadS *)malloc(n * sizeof(struct threadS))) == NULL) + return (-1); + + for (l = 0; l < n; l++) { + assert(fscanf(stdin, "%lu %lu %lu", &(thread[l].initial), + &(thread[l].minStop), &(thread[l].maxStop)) == 3); + assert((thread[l].initial >= 0) && (thread[l].initial < f)); + assert((thread[l].minStop >= 0) && (thread[l].minStop < f)); + assert((thread[l].maxStop >= 0) && (thread[l].maxStop < f)); } - if (min == max) break; - } /* end else* */ - index = (partition+hops)%(f-w); - hops++; - }/* end loop ll */ - thread[l].hops = hops; -} /* end while */ -STOP_LOOP - - endTime = time(NULL); - - volatile int _stop_optimizer = thread[l].hops + l; - /*for (l=0; l= minStop) && (index < maxStop)))) { + + unsigned int ll, lll; + unsigned int max, min; + unsigned int partition; + unsigned int high; + + partition = field[index]; + max = MAX_FIELD_SIZE; + min = 0; + high = 0; + + for (ll = 0; ll < w; ll++) { + unsigned int balance; + unsigned int x; + x = field[index + ll]; + + if (x > max) + high++; + else if (x > min) { /* start else* */ + partition = x; + balance = 0; + for (lll = ll + 1; lll < w; lll++) { + if (field[index + lll] > partition) + balance++; + } /* end for loop */ + + if (balance + high == w / 2) + break; + else if (balance + high > w / 2) { + min = partition; + } /* end if */ + else { + max = partition; + high++; + } /* end else */ + } + if (min == max) + break; + } /* end else* */ + index = (partition + hops) % (f - w); + hops++; + } /* end loop ll */ + thread[l].hops = hops; + } /* end while */ + STOP_LOOP + + endTime = time(NULL); + + volatile int _stop_optimizer = thread[l].hops + l; + /*for (l=0; l #include #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 @@ /* * Sample code for the DIS Transitive Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. @@ -16,12 +16,12 @@ * Joshua Bakita, 05/30/2020: Fixed out-of-bounds randInt call */ -#include -#include -#include -#include #include "DISstressmarkRNG.h" #include "extra.h" +#include +#include +#include +#include #define MIN_VERTICES 8 #define MAX_VERTICES 16384 @@ -34,11 +34,11 @@ #define MIN_EDGS 0 #define MAX_EDGE 255 -/* +/* * main() */ -int main(int argc, char** argv){ +int main(int argc, char **argv) { unsigned int *din, *dout; unsigned int n; unsigned int m; @@ -49,46 +49,46 @@ int main(int argc, char** argv){ unsigned int sum; volatile int realRes = 0; - assert(fscanf(stdin,"%d %d %d", &n, &m, &seed) == 3); + assert(fscanf(stdin, "%d %d %d", &n, &m, &seed) == 3); assert((n >= MIN_VERTICES) && (n <= MAX_VERTICES)); assert((m >= MIN_EDGES) && (m <= MAX_EDGES)); - assert(m <= n*n); + assert(m <= n * n); assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); - if ((din = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) - return (-1); - if ((dout = (unsigned int *)malloc(n*n*sizeof(unsigned int))) == NULL) - return (-1); + if ((din = (unsigned int *)malloc(n * n * sizeof(unsigned int))) == NULL) + return (-1); + if ((dout = (unsigned int *)malloc(n * n * sizeof(unsigned int))) == NULL) + return (-1); - for (i=0; i #include #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 @@ /* * Sample code for the DIS Update Stressmark * - * This source code is the completely correct source code based on - * the example codes provided by Atlantic Aerospace Division, Titan + * This source code is the completely correct source code based on + * the example codes provided by Atlantic Aerospace Division, Titan * Systems Corporation, 2000. - * - * If you just compile and generate the executables from this source - * code, this code would be enough. However, if you wish to get a complete + * + * If you just compile and generate the executables from this source + * code, this code would be enough. However, if you wish to get a complete * understanding of this stressmark, it is strongly suggested that you * read the Benchmark Analysis and Specifications Document Version 1.0 * before going on since the detailed comments are given in this documents. * the comments are not repeated here. */ +#include "DISstressmarkRNG.h" +#include "extra.h" +#include #include #include #include -#include -#include "DISstressmarkRNG.h" -#include "extra.h" #define MIN_FIELD_SIZE 16 @@ -36,11 +36,11 @@ #define MAX_SEED -1 -/* - *main() +/* + *main() */ - -int main(int argc, char** argv){ + +int main(int argc, char **argv) { unsigned int *field; unsigned int f; @@ -55,13 +55,13 @@ int main(int argc, char** argv){ unsigned int hops; unsigned int l; - assert(fscanf(stdin, "%u %u %u %d %u %u %u", - &f, &l, &maxhops, &seed, &initial, &minStop, &maxStop) == 7); + assert(fscanf(stdin, "%u %u %u %d %u %u %u", &f, &l, &maxhops, &seed, + &initial, &minStop, &maxStop) == 7); assert((f >= MIN_FIELD_SIZE) && (f <= MAX_FIELD_SIZE)); - w = (unsigned int )l; + w = (unsigned int)l; assert((w >= MIN_WINDOW_SIZE) && (w <= MAX_WINDOW_SIZE)); - assert(w%2 == 1); + assert(w % 2 == 1); assert(f > w); assert((maxhops >= MIN_HOP_LIMIT) && (maxhops <= MAX_HOP_LIMIT)); assert((seed >= MIN_SEED) && (seed <= MAX_SEED)); @@ -69,14 +69,14 @@ int main(int argc, char** argv){ assert((minStop >= 0) && (minStop < f)); assert((maxStop >= 0) && (maxStop < f)); - if ((field = (unsigned int *)malloc(f*sizeof(int))) == NULL) + if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) return (-1); - + randInit(seed); - for (l=0; l= minStop) && - (index < maxStop)))){ + while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { int sum; unsigned int ll, lll; @@ -98,43 +96,47 @@ int main(int argc, char** argv){ high = 0; sum = 0; - for (ll=0; ll max) high++; - else if (x >min){ /* start else* */ - partition = x; - balance = 0; - for (lll=ll+1; lll partition) balance++; - } - if (balance+high == w/2) break; - else if (balance+high>w/2){ - min = partition; - }/* end if */ - else{ - max = partition; - high++; - } /* end else */ + if (x > max) + high++; + else if (x > min) { /* start else* */ + partition = x; + balance = 0; + for (lll = ll + 1; lll < w; lll++) { + if (field[index + lll] > partition) + balance++; + } + if (balance + high == w / 2) + break; + else if (balance + high > w / 2) { + min = partition; + } /* end if */ + else { + max = partition; + high++; + } /* end else */ } - if (min == max) break; - }/* end else* */ - field[index] = sum % (f-w); - index = (partition+hops)%(f-w); + if (min == max) + break; + } /* end else* */ + field[index] = sum % (f - w); + index = (partition + hops) % (f - w); hops++; - }/* end for loop */ + } /* end for loop */ STOP_LOOP endTime = time(NULL); volatile int _stop_optimizer = hops; - //fprintf(stdout, "%u hops\n", hops); + // fprintf(stdout, "%u hops\n", hops); fprintf(stderr, "time for update stressmark = %f seconds.\n", difftime(endTime, startTime)); free(field); WRITE_TO_FILE - return(1); + return (1); } -- cgit v1.2.2