[petsc-users] Check vector for zeros

Jed Brown jed at jedbrown.org
Thu Jan 3 14:25:19 CST 2019


Florian Lindner via petsc-users <petsc-users at mcs.anl.gov> writes:

> I get a vector from a linear solve and is used a divisor in VecPointwiseDivide. Clearly, I must check for zero entries before doing the division.

Note that VecPointwiseDivide does not divide by values that are
identically zero.

  for (i=0; i<n; i++) {
    if (yy[i] != 0.0) ww[i] = xx[i] / yy[i];
    else ww[i] = 0.0;
  }

This is semantically peculiar, but if it's okay for you, you can use
VecChop to truncate sufficiently small values to zero.

> What is the best way to do so, especially performance wise?
>
> The only way I come up with so far, is to VecCopy, VecAbs and then check for VecMin > eps. The VecCopy kind of scares me for the performance draw back. I haven't found something like a VecAbsMin.
>
> Any better ideas?
>
> Thanks,
> Florian


More information about the petsc-users mailing list