RANDOM_MPI - Master process: C version The number of processors is P = 1 This program shows how a stream of random numbers can be computed 'in parallel' in an MPI program. We assume we are using a linear congruential random number generator or LCRG, which takes an integer input and returns a new integer output: U = ( A * V + B ) mod C We assume that we want the MPI program to produce the same sequence of random values as a sequential program would - but we want each processor to compute one part of that sequence. We do this by computing a new LCRG which can compute every P'th entry of the original one. Our LCRG works with integers, but it is easy to turn each integer into a real number between [0,1]. LCRG parameters: A = 16807 B = 0 C = 2147483647 Let processor 0 generate the entire random number sequence. K ID Input Output 0 0 12345 1 0 12345 207482415 2 0 207482415 1790989824 3 0 1790989824 2035175616 4 0 2035175616 77048696 5 0 77048696 24794531 6 0 24794531 109854999 7 0 109854999 1644515420 8 0 1644515420 1256127050 9 0 1256127050 1963079340 10 0 1963079340 1683198519 LCRG parameters for P processors: AN = 16807 BN = 0 C = 2147483647 Have ALL the processors participate in computing the same random number sequence. K ID Input Output 0 0 12345 1 0 12345 207482415 2 0 207482415 1790989824 3 0 1790989824 2035175616 4 0 2035175616 77048696 5 0 77048696 24794531 6 0 24794531 109854999 7 0 109854999 1644515420 8 0 1644515420 1256127050 9 0 1256127050 1963079340 10 0 1963079340 1683198519 RANDOM_MPI: Normal end of execution.