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/Update/update.c | 107 ++++++++++++++++++++++++++-------------------------- 1 file changed, 54 insertions(+), 53 deletions(-) (limited to 'dis/Update') 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); -- cgit v1.2.2