static char help[] = "Tests PetscRandom functions.\n\n"; #include /* Usage: mpiexec -n ./ex1 -n -random_type -log_view -view_randomvalues -random_view ascii -random_view :filename */ int main(int argc,char **argv) { PetscInt i,n = 1000,*values; PetscRandom rnd; PetscScalar value,avg = 0.0; PetscMPIInt rank; PetscInt view_rank=-1; #if defined(PETSC_USE_LOG) PetscLogEvent event; #endif PetscCall(PetscInitialize(&argc,&argv,(char*)0,help)); PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD,&rank)); PetscCall(PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL)); PetscCall(PetscOptionsGetInt(NULL,NULL,"-view_randomvalues",&view_rank,NULL)); PetscCall(PetscRandomCreate(PETSC_COMM_WORLD,&rnd)); /* force imaginary part of random number to always be zero; thus obtain reproducible results with real and complex numbers */ PetscCall(PetscRandomSetInterval(rnd,0.0,1.0)); PetscCall(PetscRandomSetFromOptions(rnd)); PetscCall(PetscMalloc1(n,&values)); for (i=0; i= values[i-1],PETSC_COMM_SELF,PETSC_ERR_PLIB,"Values not sorted"); } PetscCall(PetscFree(values)); PetscCall(PetscRandomDestroy(&rnd)); PetscCall(PetscFinalize()); return 0; } /*TEST test: test: suffix: 2 nsize: 2 output_file: output/ex1_1.out test: suffix: 3 args: -view_randomvalues 0 TEST*/