:orphan:
# VecSetOperation
Allows the user to override a particular vector operation. 
## Synopsis
```
#include "petscvec.h"   
PetscErrorCode VecSetOperation(Vec vec, VecOperation op, void (*f)(void))
```
Logically Collective; No Fortran Support


## Input Parameters

- ***vec -*** The vector to modify
- ***op  -*** The name of the operation
- ***f   -*** The function that provides the operation.



## Notes
`f` may be `NULL` to remove the operation from `vec`. Depending on the operation this may be
allowed, however some always expect a valid function. In these cases an error will be raised
when calling the interface routine in question.

See `VecOperation` for an up-to-date list of override-able operations. The operations listed
there have the form `VECOP_<OPERATION>`, where `<OPERATION>` is the suffix (in all capital
letters) of the public interface routine (e.g., `VecView()` -> `VECOP_VIEW`).

Overriding a particular `Vec`'s operation has no affect on any other `Vec`s past, present,
or future. The user should also note that overriding a method is "destructive"; the previous
method is not retained in any way.




## Example Usage
```none
  // some new VecView() implementation, must have the same signature as the function it seeks
  // to replace
  PetscErrorCode UserVecView(Vec x, PetscViewer viewer)
  {
    PetscFunctionBeginUser;
    // ...
    PetscFunctionReturn(PETSC_SUCCESS);
  }

  // Create a VECMPI which has a pre-defined VecView() implementation
  VecCreateMPI(comm, n, N, &x);
  // Calls the VECMPI implementation for VecView()
  VecView(x, viewer);

  VecSetOperation(x, VECOP_VIEW, (void (*)(void))UserVecView);
  // Now calls UserVecView()
  VecView(x, viewer);
```



## See Also
 [](ch_vectors), `Vec`, `VecCreate()`, `MatShellSetOperation()`

## Level
advanced

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


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


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