I have started reading the book by Chandra et al. To practice I wrote a simple program that uses Monte Carlo integration technique. In this technique, to calculate integral of a function in a given interval you evaluate that function at randomly selected points in this interval. Average value of the function values times length of the interval gives the integral.
After writing my code using OpenMP directives I compiled it with -openmp option using Intel Fortran Compiler. After running the code I observed that program runs much slower in parallel version. At first I thought that I am making a mistake with OpenMP. I checked again and again found nothing. As a final effort I google " random number openmp slow" that was my last hope.
Then I found that OpenMP runs intrinsic random number function of fortran slower in parallel. The reason of this behavior explained here. Simply, intrinsic random_number function has a variable with "saved" attribute. Because of that every thread that calls this function should wait each other. The only solution for this problem is to use your own parallel random number generator. Hopefully they posted a solution at referred web site. They also supplied a parallel random number generator written in F90, this code can be downloaded here. However there are few bugs in this code. I have cleaned those bugs and added some features to this code. My version can be downloaded here.
while I was trying to learn OpenMP api