<div dir="ltr">Hi all,<div><br></div><div>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.</div><div><br></div><div>XZ<br><br><br>--------------------------------------------------------------------------------------------<br>  Vec             u;<br>  PetscRandom     rand_ctx;     /* random number generator context */<br>  PetscMPIInt     size, rank;<br>  PetscInt        n, dn;<br>  <br><br>  MPI_Comm_rank(PETSC_COMM_WORLD,&rank);//CHKERRQ(ierr);<br>  MPI_Comm_size(PETSC_COMM_WORLD,&size);//CHKERRQ(ierr);<br>  n  = N/size + 1;<br>  dn = n*size - N;<br>  if ( dn>0 && rank<dn ) n -= 1;<br>  printf("--->test in petsc_random_vector(): rank = %d, n = %d\n",rank,n);<br><br><br>  VecCreate(PETSC_COMM_WORLD,&u);<br>  VecSetSizes(u,n,N);<br>  PetscRandomCreate(PETSC_COMM_WORLD, &rand_ctx);<br>#if defined(PETSC_HAVE_DRAND48)<br>  PetscRandomSetType(rand_ctx,PETSCRAND48);<br>#elif defined(PETSC_HAVE_RAND)<br>  PetscRandomSetType(rand_ctx,PETSCRAND);<br>#endif<br>  PetscRandomSetFromOptions(rand_ctx);<br><br><br>  VecSetRandom(u,rand_ctx);<br>  PetscRandomDestroy(&rand_ctx);<br></div></div>