[petsc-users] prefix (i.e. cumulative) sum

Jed Brown jed at jedbrown.org
Tue Feb 14 21:18:42 CST 2017


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];
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20170214/f827a92b/attachment.pgp>


More information about the petsc-users mailing list