[petsc-users] random vector
Barry Smith
bsmith at mcs.anl.gov
Mon Jul 9 08:51:18 CDT 2012
Create and destroy the random context OUTSIDE of the loop. Each time you create it it is using the same seed hence giving the same values.
Note that it is also intentional that if you run the code twice you get the same values each time you run it to help write and debug codes. If you want different values each time you run it you need to call PetscRandomSetSeed() then PetscRandomSeed() after creating the context
Barry
On Jul 9, 2012, at 7:53 AM, Benjamin Sanderse wrote:
> Hello all,
>
> I am trying to solve a Poisson equation several times with random right-hand side vectors in order to do parallel scalability tests.
> Here is part of the code that I use to generate a random vector:
>
>
> PetscRandom :: rctx
>
> ...
>
> do I = 1,n
>
>
> call PetscRandomCreate(PETSC_COMM_WORLD,rctx,ierr); CHKERRQ(ierr)
> call VecSetRandom(f,rctx,ierr); CHKERRQ(ierr)
> call PetscRandomDestroy(rctx,ierr); CHKERRQ(ierr)
>
> call VecView(f,PETSC_VIEWER_STDOUT_WORLD,ierr); CHKERRQ(ierr)
>
> call Poisson
>
> end do
>
>
> It appears that f does not change during the execution of the do-loop. In fact its value is even always the same for I=1 when I run the code several times. Apparently I am missing something. Can anybody help?
>
> Regards,
>
>
> Benjamin
More information about the petsc-users
mailing list