20 Aralık 2009 Pazar

Random Number Generator in OpenMP

Few days ago I have started to learn OpenMP api. Before using it in my research project I started with "Hello World" type examples. OpenMP basically is a set of compiler directives which can be used to parallelize your code. Instead of message passing between cpu's OpenMP uses shared memory architecture. Every core in a multicore cpu uses same memory and if your job doesn't require huge amount of cpus OpenMP is a good choice. Detailed information can be obtained at OpenMP web site.
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

Hiç yorum yok:

Yorum Gönder