MatSetRandom#
Sets all components of a matrix to random numbers.
Synopsis#
#include "petscmat.h"
PetscErrorCode MatSetRandom(Mat x, PetscRandom rctx)
Logically Collective
Input Parameters#
x - the matrix
rctx - the
PetscRandomobject, formed byPetscRandomCreate(), orNULLand it will create one internally.
Notes#
For sparse matrices that have been preallocated but not been assembled, it randomly selects appropriate locations,
for sparse matrices that already have nonzero locations, it fills the locations with random numbers.
It generates an error if used on unassembled sparse matrices that have not been preallocated.
If values have been inserted with MatSetValues(), call MatAssemblyBegin() and MatAssemblyEnd() before calling this routine.
The matrix is assembled on return.
Example Usage#
PetscRandomCreate(PETSC_COMM_WORLD, &rctx);
MatSetRandom(x, rctx);
PetscRandomDestroy(&rctx);
Developer Notes#
Implementations must leave the matrix assembled with increased object state, assembling it themselves when it is not already the case.
Implementations that insert only local entries can temporarily set MAT_NO_OFF_PROC_ENTRIES to PETSC_TRUE during assembly, restoring its previous value afterwards.
See Also#
Matrices, Mat, PetscRandom, PetscRandomCreate(), MatZeroEntries(), MatSetValues(), PetscRandomDestroy()
Level#
intermediate
Location#
Examples#
src/mat/tutorials/ex9.c
src/mat/tests/ex27.c
src/mat/tests/ex1.c
src/mat/tests/ex102.c
src/mat/tests/ex104.c
src/mat/tests/ex109.c
src/mat/tests/ex122.c
src/mat/tests/ex125.c
src/mat/tests/ex192.c
src/mat/tests/ex195.c
Implementations#
MatSetRandom_MPIAIJ() in src/mat/impls/aij/mpi/mpiaij.c
MatSetRandom_SeqAIJ() in src/mat/impls/aij/seq/aij.c
MatSetRandom_ConstantDiagonal() in src/mat/impls/cdiagonal/cdiagonal.c
MatSetRandom_MPIDense() in src/mat/impls/dense/mpi/mpidense.c
MatSetRandom_SeqDense() in src/mat/impls/dense/seq/dense.c
MatSetRandom_Diagonal() in src/mat/impls/diagonal/diagonal.c
MatSetRandom_Nest() in src/mat/impls/nest/matnest.c
MatSetRandom_MPISELL() in src/mat/impls/sell/mpi/mpisell.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages