← Back to team overview

dolfin team mailing list archive

Re: Strange piece of code in PETScVector

 

On Wed, Jan 12, 2011 at 10:32:24AM +0000, Garth N. Wells wrote:
>
>
> On 12/01/11 10:21, Anders Logg wrote:
> > 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?
> >
>
> It can happen in parallel.

How?

> > 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?
> >
>
> When m = 0, PETSc will do nothing, since m is the number of entries to set.

Shouldn't we then just do

if (m == 0)
  return;

?

> Anyway, the code can be removed because
>
>     VecSetValues
>
> is not collective.  For collective functions (that must be called by
> each process), we need to deal with the m = 0 case, otherwise MPI
> programs will hang.

ok, see you've changed to return already.

--
Anders



>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/ListHelp



References