diff options
author | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-19 01:30:29 -0400 |
---|---|---|
committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-19 01:30:29 -0400 |
commit | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (patch) | |
tree | e0d2a0f28145ba21312c8d96442228d4b7219ff7 /dis/Update/update.c | |
parent | a71fc97fd262e1b5770f827047ea60bbaf38d9a2 (diff) |
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
Diffstat (limited to 'dis/Update/update.c')
-rw-r--r-- | dis/Update/update.c | 107 |
1 files changed, 54 insertions, 53 deletions
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) { | |||
72 | if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) | 72 | if ((field = (unsigned int *)malloc(f * sizeof(int))) == NULL) |
73 | return (-1); | 73 | return (-1); |
74 | 74 | ||
75 | SET_UP | ||
75 | randInit(seed); | 76 | randInit(seed); |
76 | for (l = 0; l < f; l++) { | ||
77 | field[l] = randInt(0, f - w); | ||
78 | } | ||
79 | 77 | ||
80 | SET_UP | 78 | for_each_job { |
81 | startTime = time(NULL); | 79 | for (l = 0; l < f; l++) { |
82 | 80 | field[l] = randInt(0, f - w); | |
83 | hops = 0; | 81 | } |
84 | index = initial; | 82 | |
85 | 83 | startTime = time(NULL); | |
86 | START_LOOP | 84 | |
87 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { | 85 | hops = 0; |
88 | int sum; | 86 | index = initial; |
89 | 87 | ||
90 | unsigned int ll, lll; | 88 | while ((hops < maxhops) && (!((index >= minStop) && (index < maxStop)))) { |
91 | unsigned int max, min; | 89 | int sum; |
92 | unsigned int partition; | 90 | |
93 | unsigned int high; | 91 | unsigned int ll, lll; |
94 | max = MAX_FIELD_SIZE; | 92 | unsigned int max, min; |
95 | min = 0; | 93 | unsigned int partition; |
96 | high = 0; | 94 | unsigned int high; |
97 | sum = 0; | 95 | max = MAX_FIELD_SIZE; |
98 | 96 | min = 0; | |
99 | for (ll = 0; ll < w; ll++) { | 97 | high = 0; |
100 | unsigned int balance; | 98 | sum = 0; |
101 | unsigned int x; | 99 | |
102 | x = field[index + ll]; | 100 | for (ll = 0; ll < w; ll++) { |
103 | sum += x; | 101 | unsigned int balance; |
104 | 102 | unsigned int x; | |
105 | if (x > max) | 103 | x = field[index + ll]; |
106 | high++; | 104 | sum += x; |
107 | else if (x > min) { /* start else* */ | 105 | |
108 | partition = x; | 106 | if (x > max) |
109 | balance = 0; | 107 | high++; |
110 | for (lll = ll + 1; lll < w; lll++) { | 108 | else if (x > min) { /* start else* */ |
111 | if (field[index + lll] > partition) | 109 | partition = x; |
112 | balance++; | 110 | balance = 0; |
111 | for (lll = ll + 1; lll < w; lll++) { | ||
112 | if (field[index + lll] > partition) | ||
113 | balance++; | ||
114 | } | ||
115 | if (balance + high == w / 2) | ||
116 | break; | ||
117 | else if (balance + high > w / 2) { | ||
118 | min = partition; | ||
119 | } /* end if */ | ||
120 | else { | ||
121 | max = partition; | ||
122 | high++; | ||
123 | } /* end else */ | ||
113 | } | 124 | } |
114 | if (balance + high == w / 2) | 125 | if (min == max) |
115 | break; | 126 | break; |
116 | else if (balance + high > w / 2) { | 127 | } /* end else* */ |
117 | min = partition; | 128 | field[index] = sum % (f - w); |
118 | } /* end if */ | 129 | index = (partition + hops) % (f - w); |
119 | else { | 130 | hops++; |
120 | max = partition; | 131 | } /* end for loop */ |
121 | high++; | 132 | } |
122 | } /* end else */ | ||
123 | } | ||
124 | if (min == max) | ||
125 | break; | ||
126 | } /* end else* */ | ||
127 | field[index] = sum % (f - w); | ||
128 | index = (partition + hops) % (f - w); | ||
129 | hops++; | ||
130 | } /* end for loop */ | ||
131 | STOP_LOOP | ||
132 | 133 | ||
133 | endTime = time(NULL); | 134 | endTime = time(NULL); |
134 | 135 | ||