parallel spin-flip with OpenMP

parallel spin-flip with OpenMP

Hello everyone,

I trying to run parallel the above simple spin-flip program:

 

!$OMP PARALLEL DO SHARED(S) PRIVATE(I,J,I1,J1,ID,JD,U,R,PROB,A1,A2)  
    
    DO J=1,NY
    DO I=1,NX

    A2=0.0d0
 
    A1= S(I,J)
    A2= dble(S(IP(I),J)+S(IM(I),J)+S(I,JP(J))+S(I,JM(J)))
      
    CALL RANDOM_NUMBER (U) 
    U=dble(U)   

    R=DEXP((-2.0d0*A2)/dble(TEMP)) 
    PROB=1.0d0/(1.0d0+R)
    
    IF (U<PROB) THEN 
     S(I,J)=1.0
    ELSE
     S(I,J)=-1.0
    END IF
    IF (S(I,J)==-A1) CT=CT+1
 !  !$omp flush (S)
    END DO
    END DO
 
!$OMP END PARALLEL DO

The question is whether each thread sees the correct, updated, values of the spin matrix S

when it tries to flip the spin. I have declared S as a shared variable, is that sufficient? If not adding a flush directive after the spin-flip trial:

IF (U<PROB) THEN 
     S(I,J)=1.0
    ELSE
     S(I,J)=-1.0
    END IF
    IF (S(I,J)==-A1) CT=CT+1
!$omp flush (S)

makes each thread see the updated values of the spin matrix S? Or something else is needed?

 

Thanks,

 

Marios

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You are asking a general OpenMP question in a forum that is specifically intended for discussion of the implementation of the Intel Open-Source OpenMP runtme. 

You would be better taking a question like this to http://stackoverflow.com which has many more readers, and has an OpenMP tag so that you can target it to those interested. 

Login to leave a comment.