c-------------------------------------------------------------------- 
c                 Test OMP parallelization
c-------------------------------------------------------------------- 
      parameter (N = 500 )
      parameter (NN= N**3)
      COMMON /aa/ A(NN)
      real*8    sum,sum1

      write (*,*)  ' Required Memory=',4.*N**3/1024.**2,'Mb'
      w =NN
C$OMP PARALLEL DO DEFAULT(SHARED) 
C$OMP+PRIVATE (i)
      Do i=1,NN
            A(i)=i/5.
      EndDo 

      sum = 0.
      Do i=1,NN
            sum =sum + A(i)**2
      EndDo 

      m=1e4
      CALL SMOOTH(m)
      sum1 = 0.
      Do i=1,NN
            sum1 =sum1 + A(i)**2
      EndDo 
      write (*,*)  ' smoothing=',m
      write (*,*)  ' average=',sqrt(sum/NN)
      write (*,*)  ' average=',sqrt(sum1/NN)
      write (*,*) 'Test: serial mode'
           stop
           end

c-------------------------------------------------------------------- 
c
      SUBROUTINE SMOOTH(m)
      parameter (N = 500 )
      parameter (NN= N**3)
      COMMON /aa/ A(NN)
      real*8    sum,norm

      istep = 1 ! max((2.*m+1)/100.,1.)+1
      norm =(2.*m+1)/istep
      write (*,*)  ' istep =',istep,m
      write (*,*)  ' steps=',norm
      Ns =5e7
      Ne =Ns+4e6
      Ne =min(Ne,NN)
      write (*,*)  ' Start,End=',Ns,Ne
C$OMP PARALLEL DO DEFAULT(SHARED) 
C$OMP+PRIVATE (i,sum,i1,ii,j,ic,cpucost)
      Do i=Ns,Ne
         if(mod(i-Ns,100).eq.0) write (*,*)  ' i=',i

               sum =0.
               Do i1=-m,m,10
                 ii = max(min(max(i+i1,1),N),1)

		do ic =1,100000
			cpucost =log10(float(ic))**2
		enddo
                 sum = sum +A(ii)*cpucost
               EndDo 


		A(i) =sum/norm








      EndDo 

      Return
      end


