RN Random Numbers
Total Page:16
File Type:pdf, Size:1020Kb
Random Numb ers RN Copyright C June Computational Science Education Pro ject Remarks Keywords Random pseudorandom linear congruential lagged Fib onacci List of prerequisites some exp osure to sequences and series some abilitytowork in base arithmetic helpful go o d background in FORTRAN or some other pro cedural language List of computational metho ds pseudorandom numb ers random numb ers linear congruential generators LCGs lagged Fib onacci generators LFGs List of architecturescomputers any computer with a FORTRAN compiler and bitwise logical functions List of co des supplied ranlcfor linear congruential generator ranlffor lagged Fib onacci generator randomfor p ortable linear congruential generator after Park and Miller getseedfor to generate initial seeds from the time and date implemented for Unix and IBM PCs Scop e lectures dep ending up on depth of coverage Notation Key a integer multiplier a m c integer constant c m D length of needle in Buons needle exp eriment F fraction of trials needle falls within ruled grid in Buons needle exp eriment k lag in lagged Fib onacci generator k lag in lagged Fib onacci generator k M numb er of binary bits in m m integer mo dulus m N numb er of trials N numb er of parallel pro cessors p P p erio d of generator p a prime integer R random real numb er R n n S spacing b etween grid in Buons needle exp eriment th X n random integer n Subscripts and Sup erscripts denotes initial value or seed th j denotes j value th denotes value th k denotes k value th n denotes n value Monte Carlo Algorithms and Random Numbers In this chapter we discuss the application of Monte Carlo metho ds to scientic and engi neering problems There are problems which can b e solved only by the Monte Carlo metho d and there also are problems which are b est solved bytheMonte Carlo metho d However the metho d is often referred to as the metho d of last resort as it is apt to consume large computing resources As such it is a metho d ideally suitable for inclusion in a textb o ok on computational science as Monte Carlo programs due to their nature of consuming vast computing resources have historically had to b e executed up on the fastest computers avail able at the time and employ the most advanced algorithms implemented with substantial programming acumen Here weprovide a brief history of the Monte Carlo metho d A go o d early work is that of Buons needle problem Ross where in Buon a French mathematician exp erimentally determined a value of by casting a needle on a ruled grid Many trials were required to obtain go o d accuracy The ob jectiveofthework wasavalidation of statistical theory as opp osed to Monte Carlo simulations typically applied to day where answers to new physical problems are sought Lord Rayleigh Rayleigh even delved into this eld near the turn of the century Courant Fredericks and Levy in showed how the metho d could b e used to solve b oundary value problems Ensuing work Hurd illustrated that Remarks Needle Length, D S S > D Obtain π After “Many” Trials S Figure Illustration of Buons Needle Problem if the entire eld were sought Monte Carlo metho ds are far from comp etitive However if the solution in a restricted region of space is sought sayatapoint then Monte Carlo metho ds may b e used to great advantage as they may b e implemented in restricted regions of space andor time Exercise Buons Needle Problem to illustrate geometrically some of the prop erties of random numb ers a Write a program to determine the value of bynumerically casting a needle of length D on a ruled grid with spacing S as shown in Figure You must rst determine a random p osition relative ruled grid as shown in Figure You must rst determine a random p osition relative to a ruled line then determine a random angle and thirdly see whether the needle falls within the ruled lines You may nd it instructiveto compute approximations for versus the numb er of trials eg N and For SDyour answer for the fraction of time F the needle falls within the grid should b e Kalos D F S b Verify the ab ove equation What is the corresp onding formula for SDWarning there is considerable eort involved in this derivation c Using a needle and a piece of pap er up on whichyou have placed a ruled grid p erform aphysical exp eriment to determine using the ab ove equation Perform rst then and then trials Comment on the accuracy of these results relativetothe accuracy of the results from the numerical exp eriment Discuss reasons for any bias apparent in the results Enrico Fermi in the s used Monte Carlo in the calculation of neutron diusion and later designed the Fermiac a Monte Carlo mechanical device used in the calculation of crit icalityinnuclear reactors In the s a formal foundation for the Monte Carlo metho d was develop ed byvon Neumann who established the mathematical basis for probability density functions PDFs inverse cumulative distribution functions CDFs and pseudo random numb er generators The work was done in collab oration with Stanislaw Ulam who realized the imp ortance of the digital computer in the implementation of the approach The collab oration resulted from work on the Manhattan pro ject where the ENIACwas employed in the calculation of yield Ulam et al Ulam and Metrop olis Eckhard Metrop olis Individuals in the IBM corp oration were pioneers in the eld of random numb er gen eration p erhaps b ecause they were rst engaged in it due to their participation in the Manhattan pro ject where Richard Feynman then directed their computing op erations a fascinating exp osition of their approach to p erforming largescale computing involving a parallel approach exists in Richard Feynmans Surely Youre Joking Mr Feynman It is interesting to note the extremely primitive computing environments in existence at that time and the challenges this presented to researchers see Hurd Uses of Monte Carlo metho ds have b een manyandvaried since that time However due to computer limitations the metho d has not yet fully lived up to its p otential as discussed by Metrop olis Metrop olis Indeed this is reected in the stages the metho d has undergone in the elds of engineering In the late s and s the metho d was tested in a variety of engineering elds Meuller Ehrlich Polgar and Howell Ha jiSheikh and Chandler et al At that time even simple problems were computeb ound The metho d has since b een extended to more complex problems Howell Mo dest Maltby a and b Maltby and Burns and Cro ckett et al Since then attention was fo cused up on muchneeded convergence enhancement pro cedures Kahn and Marshall Emery and Carson Burghart and Stevens Lanore Shamsunder et al Zinsmeister and Sawyer Larsen and Howell Many complex problems remained intractable through the seventies With the advent of highsp eed sup ercomputers the eld has received increased attention particularly with parallel algorithms whichhavemuch higher execution rates In his PhD dissertation Brown intro duced the concept of the event step Brown enabling ecientvectorization of Monte Carlo algorithms where the particles do not interact This approachwas later successfully exploited by several investigators Martin et al Martin et al rep orted sp eedups of a factor of ve on an IBM with vector units Nearly linear sp eedup was rep orted Sequent Computer Systems on a parallel architecture for photon tracing Bobrowicz et al Bobrowicz et al a and b obtained sp eedup factors of from ve to eight in an algorithm where particles are accumulated in queues until ecient vector lengths are obtained allowing physics algorithms such as the Los Alamos b enchmark GAMTEB to b e eectively vectorized Burns et al Suchadvanced co ding techniques Remarks have enabled much bigger problems to b e attacked with improved accuracyHowever there are still a host of problems which remain intractable even with an eectively vectorized algorithm Moreover some imp ediments to eectivevectorization have b een identied and analyzed Zhong and Kalos Zhong and Kalos analyzed the straggler problem where few particles p ersist for manyevent steps inhibiting p erformance due to the overhead incurred where vectors are short Pryor and Burns Pryor and Burns Burns and Pryor rep orted for one Monte Carlo problem where particles interact sp eedups on the order of half of those observed where the particles do not interact alb eit with a vectorized algorithm of greatly increased complexity The same problem has b een attacked with dierentphysics McDonald and Bagano Dagum in a more ecient algorithm Go o d general references on Monte Carlo ab ound Beckenback Hammersly and Handscomb Schreider Kleinjnen Rub enstein Binder Ha ji Sheikh in the literature Most haveadistinctbent usually either statistics or physics Unfortunately there is a dearth involving largescale engineering applications No tutorial on largescale Monte Carlo simulation can b e complete without a discussion of pseudorandom numb er generators Where billions of random numb ers are required it is essential that the generator b e of long p erio d have go o d statistical prop erties and b e vectorizable On bit machines these criteria are usually satised with a multiplicative generator if the constants are carefully chosen Kalos and Whitlo ck Indeed wehave come a long way from the early days of random numb er generators Knuth For example Crays FORTRAN callable generator ranf has a cycle length of and is very ecientvectorized with lowoverhead We summarize this intro duction with our impression of the present