On Thu, 29 May 2014, Matthew Knepley wrote:
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.
brilliant, why didn't I think of this? Only, I guess you were
copying/pasting and some variable names slipped, namely localx instead of
xr. Should it be
PetscScalar val = 0.0, gval;
PetscScalar *a;
VecGetOwnershipRange(xr, &low, &high);
if ((myindex >= low) && (myindex < high)) {
VecGetArray(xr,&a);
val = a[myindex-low];
VecRestoreArray(xr, &a);
}
MPI_Allreduce(&val, &gval, 1, MPIU_SCALAR, MPI_SUM, PETSC_COMM_WORLD);
*rr = gval*gval;
*ri = 0;
?
Thanks!
Giacomo
--
_________________________________________________________________
Giacomo Mulas <[email protected]>
_________________________________________________________________
INAF - Osservatorio Astronomico di Cagliari
via della scienza 5 - 09047 Selargius (CA)
tel. +39 070 71180244
mob. : +39 329 6603810
_________________________________________________________________
"When the storms are raging around you, stay right where you are"
(Freddy Mercury)
_________________________________________________________________