Actual source code: gmpre.c

  1: #include <../src/ksp/ksp/impls/gmres/gmresimpl.h>

  3: /*@
  4:   KSPGMRESSetPreAllocateVectors - Causes `KSPGMRES` and `KSPFGMRES` to preallocate all its
  5:   needed work vectors at initial setup rather than the default, which
  6:   is to allocate several at a time when needed.

  8:   Logically Collective

 10:   Input Parameter:
 11: . ksp - iterative context obtained from `KSPCreate()`

 13:   Options Database Key:
 14: . -ksp_gmres_preallocate - Activates `KSPGmresSetPreAllocateVectors()`

 16:   Level: intermediate

 18:   Notes:
 19:   If one knows the number of iterations will be greater than or equal to the `KSPGMRESSetRestart()` size then calling
 20:   this routine can result in faster performance since it minimizes the number of separate memory allocations used
 21:   and can improve the performance of `VecMDot()` and `VecMAXPY()` which may utilize BLAS 2 operations that benefit from
 22:   the larger allocations.

 24:   Using this function with vectors in GPU memory may waste GPU memory if not all the restart directions are used in solving the system,
 25:   that is the solver converges before the number of iterations reaches the restart value.

 27: .seealso: [](ch_ksp), `KSPGMRESSetRestart()`, `KSPGMRESSetOrthogonalization()`, `KSPGMRESGetOrthogonalization()`,
 28:           `VecMDot()`, `VecMAXPY()`
 29: @*/
 30: PetscErrorCode KSPGMRESSetPreAllocateVectors(KSP ksp)
 31: {
 32:   PetscFunctionBegin;
 33:   PetscTryMethod(ksp, "KSPGMRESSetPreAllocateVectors_C", (KSP), (ksp));
 34:   PetscFunctionReturn(PETSC_SUCCESS);
 35: }