← Back to team overview

dolfin team mailing list archive

Strange piece of code in PETScVector

 

I was browsing through PETScVector.cpp and found this very strange
piece of code:

void PETScVector::set(const double* block, uint m, const uint* rows)
{
  assert(x);
  int _m =  static_cast<int>(m);
  const int* _rows = reinterpret_cast<const int*>(rows);
  if (m == 0)
  {
    _rows = &_m;
    double tmp = 0.0;
    block = &tmp;
  }
  VecSetValues(*x, _m, _rows, block, INSERT_VALUES);
}

What's the deal with the m == 0 special case?

I would think that it would be natural to have

  assert(m > 0);

in place of that code.

What happens now when m = 0 is that the first row of the vector is set
to 0.0 (and the rows argument is ignored). Why should m = 0 be allowed
and why should element 0 be set to 0.0?

--
Anders



Follow ups