PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Webinar

OMP error

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Valerio



Joined: 06 Jul 2005
Posts: 4

PostPosted: Wed Jul 03, 2013 8:00 am    Post subject: OMP error Reply with quote

Could anyone help me to understand why the call of the intrinsic RANDOM_NUMBER within a PARALLEL DO directive in some cases it returns values larger than 1?

Here it follows the test code I made to show the problem.
Code:
      program test
      implicit none
      real*8   e_r
      integer*4 nps,i,j
      write(*,*) 'Number of tests'
      read(*,*) nps
      i=0
c$OMP parallel do private(e_r) reduction(+:i)
      do j=1,nps
         call random_number(e_r)
         if(e_r.gt.1.0d0)then
            write(*,*) e_r
            i=i+1
         endif
      end do
c$OMP end parallel do
      write(*,*) i
      end

the above code was compiled as follows
Code:
pgfortran test.f -mp -o test

Here below you can find the output
Code:
valerio@giusti-145 ~/Documents $ ./test
 Number of tests
1000
    1.539883970671497     
    1.476670404429072     
    1.412861223654971     
            3

Thanks in advance for any suggestion (...and forgive me if I did something stupid :-) ).
Back to top
View user's profile
Valerio



Joined: 06 Jul 2005
Posts: 4

PostPosted: Mon Jul 08, 2013 7:30 am    Post subject: Reply with quote

The above Fortran code compiled with the Intel Fortran Compiler through the following command:
Code:
ifort test.f -openmp -o test

does not return any random number larger than 1.
Code:
valerio@giusti-145 ~/Documents $ ./test
 Number of tests
1000000
           0
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6218
Location: The Portland Group Inc.

PostPosted: Tue Jul 09, 2013 3:36 pm    Post subject: Reply with quote

Hi Valerio,

I don't think our Randon_number's default seed generator is thread safe and might be the root of the problem. I added a problem report (TPR#19454) to see what our engineers can do.

I was able to work around the problem by explicitly setting the seed.
Code:

% cat rand.F90
      program test
      use omp_lib
      implicit none
      real*8   e_r
      integer*4 nps,i,j, thid, seed(32)
      write(*,*) 'Number of tests'
      read(*,*) nps
      seed=123
      call random_seed(put=seed)
      i=0
c$OMP parallel do private(j,e_r) reduction(+:i)
      do j=1,nps
         e_r = 0.0d0
         call random_number(e_r)
         if(e_r.gt.1.0d0)then
            write(*,*) e_r
            i=i+1
         endif
      end do
c$OMP end parallel do
      write(*,*) i
      end
% pgf90 rand.F90 -Mfixed -mp; a.out
 Number of tests
10000
            0


- Mat
Back to top
View user's profile
Valerio



Joined: 06 Jul 2005
Posts: 4

PostPosted: Wed Jul 10, 2013 7:03 am    Post subject: Reply with quote

Hi Mat,
thanks for your answer. I will use your trick to workaround the problem.

Valerio
Back to top
View user's profile
jtull



Joined: 30 Jun 2004
Posts: 445

PostPosted: Mon Nov 25, 2013 5:31 pm    Post subject: TPR 19454 - UF: Random_seed not thread safe Reply with quote

Valerio,

TPR 19454 has been fixed as of the 13.9 release.

thanks,
dave
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group