c---------------------------------------------------------------------
c Расчет нормы
c---------------------------------------------------------------------
      subroutine norm2u3(r,n1,n2,n3,rnm2,rnmu,nx,ny,nz)
c---------------------------------------------------------------------
!DVM$ INHERIT r
c---------------------------------------------------------------------

c---------------------------------------------------------------------
c     norm2u3 evaluates approximations to the L2 norm and the
c     uniform (or L-infinity or Chebyshev) norm, under the
c     assumption that the boundaries are periodic or zero.  Add the
c     boundaries in with half weight (quarter weight on the edges
c     and eighth weight at the corners) for inhomogeneous boundaries.
c---------------------------------------------------------------------
      implicit none

      integer n1, n2, n3, nx, ny, nz
      double precision rnm2, rnmu, r(n1,n2,n3)
      double precision s, a
      integer i3, i2, i1

      double precision dn

      integer T_norm2
      parameter (T_norm2=9)

      dn = 1.0d0*nx*ny*nz
      s=0.0D0
      rnmu = 0.0D0


!DVM$ REGION
!DVM$ PARALLEL (i3,i2,i1) ON r(i1,i2,i3),  
!DVM$& REDUCTION(SUM(s), MAX(rnmu)), PRIVATE(a)  
!DVM$& ,cuda_block(32,4,1)
      do  i3=2,n3-1
         do  i2=2,n2-1
            do  i1=2,n1-1
               s=s+r(i1,i2,i3)**2
               a=abs(r(i1,i2,i3))
               rnmu=dmax1(rnmu,a)
            enddo
         enddo
      enddo     
!DVM$ END REGION
!!DVM$ END INTERVAL
      rnm2=sqrt( s / dn )    
      
      return
      end