On Thu, May 29, 2014 at 7:27 PM, Jed Brown <[email protected]> wrote:
> 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); > 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
