23
A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

Embed Size (px)

Citation preview

Page 1: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

A S C A L A B L E L I B R A R Y F O R P S E U D O R A N D O M N U M B E R G E N E R A T I O N

ALGORITHM 806: SPRNG

Page 2: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

ABOUT: PSEUDO-RANDOM LIBRARIES

• Many Libraries• Parameterization – based libraries • Erroneous => Real world applications• New Library – SPRNG • Purpose of SPRNG ?

Page 3: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

INTRODUCTION

• Problems: • Erroneous => Monte Carlo Applications• High Performance Cycles• Parallelism – More Complicates• Solution:• SPRNG – Scalable and Distributed Architecture

Page 4: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

PARALLEL PSEUDORANDOM-NUMBER GENERATION

• Methods - Parameterization • Linear Congruential Generators:• Commonly used generator• Linear Recursion :

• Periodic Sequence

Page 5: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

PRIME MODULUS

• ‘m’ is prime• Determine family of a’s• Obtain Maximal period

• ‘i ’ relatively prime to

Produce Primitive element ‘j’:

PROBLEM:Overall efficiency of PPRNG ?1. Cost of Computing or2. cost of modular multiplication

Page 6: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• Exponential Sum:

• Full period • Partially period • Upper Bounds: Equidistributed

• Parallel: • Exponential Sum Correlation is :

Page 7: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• Upper Bound:

• Open Questions:• Choosing ‘m’ ? A. Fast modular multiplication or fast

calculation of jth integer • Good intrastream correlation also ensure good

intrastream independence to performance ?

• Hence Such techniques are less attractive for parallel Pseudo random number generation.

Page 8: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

LAGGED- FIBONACCI GENERATOR

• Previous: Varying parameters - recursion • Now: Parameterized – Initial Value• ALFG Equation:

• Popular : Serial and Scalable Parallel Machines• Reasons: • 1. Easy to implement• 2. Cheap to compute• It does well on statistical tests

Page 9: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• Maximal Period :

• Template :

Page 10: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• O(K*K) Template :

• Advantage: • Optimal Disadvantage : No proof and improvement of this analytical is open challenge

Page 11: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• Advantage: Good for Floating point • However, care must be taken to maintain the

uniqueness of the parallel streams

Page 12: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

SPRNG

• Random Number streams to parallel processes• Advantages:• 1. Several, Distinct, Well tested, Scalable PRNGs• 2. Initailization without Inter process

communication • 3. Reproducibility • 4. Minimization of Interprocess correaltion• 5. Uniformity• 6. Integrated Test Suites• 7. Extensibility

Page 13: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

GENERATORS

• Additive lagged Fibonacci• Multiplicative Lagged Fibonacci • Prime Modules Multiplicative Congruential• Power-of-two modules linear Congruential• Combined Multiplicative Recursive generator

Page 14: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

EXAMPLES

• Download: • http://sprng.cs.fsu.edu• Definition: init_sprng routine• int *init_sprng(int streamnum, int nstreams, int

seed, int param)

Page 15: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• #include <cstdio>•  • #define SIMPLE_SPRNG /* simple interface */• #include "sprng.h" /* SPRNG header file */•  • using namespace std;•  •  • int main()• {• double rn;• int i;•  • printf(" Printing 3 random numbers in [0,1):\n");•  • for (i=0;i<3;i++)• {• rn = sprng(); /* generate double precision random number */• printf("%f\n",rn);• }•  • return 0;• }

Page 16: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

EXECUTION

• $> ./simple-simple • Printing 3 random numbers in [0,1):• 0.014267• 0.749392• 0.007316

Page 17: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

SPRNG TEST SUITE

• Intrastream Correlation• Interstream Correlation

• Statistical Test

Page 18: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG
Page 19: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• Example: • test.lib nstreams ncombine seed param nblocks

skip • Ex: eqi-distance.lcg 4 2 0 0 3 1 2 100• mpirun -np 2 equidistnce.lcg 4 2 0 0 3 1 2 100• Result:• mpirun -np 2 eqidist.lcg 4 2 0 0 3 1 2 1 00• eqidistance.lcg 4 2 0 0 3 1 2 100• KS value : 0.601252• KS value prob : 17.50• Hence, It is b/w 2.5% and 97.5% It is passed

Page 20: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

• There are different tests that are described by Knuth are described in SPRNG library such as • Collision tests• Coupons Collector tests• Equidistance tests• Gap test• Permutation tests• Poker tests• Serial test

Page 21: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

PHYSICALLY BASED TESTS:

• Ising Model :• Random Walk Test:

Page 22: A SCALABLE LIBRARY FOR PSEUDORANDOM NUMBER GENERATION ALGORITHM 806: SPRNG

CONCLUSION

• Comprehensive Library• Recursions are simple • Reusable• Extensibility• Uniformity : C, C++, MPI and FORTRAN