MULTI THREADING OUTPUT BY OPENMP

General OpenMP discussion

MULTI THREADING OUTPUT BY OPENMP

Postby kin0907 » Fri Sep 20, 2013 2:53 am

Hello.

I've made multithreading code using OPENMP.(FORTRAN)

If I use OMP_NUM_THREADS=1, output values are correct.

But OMP_NUM_THREADS is not 1, values is incorrect.

Especaiily, I can't understand why some values are same even if I set as a private value.


In my parallel design, do-loop generate random values during procedure, and don't have data co-relation each

loop index.

Thus I made a code each loop index is divided some group.

( Ex) If I use OMP_NUM_THREADS=4 & number of index = 16, i=1~4 by OMP_NUM_THREADS=1

...)



ex) if I use OMP_NUM_THREADS=4

complex,pointer :: hb(:,:)

.....



!$omp parallel private(HB)

......
!$omp do
do = 1, 16
.....

ALLOCATE(HB(111,111))

write(i,*) HB(1,1)
------------------------------------------------------------------------------

Then
write(1,*) HB(1,1) (0.42554254221210020,0.000000000000000000E+00)
write(5,*) HB(1,1) (0.908729526171800250,0.000000000000000000E+00)
write(9,*) HB(1,1) (0.908729526171800250,0.000000000000000000E+00)
write(13,*) HB(1,1) (0.908729526171800250,0.000000000000000000E+00)

write(2,*) HB(1,1) (-0.21554254221210020,0.000000000000000000E+00)
write(6,*) HB(1,1) (0.1316354813,0.000000000000000000E+00)
write(10,*) HB(1,1) (0.1316354813,0.000000000000000000E+00)
write(14,*) HB(1,1) (0.1316354813,0.000000000000000000E+00)

write(3,*) HB(1,1) (0.54125125210,0.000000000000000000E+00)
write(7,*) HB(1,1) (-0.7054345171800250,0.000000000000000000E+00)
write(11,*) HB(1,1) (-0.7054345171800250,0.000000000000000000E+00)
write(15,*) HB(1,1) (-0.7054345171800250,0.000000000000000000E+00)

write(4,*) HB(1,1) (-0.12554254221210020,0.000000000000000000E+00)
write(8,*) HB(1,1) (0.43643643643630,0.000000000000000000E+00)
write(12,*) HB(1,1) (0.43643643643630,0.000000000000000000E+00)
write(16,*) HB(1,1) (0.43643643643630,0.000000000000000000E+00)


I can't understand this situation.(I've changed type of schedule,but same, Above values is generated by non-specific do loop schedule)

WHY i=1~4 are only correct, and other values are duplicated??

I use XLF FORTRAN, and complie just like below

xlf2003_r -O3 -q64 -qfixed -qsmp=omp -qarch=auto -qtune=auto -qautodbl=dbl4 -qmaxmem=-1 -lesslsmp kk.f
kin0907
 
Posts: 2
Joined: Sat Sep 14, 2013 11:42 pm

Re: MULTI THREADING OUTPUT BY OPENMP

Postby MarkB » Fri Sep 20, 2013 8:29 am

What function are you using to generate random numbers? If you are calling this from inside the parallel region, are you sure that it is thread-safe?
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Re: MULTI THREADING OUTPUT BY OPENMP

Postby kin0907 » Fri Sep 20, 2013 11:03 am

To Mark

A subroutine generates random work using Random_Number

Show below code

TYPE ATOM_DATA
sequence
INTEGER :: name
REAL :: coord(3)
END TYPE

complex,pointer :: hb(:,:)
REAL, pointer :: Vpot(:)
.....


!$omp parallel private(HB)

......
!$omp do
do = 1, 16
.....

ALLOCATE(HB(111,111))
call kin(HB,Vpot,....)

write(i,*) HB(1,1)
-----------------------------

subroutine kin(HB,Vpot,...)
TYPE (ATOM_DATA) :: atom_block(max_block_natom)
REAL :: rand,W
integer :: n,ii

DO ii=1,n/2
W = Vpot(atom_block(ii)%name)
CALL Random_Number(rand)
rand = rand*W - W/2.0
HB(ii,ii) = rand
HB(ii+n/2,ii+n/2) = rand
end

end


Even if thread has a copy of local variable, each thread is needed thread-safe random_number generation?

I don'w know that "Random_number" is thread-safe subroutine or not.

I made a CUDA codes using thread-safe random number generation function but I don't know about thread-safe

subroutine or function in FORTRAN OpenMP.

(Above "Random_number" is used an intrinsic subroutine in fortran.)

And this code is not declared "implict none" <-- I'm just only deal with parallel programming about this codes, not other works. Thus, I should have only small modify as possible as I can.

(Due to simple,fast, and extensive shared memory arch for system(target system has 64 core per nodes)
I picked up OpenMP rather than other library(such as MPI..)) )
kin0907
 
Posts: 2
Joined: Sat Sep 14, 2013 11:42 pm

Re: MULTI THREADING OUTPUT BY OPENMP

Postby MarkB » Mon Sep 23, 2013 2:29 am

I think Random_Number should be thread-safe under xlf. One way to check if this is a problem would be to enclose the call to it in an OpenMP critical construct and/or print the returned values.

Is the fact that you appear to be allocating HB once per loop iteration (instead of once per thread) a problem?
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 7 guests