1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors: |
34 | * Gradient Systems |
35 | */ |
36 | #include "config.h" |
37 | #include "porting.h" |
38 | #include <stdio.h> |
39 | #include "r_params.h" |
40 | #include "scaling.h" |
41 | #include "tdefs.h" |
42 | #include "genrand.h" |
43 | |
44 | /* |
45 | * Routine: split_work(int tnum, worker_t *w) |
46 | * Purpose: allocate work between processes and threads |
47 | * Algorithm: |
48 | * Data Structures: |
49 | * |
50 | * Params: |
51 | * Returns: |
52 | * Called By: |
53 | * Calls: |
54 | * Assumptions: |
55 | * Side Effects: |
56 | * TODO: None |
57 | */ |
58 | int split_work(int tnum, ds_key_t *pkFirstRow, ds_key_t *pkRowCount) { |
59 | ds_key_t kTotalRows, kRowsetSize, ; |
60 | int nParallel, nChild; |
61 | |
62 | kTotalRows = get_rowcount(tnum); |
63 | nParallel = get_int("PARALLEL" ); |
64 | nChild = get_int("CHILD" ); |
65 | |
66 | /* |
67 | * 1. small tables aren't paralelized |
68 | * 2. nothing is parallelized unless a command line arg is supplied |
69 | */ |
70 | *pkFirstRow = 1; |
71 | *pkRowCount = kTotalRows; |
72 | |
73 | if (kTotalRows < 1000000) { |
74 | if (nChild > 1) /* small table; only build it once */ |
75 | { |
76 | *pkFirstRow = 1; |
77 | *pkRowCount = 0; |
78 | return (0); |
79 | } |
80 | return (1); |
81 | } |
82 | |
83 | if (!is_set("PARALLEL" )) { |
84 | return (1); |
85 | } |
86 | |
87 | /* |
88 | * at this point, do the calculation to set the rowcount for this part of a |
89 | * parallel build |
90 | */ |
91 | kExtraRows = kTotalRows % nParallel; |
92 | kRowsetSize = (kTotalRows - kExtraRows) / nParallel; |
93 | |
94 | /* start the starting row id */ |
95 | *pkFirstRow += (nChild - 1) * kRowsetSize; |
96 | if (kExtraRows && (nChild - 1)) |
97 | *pkFirstRow += ((nChild - 1) < kExtraRows) ? (nChild - 1) : kExtraRows; |
98 | |
99 | /* set the rowcount for this child */ |
100 | *pkRowCount = kRowsetSize; |
101 | if (kExtraRows && (nChild <= kExtraRows)) |
102 | *pkRowCount += 1; |
103 | |
104 | return (1); |
105 | } |
106 | |
107 | /* |
108 | * Routine: |
109 | * Purpose: |
110 | * Algorithm: |
111 | * Data Structures: |
112 | * |
113 | * Params: |
114 | * Returns: |
115 | * Called By: |
116 | * Calls: |
117 | * Assumptions: |
118 | * Side Effects: |
119 | * TODO: None |
120 | */ |
121 | int checkSeeds(tdef *pTdef) { |
122 | int i, res, nReturnCode = 0; |
123 | static int bInit = 0, bSetSeeds = 0; |
124 | |
125 | if (!bInit) { |
126 | bSetSeeds = is_set("CHKSEEDS" ); |
127 | bInit = 1; |
128 | } |
129 | |
130 | for (i = pTdef->nFirstColumn; i <= pTdef->nLastColumn; i++) { |
131 | while (Streams[i].nUsed < Streams[i].nUsedPerRow) |
132 | genrand_integer(&res, DIST_UNIFORM, 1, 100, 0, i); |
133 | if (bSetSeeds) { |
134 | if (Streams[i].nUsed > Streams[i].nUsedPerRow) { |
135 | fprintf(stderr, "Seed overrun on column %d. Used: %d\n" , i, Streams[i].nUsed); |
136 | Streams[i].nUsedPerRow = Streams[i].nUsed; |
137 | nReturnCode = 1; |
138 | } |
139 | } |
140 | Streams[i].nUsed = 0; /* reset for the next time */ |
141 | } |
142 | |
143 | return (nReturnCode); |
144 | } |
145 | |
146 | /* |
147 | * Routine: |
148 | * Purpose: |
149 | * Algorithm: |
150 | * Data Structures: |
151 | * |
152 | * Params: |
153 | * Returns: |
154 | * Called By: |
155 | * Calls: |
156 | * Assumptions: |
157 | * Side Effects: |
158 | * TODO: None |
159 | */ |
160 | int row_stop(int tbl) { |
161 | tdef *pTdef; |
162 | |
163 | pTdef = getSimpleTdefsByNumber(tbl); |
164 | checkSeeds(pTdef); |
165 | if (pTdef->flags & FL_PARENT) { |
166 | pTdef = getSimpleTdefsByNumber(pTdef->nParam); |
167 | checkSeeds(pTdef); |
168 | if (pTdef->flags & FL_PARENT) { |
169 | pTdef = getSimpleTdefsByNumber(pTdef->nParam); |
170 | checkSeeds(pTdef); |
171 | } |
172 | } |
173 | |
174 | return (0); |
175 | } |
176 | |
177 | /* |
178 | * Routine: row_skip |
179 | * Purpose: skip over un-used rows in a table |
180 | * Algorithm: |
181 | * Data Structures: |
182 | * |
183 | * Params: |
184 | * Returns: |
185 | * Called By: |
186 | * Calls: |
187 | * Assumptions: |
188 | * Side Effects: |
189 | * TODO: 20020816 jms The second parameter should really be a ds_key_t to allow |
190 | * BIG skips |
191 | */ |
192 | int row_skip(int tbl, ds_key_t count) { |
193 | int i; |
194 | |
195 | for (i = 0; Streams[i].nColumn != -1; i++) { |
196 | if (Streams[i].nTable == tbl) { |
197 | skip_random(i, count * Streams[i].nUsedPerRow); |
198 | Streams[i].nUsed = 0; |
199 | Streams[i].nTotal = count * Streams[i].nUsedPerRow; |
200 | } |
201 | if (Streams[i].nDuplicateOf && (Streams[i].nDuplicateOf != i)) { |
202 | skip_random(Streams[i].nDuplicateOf, count * Streams[Streams[i].nDuplicateOf].nUsedPerRow); |
203 | Streams[Streams[i].nDuplicateOf].nUsed = 0; |
204 | Streams[Streams[i].nDuplicateOf].nTotal = count * Streams[i].nUsedPerRow; |
205 | } |
206 | } |
207 | |
208 | return (0); |
209 | } |
210 | |