c-------------------------------------------------------------------- 
c                 Test OMP parallelization
c-------------------------------------------------------------------- 
      parameter (N = 950 )
      COMMON /aa/ A(N,N,N)
      COMMON /bb/ B(N,N,N)
      real*8    sum,sum1

      write (*,*)  ' Required Memory=',8.*N**3/1024.**2,'Mb'
cC$OMP PARALLEL DO DEFAULT(SHARED) 
cC$OMP+PRIVATE (i,j,k)
      Do j=1,N
      Do i=1,N
         Do k=1,N
            A(i,k,j)=0
         EndDo 
      EndDo 
      EndDo 

cC$OMP PARALLEL DO DEFAULT(SHARED) 
cC$OMP+PRIVATE (i,j,k)
      Do j=1,N
      Do i=1,N
         Do k=1,N
            B(i,k,j)=0
         EndDo 
      EndDo 
      EndDo 
      sum = 0.
      Do j=1,N
      Do i=1,N
         Do k=1,N
            A(i,k,j) = ((mod(i,5)+mod(j,5)+mod(k,5))/100.)
            sum =sum + A(i,k,j)**2
         EndDo 
      EndDo 
      EndDo 

      m=3
      CALL SMOOTH(m)
      sum1 = 0.
      Do j=1,N
      Do i=1,N
         Do k=1,N
            sum1 =sum1 + A(i,k,j)**2
         EndDo 
      EndDo 
      EndDo 
      write (*,*)  ' smoothing=',m
      write (*,*)  ' average=',sqrt(sum/N**2)
      write (*,*)  ' average=',sqrt(sum1/N**2)
           stop
           end

c-------------------------------------------------------------------- 
c
      SUBROUTINE SMOOTH(m)
      parameter (N = 950 )
      COMMON /aa/ A(N,N,N)
      COMMON /bb/ B(N,N,N)
      real*8    sum,norm

      norm =(2.*m+1)**3
C$OMP PARALLEL DO DEFAULT(SHARED) 
C$OMP+PRIVATE (i,j,k,sum,i1,j1,k1,ii,jj,kk)
      Do i=1,N,4
         Do j=1,N,4
            Do k=1,N,4
               sum =0.
               Do i1=-m,m,2
               Do j1=-m,m,2
               Do k1=-m,m,2
                 ii = min(max(i+i1,1),N)
                 jj = min(max(j+j1,1),N)
                 kk = min(max(k+k1,1),N)
                 sum = sum+A(ii,jj,kk)
               EndDo 
               EndDo 
               EndDo 
               B(i,j,k) =sum/norm
            EndDo 
         EndDo 
      EndDo 
      Do j=1,N
      Do i=1,N
         Do k=1,N
            A(i,k,j)=B(i,j,k)
         EndDo 
      EndDo 
      EndDo 

      Return
      end


