Hi all,
I want PETSc to generate random vector using VecSetRandom() following given
examples, but failed and showed some "out of memory" error. The following
is the code, which goes well until it reaches VecSetRandom(). Can anyone
help me figure out the reason? Thanks a lot.
XZ
--------------------------------------------------------------------------------------------
Vec u;
PetscRandom rand_ctx; /* random number generator context */
PetscMPIInt size, rank;
PetscInt n, dn;
MPI_Comm_rank(PETSC_COMM_WORLD,&rank);//CHKERRQ(ierr);
MPI_Comm_size(PETSC_COMM_WORLD,&size);//CHKERRQ(ierr);
n = N/size + 1;
dn = n*size - N;
if ( dn>0 && rank<dn ) n -= 1;
printf("--->test in petsc_random_vector(): rank = %d, n = %d\n",rank,n);
VecCreate(PETSC_COMM_WORLD,&u);
VecSetSizes(u,n,N);
PetscRandomCreate(PETSC_COMM_WORLD, &rand_ctx);
#if defined(PETSC_HAVE_DRAND48)
PetscRandomSetType(rand_ctx,PETSCRAND48);
#elif defined(PETSC_HAVE_RAND)
PetscRandomSetType(rand_ctx,PETSCRAND);
#endif
PetscRandomSetFromOptions(rand_ctx);
VecSetRandom(u,rand_ctx);
PetscRandomDestroy(&rand_ctx);