33 #define __MIXMAX_C // do NOT define it in your own program, just include mixmax.h
47 inline uint64_t
MULWU (uint64_t){
return 0;}
49 #error SPECIALMUL not undefined
59 Y[0] = ( tempV = sumtotOld);
60 myuint sumtot = Y[0], ovflow = 0;
65 tempP =
modadd(tempP,Y[i]);
68 tempP =
modadd(tempP , Y[i]);
69 tempV =
modadd(tempV , tempP);
72 sumtot += tempV;
if (sumtot < tempV) {ovflow++;}
75 temp2 = MOD_MULSPEC(temp2);
76 Y[2] =
modadd( Y[2] , temp2 );
77 sumtot += temp2;
if (sumtot < temp2) {ovflow++;}
95 for (i=0; i<(n/M); i++){
98 unsigned int rem=(n % M);
101 for (j=0; j< (rem); j++){
119 myuint sumtot = 0, ovflow = 0;
122 tempP =
modadd(tempP,Y[i]);
123 Y[i] = ( tempV =
modadd(tempV,tempP) );
124 sumtot += tempV;
if (sumtot < tempV) {ovflow++;}
128 temp2 = MOD_MULSPEC(temp2);
129 Y[2] =
modadd( Y[2] , temp2 );
130 sumtot += temp2;
if (sumtot < temp2) {ovflow++;}
136 #if defined(__x86_64__) && defined(USE_INLINE_ASM)
139 __asm__ (
"addq %2, %0; "
176 for ( i=0; i <
N; i++){
178 sumtot += X->
V[(i)];
if (sumtot < X->V[(i)]) {ovflow++;}
189 for (i=0; i <
N; i++){
199 if (X->
fh==NULL){X->
fh=stdout;}
204 const myuint MULT64=6364136223846793005ULL;
208 fprintf(stderr,
" try seeding with nonzero seed next time!\n");
215 if (X->
fh==NULL){X->
fh=stdout;}
216 for (i=0; i <
N; i++){
217 l*=MULT64; l = (l << 32) ^ (l>>32);
219 sumtot += X->
V[(i)];
if (sumtot < X->V[(i)]) {ovflow++;}
229 for (i=0; i <
N; i++){
239 #if defined(__x86_64__)
240 inline myuint mod128(__uint128_t
s){
248 temp = (__uint128_t)a*(__uint128_t)b + cum;
252 #else // on all other platforms, including 32-bit linux, PPC and PPC64 and all Windows
253 #define MASK32 0xFFFFFFFFULL
263 o = (o &
M61) + ((ph*ah)<<3) + ((ah*pl+al*ph + ((al*pl)>>32))>>29) ;
265 o = (o &
M61) + ((o>>61));
272 fprintf(X->
fh,
"mixmax state, file version 1.0\n" );
275 fprintf(X->
fh,
"%llu, ", X->
V[j] );
278 fprintf(X->
fh,
"}; " );
279 fprintf(X->
fh,
"counter=%u; ", X->
counter );
280 fprintf(X->
fh,
"sumtot=%llu;\n", X->
sumtot );
286 if( ( fin = fopen(filename,
"r") ) ){
293 fprintf(stderr,
"mixmax -> read_state: error reading file %s\n", filename);
299 if (!fscanf(fin,
"%llu", &X->
V[0]) ) {fprintf(stderr,
"mixmax -> read_state: error reading file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
303 if (!fscanf(fin,
", %llu", &vecVal) ) {fprintf(stderr,
"mixmax -> read_state: error reading vector component i=%d from file %s\n", i, filename); exit(
ERROR_READING_STATE_FILE);}
308 fprintf(stderr,
"mixmax -> read_state: Invalid state vector value= %llu"
309 " ( must be less than %llu ) "
310 " obtained from reading file %s\n"
316 unsigned int counter;
317 if (!fscanf( fin,
"}; counter=%u; ", &counter)){fprintf(stderr,
"mixmax -> read_state: error reading counter from file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
321 fprintf(stderr,
"mixmax -> read_state: Invalid counter = %d"
322 " Must be 0 <= counter < %u\n" , counter,
N);
328 if (!fscanf( fin,
"sumtot=%llu\n", &sumtot)){fprintf(stderr,
"mixmax -> read_state: error reading checksum from file %s\n", filename); exit(
ERROR_READING_STATE_FILE);}
330 if (X->
sumtot != sumtot) {
331 fprintf(stderr,
"mixmax -> checksum error while reading state from file %s - corrupted?\n", filename);
339 #define FUSEDMODMULVEC \
340 { for (i =0; i<N; i++){ \
341 cum[i] = fmodmulM61( cum[i], coeff , Y[i] ) ; \
347 #if (BITS==61 && SKIPISON!=0)
350 Xin->sumtot =
apply_bigskip(Xin->V, Xin->V, clusterID, machineID, runID, streamID );
351 if (Xin->fh==NULL){Xin->fh=stdout;}
355 Xin->sumtot =
apply_bigskip(Xin->V, Xin->V, IDvec[3], IDvec[2], IDvec[1], IDvec[0] );
385 #include "CLHEP/Random/mixmax_skip_N17.icc"
397 myID_t IDvec[4] = {streamID, runID, machineID, clusterID};
406 for (i=0; i<
N; i++) { Y[i] = Vin[i]; sumtot =
modadd( sumtot, Vin[i]); } ;
407 for (IDindex=0; IDindex<4; IDindex++) {
413 rowPtr = (
myuint*)skipMat[r + IDindex*8*
sizeof(
myID_t)];
415 for (i=0; i<
N; i++){ cum[i] = 0; }
423 for (i=0; i<
N; i++){ Y[i] = cum[i]; sumtot =
modadd( sumtot, cum[i]); } ;
429 for (i=0; i<
N; i++){ Vout[i] = Y[i]; sumtot =
modadd( sumtot, Y[i]); } ;
433 #warning For this N, we dont have the skipping coefficients yet, using alternative method to seed
440 Xin->
V[4] = (
myuint)clusterID << 5;
441 Xin->
V[5] = (
myuint)machineID << 7;
442 Xin->
V[6] = (
myuint)runID << 11;
443 Xin->
V[7] = (
myuint)streamID << 13;
void print_state(rng_state_t *X)
myuint GET_BY_MACRO(rng_state_t *X)
myuint get_next(rng_state_t *X)
#define ERROR_READING_STATE_FILE
void seed_vielbein(rng_state_t *X, unsigned int i)
int rng_free(rng_state_t *X)
myuint fmodmulM61(myuint cum, myuint s, myuint a)
void seed_uniquestream(rng_state_t *X, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
int iterate(rng_state_t *X)
#define ARRAY_INDEX_OUT_OF_BOUNDS
void seed_spbox(rng_state_t *X, myuint seed)
double get_next_float(rng_state_t *X)
rng_state_t * rng_alloc()
rng_state_t * rng_copy(myuint *Y)
static constexpr double s
myuint apply_bigskip(myuint *Vout, myuint *Vin, myID_t clusterID, myID_t machineID, myID_t runID, myID_t streamID)
myuint iterate_raw_vec(myuint *Y, myuint sumtotOld)
void iterate_and_fill_array(rng_state_t *X, double *array)
#define ERROR_READING_STATE_CHECKSUM
void branch_inplace(rng_state_t *Xin, myID_t *ID)
static constexpr double bar
myuint precalc(rng_state_t *X)
myuint modadd(myuint foo, myuint bar)
void fill_array(rng_state_t *X, unsigned int n, double *array)
double get_next_float_BY_MACRO(rng_state_t *X)
void read_state(rng_state_t *X, const char filename[])
#define ERROR_READING_STATE_COUNTER
struct rng_state_st rng_state_t