# VecNorm

Computes the vector norm.

### Synopsis

    #include "petscvec.h"
    PetscErrorCode  VecNorm(Vec x,NormType type,PetscReal *val)

Collective on Vec

### Input Parameters

| x | - the vector
| type | - one of NORM_1, NORM_2, NORM_INFINITY. Also available NORM_1_AND_2, which computes both norms and stores them in a two element array.

### Output Parameter

val -the norm

### C++ variants

| PetscReal VecNorm(Vec x) |  | -> |  | VecNorm(x,NORM_2,&r); return r;
| PetscReal VecNorm(Vec x,NormType t) |  | -> |  | VecNorm(x,t,&r); return r;
| VecNorm(Vec x,PetscReal *r) |  | -> |  | VecNorm(x,NORM_2,r)

### Notes

        NORM_1 denotes sum_i |x_i|

        NORM_2 denotes sqrt(sum_i (x_i)^2)

        NORM_INFINITY denotes max_i |x_i|

### Performance Issues

| per | - processor memory bandwidth
| interprocessor latency | - - work load inbalance that causes certain processes to arrive much earlier than others

### Compile Option

PETSC_HAVE_SLOW_BLAS_NORM2 will cause a C (loop unrolled) version of the norm to be used, rather than the BLAS. This should probably only be used when one is using the FORTRAN BLAS routines (as opposed to vendor provided) because the FORTRAN BLAS NRM2() routine is very slow.

### See Also

VecDot(), VecTDot(), VecNorm(), VecDotBegin(), VecDotEnd(),
VecNormBegin(), VecNormEnd()

Level:intermediate
Location:src/vec/vec/interface/rvector.c
Index of all Vec routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/vec/vec/examples/tutorials/ex1.c.html
src/vec/vec/examples/tutorials/ex1e.c.html
src/vec/vec/examples/tutorials/ex11.c.html
src/vec/vec/examples/tutorials/ex17.c.html
src/vec/vec/examples/tutorials/ex1f.F.html
src/vec/vec/examples/tutorials/ex1f90.F.html
src/vec/vec/examples/tutorials/ex11f.F.html
src/mat/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex1.c.html
src/ksp/ksp/examples/tutorials/ex2.c.html
src/ksp/ksp/examples/tutorials/ex3.c.html