template<class VEC>
void set_zero_parallel(const std::vector<size_type> &cm, VEC &vec, size_type shift = 0)
{
- Assert(!vec.has_ghost_elements(), ExcInternalError());//ExcGhostsPresent());
+ Assert(!vec.has_ghost_elements(), ExcInternalError());
IndexSet locally_owned = vec.locally_owned_elements();
for (typename std::vector<size_type>::const_iterator it = cm.begin();
it != cm.end(); ++it)
- if (locally_owned.is_element(*it))
- vec(*it) = 0.;
+ {
+ // If shift>0 then we are working on a part of a BlockVector
+ // so vec(i) is actually the global entry i+shift.
+ // We first make sure the line falls into the range of vec,
+ // then check if is part of the local part of the vector, before
+ // finally setting it to 0.
+ if ((*it)<shift)
+ continue;
+ size_type idx = *it - shift;
+ if (idx<vec.size() && locally_owned.is_element(idx))
+ vec(idx) = 0.;
+ }
}
template<typename Number>