46 parallel_object_only();
49 libmesh_assert_equal_to (_values.size(), _local_size);
50 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
55 local_sum += _values[i];
57 this->comm().sum(local_sum);
68 parallel_object_only();
71 libmesh_assert_equal_to (_values.size(), _local_size);
72 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
79 this->comm().sum(local_l1);
90 parallel_object_only();
93 libmesh_assert_equal_to (_values.size(), _local_size);
94 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
101 this->comm().sum(local_l2);
103 return std::sqrt(local_l2);
108 template <
typename T>
112 parallel_object_only();
115 libmesh_assert_equal_to (_values.size(), _local_size);
116 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
118 Real local_linfty = 0.;
121 local_linfty =
std::max(local_linfty,
122 static_cast<Real>(
std::abs(_values[i]))
127 this->comm().max(local_linfty);
134 template <
typename T>
137 libmesh_assert (this->
closed());
139 libmesh_assert_equal_to (_values.size(), _local_size);
140 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
149 template <
typename T>
152 libmesh_assert (this->
closed());
154 libmesh_assert_equal_to (_values.size(), _local_size);
155 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
164 template <
typename T>
167 libmesh_assert_equal_to(size(), v.
size());
171 std::size_t val_size = _values.
size();
173 for (std::size_t i=0; i<val_size; i++)
174 _values[i] = _values[i] / v_vec._values[i];
182 template <
typename T>
188 libmesh_assert_not_equal_to (_values[i], T(0));
190 _values[i] = 1. / _values[i];
197 template <
typename T>
211 template <
typename T>
215 libmesh_assert_equal_to (_values.size(), _local_size);
216 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
224 template <
typename T>
228 libmesh_assert_equal_to (_values.size(), _local_size);
229 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
236 template <
typename T>
240 libmesh_assert_equal_to (_values.size(), _local_size);
241 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
248 template <
typename T>
252 libmesh_assert_equal_to (_values.size(), _local_size);
253 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
255 for (std::size_t i=0; i<local_size(); i++)
256 _values[i] *= factor;
259 template <
typename T>
263 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
273 template <
typename T>
277 parallel_object_only();
284 libmesh_assert_equal_to ( this->last_local_index(), v->
last_local_index() );
289 for (std::size_t i=0; i<this->local_size(); i++)
290 local_dot += this->_values[i] * v->
_values[i];
293 this->comm().sum(local_dot);
300 template <
typename T>
305 libmesh_assert_equal_to (_values.size(), _local_size);
306 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
308 for (std::size_t i=0; i<local_size(); i++)
316 template <
typename T>
330 template <
typename T>
346 libmesh_error_msg(
"v.local_size() = " << v.
local_size() <<
" must be equal to this->local_size() = " << this->local_size());
353 template <
typename T>
358 libmesh_assert_equal_to (_values.size(), _local_size);
359 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
361 if (v.size() == local_size())
364 else if (v.size() == size())
365 for (std::size_t i=first_local_index(); i<last_local_index(); i++)
366 _values[i-first_local_index()] = v[i];
369 libmesh_error_msg(
"Incompatible sizes in DistributedVector::operator=");
376 template <
typename T>
381 libmesh_assert_equal_to (_values.size(), _local_size);
382 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
399 #ifndef LIBMESH_HAVE_MPI 401 libmesh_assert_equal_to (local_size(), size());
408 template <
typename T>
410 const std::vector<numeric_index_type> &)
const 413 libmesh_assert_equal_to (_values.size(), _local_size);
414 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
417 localize (v_local_in);
422 template <
typename T>
424 const std::vector<numeric_index_type> & indices)
const 427 v_local.resize(indices.size());
430 std::vector<numeric_index_type> local_sizes;
431 this->comm().allgather (_local_size, local_sizes);
434 std::vector<numeric_index_type> local_size_sums(this->n_processors());
435 local_size_sums[0] = local_sizes[0];
437 local_size_sums[i] = local_size_sums[i-1] + local_sizes[i];
442 std::map<processor_id_type, std::vector<numeric_index_type>>
443 requested_ids, local_requested_ids;
446 typedef typename std::vector<numeric_index_type>::iterator iter_t;
454 iter_t ub = std::upper_bound(local_size_sums.begin(),
455 local_size_sums.end(),
459 (std::distance(local_size_sums.begin(), ub));
461 requested_ids[on_proc].push_back(indices[i]);
462 local_requested_ids[on_proc].push_back(i);
465 auto gather_functor =
468 std::vector<T> & values)
472 const std::size_t ids_size = ids.size();
473 values.resize(ids_size);
475 for (std::size_t i=0; i != ids_size; i++)
481 values[i] = _values[requested_index - _first_local_index];
485 auto action_functor =
486 [& v_local, & local_requested_ids]
488 const std::vector<dof_id_type> &,
489 const std::vector<T> & values)
492 for (std::size_t i=0, vsize = values.size(); i != vsize; i++)
494 libmesh_assert(local_requested_ids.count(pid));
495 libmesh_assert_less(i, local_requested_ids[pid].size());
499 local_requested_ids[pid][i];
502 v_local[local_requested_index] = values[i];
506 const T * ex =
nullptr;
508 (this->comm(), requested_ids, gather_functor, action_functor, ex);
513 template <
typename T>
516 const std::vector<numeric_index_type> & send_list)
519 libmesh_assert_equal_to (this->size(), this->local_size());
520 libmesh_assert_greater (last_local_idx, first_local_idx);
521 libmesh_assert_less_equal (send_list.size(), this->size());
522 libmesh_assert_less (last_local_idx, this->size());
528 if ((first_local_idx == 0) &&
529 (my_local_size == my_size))
537 parallel_vec.
init (my_size, my_local_size,
true,
PARALLEL);
541 parallel_vec.
_values[i-first_local_idx] = _values[i];
544 parallel_vec.
localize (*
this, send_list);
549 template <
typename T>
553 parallel_object_only();
556 libmesh_assert_equal_to (_values.size(), _local_size);
557 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
559 v_local = this->_values;
561 this->comm().allgather (v_local);
563 #ifndef LIBMESH_HAVE_MPI 564 libmesh_assert_equal_to (local_size(), size());
570 template <
typename T>
575 parallel_object_only();
578 libmesh_assert_equal_to (_values.size(), _local_size);
579 libmesh_assert_equal_to ((_last_local_index - _first_local_index), _local_size);
581 v_local = this->_values;
583 this->comm().gather (pid, v_local);
585 #ifndef LIBMESH_HAVE_MPI 586 libmesh_assert_equal_to (local_size(), size());
592 template <
typename T>
598 libmesh_not_implemented();
virtual T dot(const NumericVector< T > &V) const override
numeric_index_type _last_local_index
virtual void scale(const T factor) override
virtual numeric_index_type last_local_index() const override
virtual numeric_index_type size() const =0
virtual NumericVector< T > & operator-=(const NumericVector< T > &v) override
DistributedVector & operator=(const DistributedVector &)
uint8_t processor_id_type
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
virtual NumericVector< T > & operator/=(const NumericVector< T > &v) override
virtual void add(const numeric_index_type i, const T value) override
virtual Real linfty_norm() const override
numeric_index_type _global_size
long double max(long double a, double b)
virtual numeric_index_type local_size() const override
virtual NumericVector< T > & operator+=(const NumericVector< T > &v) override
virtual void reciprocal() override
virtual Real l1_norm() const override
dof_id_type numeric_index_type
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, RequestContainer &reqs, GatherFunctor &gather_data, ActionFunctor &act_on_data, const datum *example)
virtual numeric_index_type size() const override
virtual void pointwise_mult(const NumericVector< T > &vec1, const NumericVector< T > &vec2) override
virtual void conjugate() override
virtual void localize_to_one(std::vector< T > &v_local, const processor_id_type proc_id=0) const override
numeric_index_type _local_size
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual numeric_index_type first_local_index() const override
virtual void localize(std::vector< T > &v_local) const override
virtual Real l2_norm() const override
virtual void abs() override
virtual void init(const numeric_index_type N, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC) override
virtual T sum() const override
numeric_index_type _first_local_index