[petsc-users] question about arbitrary eigenvector selection in SLEPC

Jed Brown jed at jedbrown.org
Thu May 29 19:27:28 CDT 2014


Matthew Knepley <knepley at gmail.com> writes:
> There might be an easier way to do this:
>   PetscScalar val = 0.0, gval;
>
>   VecGetOwnershipRange(xr, &low, &high);
>   if ((myindex >= low) && (myindex < high)) {
>     VecGetArray(localx1,&a);
>     val = a[myindex-low];
>     VecRestoreArray(localx1, &a);
>   }
>   MPI_Allreduce(&val, &gval, 1, MPIU_SCALAR, MPI_SUM, PETSC_COMM_WORLD);
>
> Now everyone has the value at myindex.

Yes, but VecGetArray is collective so please don't do it quite this way.
Instead, write

  VecGetArray(localx1,&a);
  if ((myindex >= low) && (myindex < high)) {
    val = a[myindex-low];
  }
  VecRestoreArray(localx1, &a);
  MPI_Allreduce(&val, &gval, 1, MPIU_SCALAR, MPI_SUM, PETSC_COMM_WORLD);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140530/695f81d7/attachment.pgp>


More information about the petsc-users mailing list