Skip to main content
Ctrl+K
PETSc 3.23.2 documentation - Home
  • Overview
  • Install
  • Tutorials
  • User-Guide
  • C/Fortran API
  • petsc4py API
  • FAQ
  • Community
  • Developers
  • Misc.
  • GitLab
  • Overview
  • Install
  • Tutorials
  • User-Guide
  • C/Fortran API
  • petsc4py API
  • FAQ
  • Community
  • Developers
  • Misc.
  • GitLab
  • VecSetRandom

VecSetRandom#

Sets all components of a vector to random numbers.

Synopsis#

#include "petscvec.h"   
PetscErrorCode VecSetRandom(Vec x, PetscRandom rctx)

Logically Collective

Input Parameters#

  • x - the vector

  • rctx - the random number context, formed by PetscRandomCreate(), or use NULL and it will create one internally.

Output Parameter#

  • x - the vector

Example of Usage#

     PetscRandomCreate(PETSC_COMM_WORLD,&rctx);
     VecSetRandom(x,rctx);
     PetscRandomDestroy(&rctx);

See Also#

Vectors and Parallel Data, Vec, VecSet(), VecSetValues(), PetscRandomCreate(), PetscRandomDestroy()

Level#

intermediate

Location#

src/vec/vec/interface/vector.c

Examples#

src/ksp/ksp/tutorials/ex11f.F90
src/ksp/ksp/tutorials/ex81a.c
src/ksp/ksp/tutorials/ex11.c
src/ksp/ksp/tutorials/ex60.c
src/ksp/ksp/tutorials/ex5f.F90
src/ksp/ksp/tutorials/ex77.c
src/ksp/ksp/tutorials/ex81.c
src/ksp/ksp/tutorials/ex2f.F90
src/ksp/ksp/tutorials/ex46.c
src/ksp/ksp/tutorials/ex10.c

Implementations#

VecSetRandom_Nest() in src/vec/vec/impls/nest/vecnest.c
VecSetRandom_Seq() in src/vec/vec/impls/seq/bvec2.c
VecSetRandom_SeqKokkos() in src/vec/vec/impls/seq/kokkos/veckok.kokkos.cxx
VecSetRandom_SeqViennaCL() in src/vec/vec/impls/seq/seqviennacl/vecviennacl.cxx


Index of all Vec routines
Table of Contents for all manual pages
Index of all manual pages

On this page
  • Synopsis
  • Input Parameters
  • Output Parameter
  • Example of Usage
  • See Also
  • Level
  • Location
  • Examples
  • Implementations
Edit on GitLab
Show Source

© Copyright 1991-2025, UChicago Argonne, LLC and the PETSc Development Team.

Created using Sphinx 7.3.7.

Built with the PyData Sphinx Theme 0.15.1.

Last updated on 2025-05-20T11:59:30-0500 (v3.23.2-35-g165c2d34d1cb).