I'm calculating basically a multidimensional random walk problem. To get more accuracy, I need larger systems (more dimensions), which requires longer time. To speed up the calculation, I'm delving into parallel computing for the first time.

I call the fortran random number generator frequently. It occurred to me that I might split the random number generator off from the rest of the program and run it in parallel. Of course, the generated random numbers would be stored in a shared memory location. Does it seem like this could potentially speed up the computation? Does a random number generator take up a large fraction of the CPU in a random walk problem?


1 Answer 1


The random number generator is rarely the limiting factor in computational science. RNGs are usually quite simple and fast, a few dozen instructions, really. If you are doing anything even remotely complicated in your code with these random numbers, then the bottleneck is there.

  • $\begingroup$ Probably want to profile your code to see where the bottlenecks. But looking ahead, a question for you: If you're thinking about moving to higher number of dimensions, how are you envisioning parallelizing your model? $\endgroup$ Mar 21, 2021 at 22:41
  • $\begingroup$ @rural I don't know if there is a clever way to parallelize this model. However, I do many samples or realizations of the random walk, and I average over such realizations. I could create independent realizations of the model and send each realization to a different thread. I'd call this the brain-dead method of parallelization. The problem there is that I have a big system. Hence, if I create multiple realizations, each realization has a system state that must be stored in memory, and I will soon take up the entire memory. Thanks for your interest. $\endgroup$
    – Chris
    Mar 21, 2021 at 23:08
  • $\begingroup$ Sounds as if you have an 'embarrassingly parallel' model so I assume you're targeting a multinode system. The only advice I can share is to take advantage of existing strategies for distribution of the starting seeds to each processor. That way you avoid the unlikely-theoretically-but-likely-when-you-least-expect-it issue of two processes that you intend to be independent realizations actually sharing the same sequence of variates. $\endgroup$ Mar 21, 2021 at 23:18
  • $\begingroup$ If I understand correctly, @Chris needs to generate a random array which needs to be shared among the threads. Is your problem similar to the Heston problem, Chris? $\endgroup$ Mar 22, 2021 at 0:22
  • $\begingroup$ @rural Yes, embarrassingly parallel, but limited by total memory. I'm learning about sending threads to different cores, but haven't encountered the term "multinode" yet. Abdullah, I'm afraid I don't know about the Heston problem. The various realizations are totally independent; they don't share anything, but the parent thread must sum the results of all realizations. Hope that makes sense. $\endgroup$
    – Chris
    Mar 22, 2021 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.