Matthew Knepley <[email protected]> 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);

Attachment: pgpgwKNIa3bva.pgp
Description: PGP signature

Reply via email to