[petsc-users] prefix (i.e. cumulative) sum
Barry Smith
bsmith at mcs.anl.gov
Tue Feb 14 21:24:25 CST 2017
Ahh yes, a million times better (for appropriately sized P).
Thanks
> On Feb 14, 2017, at 9:18 PM, Jed Brown <jed at jedbrown.org> wrote:
>
> Barry Smith <bsmith at mcs.anl.gov> writes:
>
>> Here you go. In 20+ years of PETSc no one has needed this before.
>
> This is disgusting O(P) critical path. Do it in O(log P):
>
> int mysum=0,mystart;
> for (i=0; i<nlocal; i++) {
> mysum += xx[i];
> }
> MPI_Scan(&mysum,&mystart,1,MPI_INT,MPI_SUM,comm);
> mystart -= mysum;
> xx[0] += mystart;
> for (i=1; i<nlocal; i++) {
> xx[i] += xx[i-1];
> }
More information about the petsc-users
mailing list