From 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 19 Oct 2020 01:30:29 -0400 Subject: Enable internal DIS job looping and port to new extra.h API Changes to DIS code: - field, pointer, transitive, and update's random initialization steps moved the main job loop (so that they run on fresh state each job). - Moved free() calls outside of the job loop in matrix - Removed loose clock() call in pointer Misc fixes: - Added input file for neighborhood - Log status before, rather than after, printing in gen_input.py --- dis/Field/field.c | 78 ++++++++++++------------- dis/Matrix/ver2/matrix.c | 40 ++++++------- dis/Neighborhood/neighborhood.c | 14 ++--- dis/Pointer/pointer.c | 121 +++++++++++++++++++-------------------- dis/Transitive/transitive.c | 57 +++++++++--------- dis/Update/update.c | 107 +++++++++++++++++----------------- dis/gen_input.py | 2 +- dis/inputs/Neighborhood/test1.in | 1 + 8 files changed, 211 insertions(+), 209 deletions(-) create mode 100644 dis/inputs/Neighborhood/test1.in (limited to 'dis') diff --git a/dis/Field/field.c b/dis/Field/field.c index 248f779..900d47b 100644 --- a/dis/Field/field.c +++ b/dis/Field/field.c @@ -86,55 +86,55 @@ int main(int argc, char **argv) { return (-1); randInit(seed); - for (l = 0; l < f; l++) { - field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE); - } - startTime = time(NULL); - START_LOOP + for_each_job { + for (l = 0; l < f; l++) { + field[l] = randInt(MIN_TOKEN_VALUE, MAX_TOKEN_VALUE); + } - for (l = 0; l < n; l++) { - unsigned int index; + startTime = time(NULL); - token[l].subfields = 0; - token[l].stat[0].count = 0; - token[l].stat[0].sum = 0; - token[l].stat[0].min = MAX_TOKEN_VALUE; + for (l = 0; l < n; l++) { + unsigned int index; - index = 0; - while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)) { - unsigned char offset; - offset = 0; - while ((field[index + offset] == token[l].delimiter[offset]) && - (offset < token[l].length)) { - offset++; - } + token[l].subfields = 0; + token[l].stat[0].count = 0; + token[l].stat[0].sum = 0; + token[l].stat[0].min = MAX_TOKEN_VALUE; - 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 = 0; + while ((index < f) && (token[l].subfields < MAX_SUBFIELDS)) { + unsigned char offset; + offset = 0; + while ((field[index + offset] == token[l].delimiter[offset]) && + (offset < token[l].length)) { + offset++; } - 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]; + 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++; } - index++; + token[l].subfields++; } - token[l].subfields++; } - - STOP_LOOP endTime = time(NULL); volatile int sumAll = 0; diff --git a/dis/Matrix/ver2/matrix.c b/dis/Matrix/ver2/matrix.c index 2b075fb..5162579 100755 --- a/dis/Matrix/ver2/matrix.c +++ b/dis/Matrix/ver2/matrix.c @@ -407,13 +407,6 @@ void biConjugateGradient(double *value, int *col_ind, int *row_start, *actualError = error; *actualIteration = iteration; - free(tmpVector1); - free(tmpVector2); - free(tmpVector3); - - free(vectorR); - free(vectorP); - return; } @@ -525,27 +518,34 @@ int main(int argc, char **argv) { randInit(seed); - START_LOOP - initMatrix(matrixA, dim, numberNonzero); + for_each_job { + initMatrix(matrixA, dim, numberNonzero); - create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); + create_CRS(matrixA, value, col_ind, row_start, dim, numberNonzero); - initVector(vectorB, dim); - zeroVector(vectorX, dim); + initVector(vectorB, dim); + zeroVector(vectorX, dim); - beginTime = time(NULL); + beginTime = time(NULL); - actualError = 0; - actualIteration = 0; + 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); + free(tmpVector1); + free(tmpVector2); + free(tmpVector3); + + free(vectorR); + free(vectorP); + sum = 0; for (k = 1; k < dim; k++) { sum += sum + *(vectorX + k); diff --git a/dis/Neighborhood/neighborhood.c b/dis/Neighborhood/neighborhood.c index 614b8e8..2d401d3 100644 --- a/dis/Neighborhood/neighborhood.c +++ b/dis/Neighborhood/neighborhood.c @@ -63,14 +63,14 @@ int main(int argc, char **argv) { image = malloc(sizeof(Pixel) * dimension * dimension); assert(image != NULL); - beginTime = time(NULL); - START_LOOP - createImage(image, dimension, maxPixel, numberLines, minThickness, - maxThickness); + for_each_job { + beginTime = time(NULL); + createImage(image, dimension, maxPixel, numberLines, minThickness, + maxThickness); - neighborhoodCalculation(image, dimension, distanceShort, distanceLong, - &values, maxPixel); - STOP_LOOP + neighborhoodCalculation(image, dimension, distanceShort, distanceLong, + &values, maxPixel); + } endTime = time(NULL); WRITE_TO_FILE diff --git a/dis/Pointer/pointer.c b/dis/Pointer/pointer.c index 3f3eefb..d97f276 100644 --- a/dis/Pointer/pointer.c +++ b/dis/Pointer/pointer.c @@ -82,68 +82,67 @@ int main(int argc, char **argv) { return (-1); randInit(seed); - for (l = 0; l < f; l++) { - field[l] = randInt(0, f - w); - } - startTime = time(NULL); - clock(); - - START_LOOP - for (l = 0; l < n; l++) { - unsigned int index; - unsigned int minStop, maxStop; - unsigned int hops; - - hops = 0; - minStop = thread[l].minStop; - maxStop = thread[l].maxStop; - index = thread[l].initial; - while ((hops < maxhops) && (!((index >= 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; + for_each_job { + for (l = 0; l < f; l++) { + field[l] = randInt(0, f - w); + } + startTime = time(NULL); + + for (l = 0; l < n; l++) { + unsigned int index; + unsigned int minStop, maxStop; + unsigned int hops; + + hops = 0; + minStop = thread[l].minStop; + maxStop = thread[l].maxStop; + index = thread[l].initial; + while ((hops < maxhops) && (!((index >= 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++; - } /* 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 + 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 */ + } endTime = time(NULL); diff --git a/dis/Transitive/transitive.c b/dis/Transitive/transitive.c index 51805a6..9337aad 100644 --- a/dis/Transitive/transitive.c +++ b/dis/Transitive/transitive.c @@ -61,42 +61,43 @@ int main(int argc, char **argv) { if ((dout = (unsigned int *)malloc(n * n * sizeof(unsigned int))) == NULL) return (-1); - for (i = 0; i < n * n; i++) { - *(din + i) = NO_PATH; - *(dout + i) = NO_PATH; - } - + SET_UP randInit(seed); - for (k = 0; k < m; k++) { - i = randInt(0, n - 1); - j = randInt(0, n - 1); - *(din + j * n + i) = randInt(MIN_EDGES, MAX_EDGES); - } - SET_UP - startTime = time(NULL); + for_each_job { + for (i = 0; i < n * n; i++) { + *(din + i) = NO_PATH; + *(dout + i) = NO_PATH; + } - START_LOOP - for (k = 0; k < n; k++) { - unsigned int old; - unsigned int new1; - unsigned int *dtemp; + for (k = 0; k < m; k++) { + i = randInt(0, n - 1); + j = randInt(0, n - 1); + *(din + j * n + i) = randInt(MIN_EDGES, MAX_EDGES); + } - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - old = *(din + j * n + i); - new1 = *(din + j * n + k) + *(din + k * n + i); - *(dout + j * n + i) = (new1 < old ? new1 : old); - assert(*(dout + j * n + i) <= NO_PATH); - assert(*(dout + j * n + i) <= *(din + j * n + i)); + startTime = time(NULL); + + for (k = 0; k < n; k++) { + unsigned int old; + unsigned int new1; + unsigned int *dtemp; + + for (i = 0; i < n; i++) { + for (j = 0; j < n; j++) { + old = *(din + j * n + i); + new1 = *(din + j * n + k) + *(din + k * n + i); + *(dout + j * n + i) = (new1 < old ? new1 : old); + assert(*(dout + j * n + i) <= NO_PATH); + assert(*(dout + j * n + i) <= *(din + j * n + i)); + } } + dtemp = dout; + dout = din; + din = dtemp; } - dtemp = dout; - dout = din; - din = dtemp; } - STOP_LOOP stopTime = time(NULL); for (j = 0; j < n; j++) { diff --git a/dis/Update/update.c b/dis/Update/update.c index a12c3df..b7bf2b5 100644 --- a/dis/Update/update.c +++ b/dis/Update/update.c @@ -72,63 +72,64 @@ int main(int argc, char **argv) { if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) return (-1); + SET_UP randInit(seed); - for (l = 0; l < f; l++) { - field[l] = randInt(0, f - w); - } - SET_UP - startTime = time(NULL); - - hops = 0; - index = initial; - - START_LOOP - while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { - int sum; - - unsigned int ll, lll; - unsigned int max, min; - unsigned int partition; - unsigned int high; - max = MAX_FIELD_SIZE; - min = 0; - high = 0; - sum = 0; - - for (ll = 0; ll < w; ll++) { - unsigned int balance; - unsigned int x; - x = field[index + ll]; - sum += x; - - 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++; + for_each_job { + for (l = 0; l < f; l++) { + field[l] = randInt(0, f - w); + } + + startTime = time(NULL); + + hops = 0; + index = initial; + + while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { + int sum; + + unsigned int ll, lll; + unsigned int max, min; + unsigned int partition; + unsigned int high; + max = MAX_FIELD_SIZE; + min = 0; + high = 0; + sum = 0; + + for (ll = 0; ll < w; ll++) { + unsigned int balance; + unsigned int x; + x = field[index + ll]; + sum += x; + + 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 (balance + high == w / 2) + if (min == max) 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); - hops++; - } /* end for loop */ - STOP_LOOP + } /* end else* */ + field[index] = sum % (f - w); + index = (partition + hops) % (f - w); + hops++; + } /* end for loop */ + } endTime = time(NULL); diff --git a/dis/gen_input.py b/dis/gen_input.py index 67ee316..3698e88 100755 --- a/dis/gen_input.py +++ b/dis/gen_input.py @@ -106,8 +106,8 @@ with open(sys.argv[2], "r") as template: # We expect the initialization params to all be on the first line params = template.readline().split() mutated_params = BENCH_TO_PARAMS[benchmark_name](params, wss); - print(" ".join(map(lambda x: str(x), mutated_params))) print("Using", " ".join(map(lambda x: str(x), mutated_params)), "for", benchmark_name, "stressmark", file=sys.stderr) + print(" ".join(map(lambda x: str(x), mutated_params))) if benchmark_name == "pointer": # Clone the data format used in the template for i in range(0,10): diff --git a/dis/inputs/Neighborhood/test1.in b/dis/inputs/Neighborhood/test1.in new file mode 100644 index 0000000..ef34bad --- /dev/null +++ b/dis/inputs/Neighborhood/test1.in @@ -0,0 +1 @@ +-12789 15 5000 3000 5 200 5 20 -- cgit v1.2.2