[petsc-users] question about arbitrary eigenvector selection in SLEPC
Matthew Knepley
knepley at gmail.com
Fri May 30 06:35:30 CDT 2014
On Thu, May 29, 2014 at 7:27 PM, Jed Brown <jed at jedbrown.org> wrote:
> 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);
>
I think its better to use the non-collective version:
VecGetOwnershipRange(xr, &low, &high);
if ((myindex >= low) && (myindex < high)) {
VecGetArrayRead(xr,&a);
val = a[myindex-low];
VecRestoreArrayRead(xr, &a);
}
MPI_Allreduce(&val, &gval, 1, MPIU_SCALAR, MPI_SUM, PETSC_COMM_WORLD);
Thanks
Matt
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140530/f9052a94/attachment.html>
More information about the petsc-users
mailing list