| 1 | /* |
| 2 | * $Id: speed_seed.c,v 1.9 2009/06/28 14:01:08 jms Exp $ |
| 3 | * |
| 4 | * Revision History |
| 5 | * =================== |
| 6 | * $Log: speed_seed.c,v $ |
| 7 | * Revision 1.9 2009/06/28 14:01:08 jms |
| 8 | * bug fix for DOP |
| 9 | * |
| 10 | * Revision 1.8 2006/08/01 04:13:17 jms |
| 11 | * fix parallel generation |
| 12 | * |
| 13 | * Revision 1.7 2006/07/31 17:23:09 jms |
| 14 | * fix to parallelism problem |
| 15 | * |
| 16 | * Revision 1.6 2006/05/16 16:26:51 jms |
| 17 | * remove calls to FAKE_V_STR |
| 18 | * |
| 19 | * Revision 1.5 2006/04/26 23:14:28 jms |
| 20 | * Declaraion cleanup of fakeVStr() |
| 21 | * |
| 22 | * Revision 1.4 2006/04/26 23:01:10 jms |
| 23 | * address update generation problems |
| 24 | * |
| 25 | * Revision 1.3 2005/10/25 17:26:38 jms |
| 26 | * check in integration between microsoft changes and baseline code |
| 27 | * |
| 28 | * Revision 1.2 2005/01/03 20:08:59 jms |
| 29 | * change line terminations |
| 30 | * |
| 31 | * Revision 1.1.1.1 2004/11/24 23:31:47 jms |
| 32 | * re-establish external server |
| 33 | * |
| 34 | * Revision 1.2 2004/01/22 03:54:12 jms |
| 35 | * 64 bit support changes for customer address |
| 36 | * |
| 37 | * Revision 1.1.1.1 2003/08/08 22:37:36 jms |
| 38 | * recreation after CVS crash |
| 39 | * |
| 40 | * Revision 1.3 2003/08/08 22:37:36 jms |
| 41 | * first integration of rng64 for o_custkey and l_partkey |
| 42 | * |
| 43 | * Revision 1.2 2003/08/07 17:58:34 jms |
| 44 | * Convery RNG to 64bit space as preparation for new large scale RNG |
| 45 | * |
| 46 | * Revision 1.1.1.1 2003/04/03 18:54:21 jms |
| 47 | * initial checkin |
| 48 | * |
| 49 | * |
| 50 | */ |
| 51 | #include <stdio.h> |
| 52 | #include <stdlib.h> |
| 53 | #include "dss.h" |
| 54 | #include "rng64.h" |
| 55 | #include "dss.h" |
| 56 | |
| 57 | /* _tal long RandSeed = "Random^SeedFromTimestamp" (void); */ |
| 58 | |
| 59 | #define ADVANCE_STREAM(stream_id, num_calls) \ |
| 60 | advanceStream(stream_id, num_calls, 0) |
| 61 | #define ADVANCE_STREAM64(stream_id, num_calls) \ |
| 62 | advanceStream(stream_id, num_calls, 1) |
| 63 | #define MAX_COLOR 92 |
| 64 | long name_bits[MAX_COLOR / BITS_PER_LONG]; |
| 65 | extern seed_t Seed[]; |
| 66 | void fakeVStr(int nAvg, long nSeed, DSS_HUGE nCount); |
| 67 | void NthElement (DSS_HUGE N, DSS_HUGE *StartSeed); |
| 68 | |
| 69 | |
| 70 | void |
| 71 | advanceStream(int nStream, DSS_HUGE nCalls, int bUse64Bit) |
| 72 | { |
| 73 | if (bUse64Bit) |
| 74 | Seed[nStream].value = AdvanceRand64(Seed[nStream].value, nCalls); |
| 75 | else |
| 76 | NthElement(nCalls, &Seed[nStream].value); |
| 77 | |
| 78 | #ifdef RNG_TEST |
| 79 | Seed[nStream].nCalls += nCalls; |
| 80 | #endif |
| 81 | |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | /* WARNING! This routine assumes the existence of 64-bit */ |
| 86 | /* integers. The notation used here- "HUGE" is *not* ANSI standard. */ |
| 87 | /* Hopefully, you have this extension as well. If not, use whatever */ |
| 88 | /* nonstandard trick you need to in order to get 64 bit integers. */ |
| 89 | /* The book says that this will work if MAXINT for the type you choose */ |
| 90 | /* is at least 2**46 - 1, so 64 bits is more than you *really* need */ |
| 91 | |
| 92 | static DSS_HUGE Multiplier = 16807; /* or whatever nonstandard */ |
| 93 | static DSS_HUGE Modulus = 2147483647; /* trick you use to get 64 bit int */ |
| 94 | |
| 95 | /* Advances value of Seed after N applications of the random number generator |
| 96 | with multiplier Mult and given Modulus. |
| 97 | NthElement(Seed[],count); |
| 98 | |
| 99 | Theory: We are using a generator of the form |
| 100 | X_n = [Mult * X_(n-1)] mod Modulus. It turns out that |
| 101 | X_n = [(Mult ** n) X_0] mod Modulus. |
| 102 | This can be computed using a divide-and-conquer technique, see |
| 103 | the code below. |
| 104 | |
| 105 | In words, this means that if you want the value of the Seed after n |
| 106 | applications of the generator, you multiply the initial value of the |
| 107 | Seed by the "super multiplier" which is the basic multiplier raised |
| 108 | to the nth power, and then take mod Modulus. |
| 109 | */ |
| 110 | |
| 111 | /* Nth Element of sequence starting with StartSeed */ |
| 112 | void NthElement (DSS_HUGE N, DSS_HUGE *StartSeed) |
| 113 | { |
| 114 | DSS_HUGE Z; |
| 115 | DSS_HUGE Mult; |
| 116 | static int ln=-1; |
| 117 | int i; |
| 118 | |
| 119 | if ((verbose > 0) && ++ln % 1000 == 0) |
| 120 | { |
| 121 | i = ln % LN_CNT; |
| 122 | fprintf(stderr, "%c\b" , lnoise[i]); |
| 123 | } |
| 124 | Mult = Multiplier; |
| 125 | Z = (DSS_HUGE) *StartSeed; |
| 126 | while (N > 0 ) |
| 127 | { |
| 128 | if (N % 2 != 0) /* testing for oddness, this seems portable */ |
| 129 | Z = (Mult * Z) % Modulus; |
| 130 | N = N / 2; /* integer division, truncates */ |
| 131 | Mult = (Mult * Mult) % Modulus; |
| 132 | } |
| 133 | *StartSeed = Z; |
| 134 | |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | /* updates Seed[column] using the a_rnd algorithm */ |
| 140 | void |
| 141 | fake_a_rnd(int min, int max, int column) |
| 142 | { |
| 143 | DSS_HUGE len; |
| 144 | DSS_HUGE itcount; |
| 145 | |
| 146 | RANDOM(len, min, max, column); |
| 147 | if (len % 5L == 0) |
| 148 | itcount = len/5; |
| 149 | else |
| 150 | itcount = len/5 + 1L; |
| 151 | NthElement(itcount, &Seed[column].usage); |
| 152 | #ifdef RNG_TEST |
| 153 | Seed[column].nCalls += itcount; |
| 154 | #endif |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | long |
| 160 | sd_part(int child, DSS_HUGE skip_count) |
| 161 | { |
| 162 | int i; |
| 163 | |
| 164 | for (i=P_MFG_SD; i<= P_CNTR_SD; i++) |
| 165 | ADVANCE_STREAM(i, skip_count); |
| 166 | |
| 167 | ADVANCE_STREAM(P_CMNT_SD, skip_count * 2); |
| 168 | ADVANCE_STREAM(P_NAME_SD, skip_count * 92); |
| 169 | |
| 170 | return(0L); |
| 171 | } |
| 172 | |
| 173 | long |
| 174 | sd_line(int child, DSS_HUGE skip_count) |
| 175 | { |
| 176 | int i,j; |
| 177 | |
| 178 | for (j=0; j < O_LCNT_MAX; j++) |
| 179 | { |
| 180 | for (i=L_QTY_SD; i<= L_RFLG_SD; i++) |
| 181 | /* |
| 182 | if (scale >= 30000 && i == L_PKEY_SD) |
| 183 | ADVANCE_STREAM64(i, skip_count); |
| 184 | else |
| 185 | */ |
| 186 | ADVANCE_STREAM(i, skip_count); |
| 187 | ADVANCE_STREAM(L_CMNT_SD, skip_count * 2); |
| 188 | } |
| 189 | |
| 190 | /* need to special case this as the link between master and detail */ |
| 191 | if (child == 1) |
| 192 | { |
| 193 | ADVANCE_STREAM(O_ODATE_SD, skip_count); |
| 194 | ADVANCE_STREAM(O_LCNT_SD, skip_count); |
| 195 | } |
| 196 | |
| 197 | return(0L); |
| 198 | } |
| 199 | |
| 200 | long |
| 201 | sd_order(int child, DSS_HUGE skip_count) |
| 202 | { |
| 203 | ADVANCE_STREAM(O_LCNT_SD, skip_count); |
| 204 | /* |
| 205 | if (scale >= 30000) |
| 206 | ADVANCE_STREAM64(O_CKEY_SD, skip_count); |
| 207 | else |
| 208 | */ |
| 209 | ADVANCE_STREAM(O_CKEY_SD, skip_count); |
| 210 | ADVANCE_STREAM(O_CMNT_SD, skip_count * 2); |
| 211 | ADVANCE_STREAM(O_SUPP_SD, skip_count); |
| 212 | ADVANCE_STREAM(O_CLRK_SD, skip_count); |
| 213 | ADVANCE_STREAM(O_PRIO_SD, skip_count); |
| 214 | ADVANCE_STREAM(O_ODATE_SD, skip_count); |
| 215 | |
| 216 | return (0L); |
| 217 | } |
| 218 | |
| 219 | long |
| 220 | sd_psupp(int child, DSS_HUGE skip_count) |
| 221 | { |
| 222 | int j; |
| 223 | |
| 224 | for (j=0; j < SUPP_PER_PART; j++) |
| 225 | { |
| 226 | ADVANCE_STREAM(PS_QTY_SD, skip_count); |
| 227 | ADVANCE_STREAM(PS_SCST_SD, skip_count); |
| 228 | ADVANCE_STREAM(PS_CMNT_SD, skip_count * 2); |
| 229 | } |
| 230 | |
| 231 | return(0L); |
| 232 | } |
| 233 | |
| 234 | long |
| 235 | sd_cust(int child, DSS_HUGE skip_count) |
| 236 | { |
| 237 | |
| 238 | ADVANCE_STREAM(C_ADDR_SD, skip_count * 9); |
| 239 | ADVANCE_STREAM(C_CMNT_SD, skip_count * 2); |
| 240 | ADVANCE_STREAM(C_NTRG_SD, skip_count); |
| 241 | ADVANCE_STREAM(C_PHNE_SD, 3L * skip_count); |
| 242 | ADVANCE_STREAM(C_ABAL_SD, skip_count); |
| 243 | ADVANCE_STREAM(C_MSEG_SD, skip_count); |
| 244 | return(0L); |
| 245 | } |
| 246 | |
| 247 | long |
| 248 | sd_supp(int child, DSS_HUGE skip_count) |
| 249 | { |
| 250 | ADVANCE_STREAM(S_NTRG_SD, skip_count); |
| 251 | ADVANCE_STREAM(S_PHNE_SD, 3L * skip_count); |
| 252 | ADVANCE_STREAM(S_ABAL_SD, skip_count); |
| 253 | ADVANCE_STREAM(S_ADDR_SD, skip_count * 9); |
| 254 | ADVANCE_STREAM(S_CMNT_SD, skip_count * 2); |
| 255 | ADVANCE_STREAM(BBB_CMNT_SD, skip_count); |
| 256 | ADVANCE_STREAM(BBB_JNK_SD, skip_count); |
| 257 | ADVANCE_STREAM(BBB_OFFSET_SD, skip_count); |
| 258 | ADVANCE_STREAM(BBB_TYPE_SD, skip_count); /* avoid one trudge */ |
| 259 | |
| 260 | return(0L); |
| 261 | } |
| 262 | |