# VecMax
Determines the vector component with maximum real part and its location. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecMax(Vec x, PetscInt *p, PetscReal *val)
```
Collective


## Input Parameter

- ***x -*** the vector



## Output Parameters

- ***p -*** the location of val (pass `NULL` if you don't want this)
- ***val -*** the maximum component





## Notes
Returns the value `PETSC_MIN_REAL` and negative p if the vector is of length 0.

Returns the smallest index with the maximum value


## See Also
 [](chapter_vectors), `Vec`, `VecNorm()`, `VecMin()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/interface/rvector.c.html#VecMax">src/vec/vec/interface/rvector.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex1.c.html">src/vec/vec/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex15.c.html">src/dm/tutorials/ex15.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex72.c.html">src/ksp/ksp/tutorials/ex72.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex17.c.html">src/ts/tutorials/ex17.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex9.c.html">src/ts/tutorials/ex9.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/kokkos/mpikok.kokkos.cxx.html#VecMax_MPIKokkos">VecMax_MPIKokkos in src/vec/vec/impls/mpi/kokkos/mpikok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/mpicuda/mpicuda.cu.html#VecMax_MPICUDA">VecMax_MPICUDA in src/vec/vec/impls/mpi/mpicuda/mpicuda.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/mpihip/mpihip.hip.c.html#VecMax_MPIHIP">VecMax_MPIHIP in src/vec/vec/impls/mpi/mpihip/mpihip.hip.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/mpi/pvec2.c.html#VecMax_MPI">VecMax_MPI in src/vec/vec/impls/mpi/pvec2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/nest/vecnest.c.html#VecMax_Nest">VecMax_Nest in src/vec/vec/impls/nest/vecnest.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/dvec2.c.html#VecMax_Seq">VecMax_Seq in src/vec/vec/impls/seq/dvec2.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx.html#VecMax_SeqKokkos">VecMax_SeqKokkos in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/seqcuda/veccuda2.cu.html#VecMax_SeqCUDA">VecMax_SeqCUDA in src/vec/vec/impls/seq/seqcuda/veccuda2.cu</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/impls/seq/seqhip/vechip2.hip.c.html#VecMax_SeqHIP">VecMax_SeqHIP in src/vec/vec/impls/seq/seqhip/vechip2.hip.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/vec/interface/rvector.c)


[Index of all Vec routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
