/* * ---- The Unbalanced Tree Search (UTS) Benchmark ---- * * Copyright (c) 2010 See AUTHORS file for copyright holders * * This file is part of the unbalanced tree search benchmark. This * project is licensed under the MIT Open Source license. See the LICENSE * file for copyright and licensing information. * * UTS is a collaborative project between researchers at the University of * Maryland, the University of North Carolina at Chapel Hill, and the Ohio * State University. See AUTHORS file for more information. * */ /* * Unbalanced Tree Search * * alfg.c * Additive Lagged Fibonacci Generator * - splittable pseudorandom number generator for UTS * */ #include #include #include #include "alfg.h" void rng_init(RNG_state *mystate, int seed) { /************************************************/ /* state_size < 0: this is the special case */ /* where we initialize the root sequence state. */ /* (every subsequent state uses information */ /* copied from its parent state.) */ /************************************************/ int i,j,l,k,cbit,runup,state_size,tmp[861]; int *reg, *node; state_size=2*UTS_ALFG_L-1+N_SCALARS; l=UTS_ALFG_L; k = 0; if(l == 7) { k = 4 ; cbit = 1 ; runup = k*71; } if(l == 17) { k = 12 ; cbit = 5 ; runup = k*65; } if(l == 55) { k = 31 ; cbit = 18 ; runup = k*93; } if(l == 159) { k = 128 ; cbit = 63 ; runup = k*179; } if(l == 607) { k = 334 ; cbit = 166 ; runup = k*628; } if(l == 1279) { k = 861 ; cbit = 233 ; runup = k*1291; } if(!k) { printf("\n\n invalid UTS_ALFG_L value: %d\n\n",l); exit(0); } mystate[J_STATE_SIZE] = state_size; mystate[J_L ] = l; mystate[J_SEED ] = seed; mystate[J_K ] = k; mystate[J_CBIT ] = cbit; mystate[J_RUNUP ] = runup; mystate[J_LP ] = l-1; mystate[J_KP ] = k-1; mystate[J_ZP ] = 0; node = &(mystate[NODE0]); reg = &(mystate[REG0 ]); for(i=0; i> 1) & POS_MASK; return n; } /* advance ALFG and extract random value */ int rng_nextrand(RNG_state *mystate) { int n,l,lp,kp,*reg; l = mystate[J_L ]; lp = mystate[J_LP ]; kp = mystate[J_KP ]; reg = &(mystate[REG0]); reg[lp] += reg[kp]; n = (reg[lp] >> 1) & POS_MASK; lp--; if(lp < 0) lp = l-1; kp--; if(kp < 0) kp = l-1; mystate[J_LP ] = lp; mystate[J_KP ] = kp; return n; } /* condense state into string to display in debugging */ char * rng_showstate(RNG_state *mystate, char *s){ int n,l,lp,*reg; l = mystate[J_L ]; lp = mystate[J_LP ]; reg = &(mystate[REG0]); n = (reg[lp] >> 1) & POS_MASK; sprintf(s,"%.8X...", n); return s; } /* describe random number generator type into string */ int rng_showtype(char *strBuf, int ind) { ind += sprintf(strBuf+ind, "ALFG (state size = %dB, L = %d)", sizeof(struct state_t), UTS_ALFG_L); return ind; }