PetscRandomCreate#

Creates an object for generating random numbers, and initializes the random-number generator.

Synopsis#

#include "petscsys.h" 
PetscErrorCode PetscRandomCreate(MPI_Comm comm, PetscRandom *r)

Collective

Input Parameter#

  • comm - MPI communicator

Output Parameter#

  • r - the random number generator object

Notes#

The random type has to be set by PetscRandomSetType().

This is only a primitive “parallel” random number generator, it should NOT be used for sophisticated parallel Monte Carlo methods since it will very likely not have the correct statistics across processors. You can provide your own parallel generator using PetscRandomRegister();

If you create a PetscRandom() using PETSC_COMM_SELF on several processors then the SAME random numbers will be generated on all those processors. Use PETSC_COMM_WORLD or the appropriate parallel communicator to eliminate this issue.

Use VecSetRandom() to set the elements of a vector to random numbers.

Example of Usage#

See Also#

PetscRandomSetType(), PetscRandomGetValue(), PetscRandomGetValueReal(), PetscRandomSetInterval(), PetscRandomDestroy(), VecSetRandom(), PetscRandomType, PetscRandom

Level#

intermediate

Location#

src/sys/classes/random/interface/randomc.c

Examples#

src/tao/unconstrained/tutorials/minsurf2.c
src/tao/tutorials/ex4.c
src/dm/field/tutorials/ex1.c
src/vec/vec/tutorials/ex19.c
src/tao/bound/tutorials/plate2.c
src/vec/vec/tutorials/performance.c
src/tao/bound/tutorials/plate2f.F90
src/dm/tutorials/swarm_ex3.c
src/tao/unconstrained/tutorials/spectraladjointassimilation.c
src/vec/vec/utils/tagger/tutorials/ex1.c

Implementations#

PetscRandomCreate_CURAND() in src/sys/classes/random/impls/curand/curand.c
PetscRandomCreate_Rand() in src/sys/classes/random/impls/rand/rand.c
PetscRandomCreate_Rand48() in src/sys/classes/random/impls/rand48/rand48.c
PetscRandomCreate_Rander48() in src/sys/classes/random/impls/rander48/rander48.c
PetscRandomCreate_Random123() in src/sys/classes/random/impls/random123/random123.c
PetscRandomCreate_Sprng() in src/sys/classes/random/impls/sprng/sprng.c


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