if (this->size() != in_vector.size())
this->reinit(in_vector, true);
- dealii::internal::VectorOperations::Vector_copy<Number, Number> copier(in_vector.val, this->val);
+ dealii::internal::VectorOperations::Vector_copy<Number, Number> copier(in_vector.values.get(), this->values.get());
internal::VectorOperations::parallel_for(copier, 0, this->size(), this->thread_loop_partitioner);
return *this;
if (this->size() != in_vector.size())
ReadWriteVector<Number>::reinit(in_vector, true);
- dealii::internal::VectorOperations::Vector_copy<Number, Number2> copier(in_vector.val, this->val);
+ dealii::internal::VectorOperations::Vector_copy<Number, Number2> copier(in_vector.values.get(), this->values.get());
internal::VectorOperations::parallel_for(copier, 0, this->size(), this->thread_loop_partitioner);
return *this;
Assert(s==static_cast<Number>(0), ExcMessage("Only 0 can be assigned to a vector."));
(void) s;
- internal::VectorOperations::Vector_set<Number> setter(Number(), this->val);
+ internal::VectorOperations::Vector_set<Number> setter(Number(), this->values.get());
internal::VectorOperations::parallel_for(setter, 0, this->size(), this->thread_loop_partitioner);
return *this;
{
AssertIsFinite(factor);
- internal::VectorOperations::Vectorization_multiply_factor<Number> vector_multiply(this->val, factor);
+ internal::VectorOperations::Vectorization_multiply_factor<Number> vector_multiply(this->values.get(), factor);
internal::VectorOperations::parallel_for(vector_multiply, 0, this->size(), this->thread_loop_partitioner);
return *this;
Assert(down_V.size()==this->size(),
ExcMessage("Cannot add two vectors with different numbers of elements"));
- internal::VectorOperations::Vectorization_add_v<Number> vector_add(this->val, down_V.val);
+ internal::VectorOperations::Vectorization_add_v<Number> vector_add(this->values.get(), down_V.values.get());
internal::VectorOperations::parallel_for(vector_add, 0, this->size(), this->thread_loop_partitioner);
return *this;
const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
Assert(down_V.size()==this->size(),
ExcMessage("Cannot subtract two vectors with different numbers of elements"));
- internal::VectorOperations::Vectorization_subtract_v<Number> vector_subtract(this->val, down_V.val);
+ internal::VectorOperations::Vectorization_subtract_v<Number> vector_subtract(this->values.get(), down_V.values.get());
internal::VectorOperations::parallel_for(vector_subtract, 0, this->size(), this->thread_loop_partitioner);
return *this;
ExcMessage("Cannot compute the scalar product "
"of two vectors with different numbers of elements"));
Number sum;
- internal::VectorOperations::Dot<Number, Number> dot(this->val, down_V.val);
+ internal::VectorOperations::Dot<Number, Number> dot(this->values.get(), down_V.values.get());
internal::VectorOperations::parallel_reduce(dot, 0, this->size(), sum, this->thread_loop_partitioner);
return sum;
{
AssertIsFinite(a);
- internal::VectorOperations::Vectorization_add_factor<Number> vector_add(this->val, a);
+ internal::VectorOperations::Vectorization_add_factor<Number> vector_add(this->values.get(), a);
internal::VectorOperations::parallel_for(vector_add, 0, this->size(), this->thread_loop_partitioner);
}
Assert(down_V.size()==this->size(),
ExcMessage("Cannot add two vectors with different numbers of elements"));
- internal::VectorOperations::Vectorization_add_av<Number> vector_add_av(this->val, down_V.val, a);
+ internal::VectorOperations::Vectorization_add_av<Number> vector_add_av(this->values.get(), down_V.values.get(), a);
internal::VectorOperations::parallel_for(vector_add_av, 0, this->size(), this->thread_loop_partitioner);
}
Assert(down_W.size()==this->size(),
ExcMessage("Cannot add two vectors with different numbers of elements"));
- internal::VectorOperations::Vectorization_add_avpbw<Number> vector_add(this->val, down_V.val,
- down_W.val, a, b);
+ internal::VectorOperations::Vectorization_add_avpbw<Number> vector_add(this->values.get(), down_V.values.get(),
+ down_W.values.get(), a, b);
internal::VectorOperations::parallel_for(vector_add, 0, this->size(), this->thread_loop_partitioner);
}
// Downcast V. It fails, throws an exception.
const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
- internal::VectorOperations::Vectorization_sadd_xav<Number> vector_sadd_xav(this->val, down_V.val,
+ internal::VectorOperations::Vectorization_sadd_xav<Number> vector_sadd_xav(this->values.get(), down_V.values.get(),
a, s);
internal::VectorOperations::parallel_for(vector_sadd_xav, 0, this->size(), this->thread_loop_partitioner);
}
Assert(down_scaling_factors.size()==this->size(),
ExcMessage("Cannot add two vectors with different numbers of elements"));
- internal::VectorOperations::Vectorization_scale<Number> vector_scale(this->val, down_scaling_factors.val);
+ internal::VectorOperations::Vectorization_scale<Number> vector_scale(this->values.get(), down_scaling_factors.values.get());
internal::VectorOperations::parallel_for(vector_scale, 0, this->size(), this->thread_loop_partitioner);
}
// Downcast V. If fails, throws an exception.
const Vector<Number> &down_V = dynamic_cast<const Vector<Number>&>(V);
- internal::VectorOperations::Vectorization_equ_au<Number> vector_equ(this->val, down_V.val, a);
+ internal::VectorOperations::Vectorization_equ_au<Number> vector_equ(this->values.get(), down_V.values.get(), a);
internal::VectorOperations::parallel_for(vector_equ, 0, this->size(), this->thread_loop_partitioner);
}
const size_type size = this->size();
for (size_type i=0; i<size; ++i)
- if (this->val[i] != Number())
+ if (this->values[i] != Number())
return false;
return true;
typedef typename VectorSpaceVector<Number>::real_type real_type;
value_type sum;
- internal::VectorOperations::MeanValue<Number> mean_value(this->val);
+ internal::VectorOperations::MeanValue<Number> mean_value(this->values.get());
internal::VectorOperations::parallel_reduce(mean_value, 0, this->size(), sum, this->thread_loop_partitioner);
return sum/static_cast<real_type>(this->size());
typedef typename VectorSpaceVector<Number>::real_type real_type;
real_type sum;
- internal::VectorOperations::Norm1<Number, real_type> norm1(this->val);
+ internal::VectorOperations::Norm1<Number, real_type> norm1(this->values.get());
internal::VectorOperations::parallel_reduce(norm1, 0, this->size(), sum, this->thread_loop_partitioner);
return sum;
// precision) using the BLAS approach with a weight, see e.g. dnrm2.f.
typedef typename VectorSpaceVector<Number>::real_type real_type;
real_type norm_square;
- internal::VectorOperations::Norm2<Number, real_type> norm2(this->val);
+ internal::VectorOperations::Norm2<Number, real_type> norm2(this->values.get());
internal::VectorOperations::parallel_reduce(norm2, 0, this->size(), norm_square,
this->thread_loop_partitioner);
if (numbers::is_finite(norm_square) &&
const size_type size = this->size();
for (size_type i=0; i<size; ++i)
{
- if (this->val[i] != Number())
+ if (this->values[i] != Number())
{
const real_type abs_x =
- numbers::NumberTraits<Number>::abs(this->val[i]);
+ numbers::NumberTraits<Number>::abs(this->values[i]);
if (scale < abs_x)
{
sum = 1. + sum * (scale/abs_x) * (scale/abs_x);
typename ReadWriteVector<Number>::real_type norm = 0.;
const size_type size = this->size();
for (size_type i=0; i<size; ++i)
- norm = std::max(std::abs(this->val[i]),norm);
+ norm = std::max(std::abs(this->values[i]),norm);
return norm;
}
ExcMessage("Cannot add two vectors with different numbers of elements"));
Number sum;
- internal::VectorOperations::AddAndDot<Number> adder(this->val, down_V.val, down_W.val, a);
+ internal::VectorOperations::AddAndDot<Number> adder(this->values.get(), down_V.values.get(), down_W.values.get(), a);
internal::VectorOperations::parallel_reduce(adder, 0, this->size(), sum, this->thread_loop_partitioner);
AssertIsFinite(sum);
/**
* Destructor.
*/
- ~ReadWriteVector ();
+ ~ReadWriteVector () = default;
/**
* Set the global size of the vector to @p size. The stored elements have
/**
* Pointer to the array of local elements of this vector.
*/
- Number *val;
+ std::unique_ptr<Number[]> values;
/**
* For parallel loops with TBB, this member variable stores the affinity
template <typename Number>
inline
ReadWriteVector<Number>::ReadWriteVector ()
- :
- val(nullptr)
{
// virtual functions called in constructors and destructors never use the
// override in a derived class
inline
ReadWriteVector<Number>::ReadWriteVector (const ReadWriteVector<Number> &v)
:
- Subscriptor(),
- val(nullptr)
+ Subscriptor()
{
this->operator=(v);
}
template <typename Number>
inline
ReadWriteVector<Number>::ReadWriteVector (const size_type size)
- :
- val(nullptr)
{
// virtual functions called in constructors and destructors never use the
// override in a derived class
template <typename Number>
inline
ReadWriteVector<Number>::ReadWriteVector (const IndexSet &locally_stored_indices)
- :
- val(nullptr)
{
// virtual functions called in constructors and destructors never use the
// override in a derived class
- template <typename Number>
- inline
- ReadWriteVector<Number>::~ReadWriteVector ()
- {
- try
- {
- resize_val(0);
- }
- catch (...)
- {}
- }
-
-
-
template <typename Number>
inline
typename ReadWriteVector<Number>::size_type
typename ReadWriteVector<Number>::iterator
ReadWriteVector<Number>::begin ()
{
- return val;
+ return values.get();
}
typename ReadWriteVector<Number>::const_iterator
ReadWriteVector<Number>::begin () const
{
- return val;
+ return values.get();
}
typename ReadWriteVector<Number>::iterator
ReadWriteVector<Number>::end ()
{
- return val + this->n_elements();
+ return values.get() + this->n_elements();
}
typename ReadWriteVector<Number>::const_iterator
ReadWriteVector<Number>::end () const
{
- return val + this->n_elements();
+ return values.get() + this->n_elements();
}
Number
ReadWriteVector<Number>::operator() (const size_type global_index) const
{
- return val[global_to_local(global_index)];
+ return values[global_to_local(global_index)];
}
Number &
ReadWriteVector<Number>::operator() (const size_type global_index)
{
- return val[global_to_local (global_index)];
+ return values[global_to_local (global_index)];
}
template <typename Number2>
inline
void ReadWriteVector<Number>::extract_subvector_to (const std::vector<size_type> &indices,
- std::vector<Number2> &values) const
+ std::vector<Number2> &extracted_values) const
{
for (size_type i = 0; i < indices.size(); ++i)
- values[i] = operator()(indices[i]);
+ extracted_values[i] = operator()(indices[i]);
}
{
AssertIndexRange (local_index, this->n_elements());
- return val[local_index];
+ return values[local_index];
}
{
AssertIndexRange (local_index, this->n_elements());
- return val[local_index];
+ return values[local_index];
}
void
ReadWriteVector<Number>::add (const size_type n_indices,
const size_type *indices,
- const Number2 *values)
+ const Number2 *values_to_add)
{
for (size_type i=0; i<n_indices; ++i)
{
Assert (numbers::is_finite(values[i]),
ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- this->operator()(indices[i]) += values[i];
+ this->operator()(indices[i]) += values_to_add[i];
}
}
const size_type end)
{
for (size_type i=begin; i<end; ++i)
- functor(parent.val[i]);
+ functor(parent.values[i]);
}
#endif // ifndef DOXYGEN
{
if (new_alloc_size == 0)
{
- if (val != nullptr)
- free(val);
- val = nullptr;
+ values.reset ();
thread_loop_partitioner = std::make_shared<parallel::internal::TBBPartitioner>();
}
else
{
- if (val != nullptr)
- free(val);
+ Number *new_values;
+ Utilities::System::posix_memalign ((void **)&new_values, 64, sizeof(Number)*new_alloc_size);
+ values.reset (new_values);
- Utilities::System::posix_memalign ((void **)&val, 64, sizeof(Number)*new_alloc_size);
if (new_alloc_size >= 4*dealii::internal::VectorImplementation::minimum_parallel_grain_size)
thread_loop_partitioner = std::make_shared<parallel::internal::TBBPartitioner>();
}
int ierr = trilinos_vec.trilinos_vector().ExtractView (&start_ptr, &leading_dimension);
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
- std::copy(start_ptr, start_ptr + leading_dimension, val);
+ std::copy(start_ptr, start_ptr + leading_dimension, values.get());
// reset the communication pattern
source_stored_elements.clear();
if (n_elements() != in_vector.n_elements())
reinit(in_vector, true);
- dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(in_vector.val, val);
+ dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(in_vector.values.get(), values.get());
dealii::internal::VectorOperations::parallel_for(copier, 0, n_elements(), thread_loop_partitioner);
return *this;
if (n_elements() != in_vector.n_elements())
reinit(in_vector, true);
- dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(in_vector.val, val);
+ dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(in_vector.values.get(), values.get());
dealii::internal::VectorOperations::parallel_for(copier, 0, n_elements(), thread_loop_partitioner);
return *this;
const size_type this_size = n_elements();
if (this_size>0)
{
- dealii::internal::VectorOperations::Vector_set<Number> setter(Number(), val);
+ dealii::internal::VectorOperations::Vector_set<Number> setter(Number(), values.get());
dealii::internal::VectorOperations::parallel_for(setter, 0, this_size, thread_loop_partitioner);
}
AssertThrow(err == 0, ExcMessage("Epetra Import() failed with error code: "
+ Utilities::to_string(err)));
- const double *values = target_vector.Values();
+ const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
Assert(size==0 || values != nullptr, ExcInternalError("Import failed."));
for (int i=0; i<size; ++i)
- val[i] = values[i];
+ values[i] = new_values[i];
}
else if (operation==VectorOperation::add)
{
AssertThrow(err == 0, ExcMessage("Epetra Import() failed with error code: "
+ Utilities::to_string(err)));
- const double *values = target_vector.Values();
+ const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
Assert(size==0 || values != nullptr, ExcInternalError("Import failed."));
for (int i=0; i<size; ++i)
- val[i] += values[i];
+ values[i] += new_values[i];
}
else
AssertThrow(false, ExcNotImplemented());
const unsigned int n_elements = stored_elements.n_elements();
if (operation == VectorOperation::insert)
{
- cudaError_t error_code = cudaMemcpy(val, cuda_vec.get_values(),
+ cudaError_t error_code = cudaMemcpy(values.get(), cuda_vec.get_values(),
n_elements*sizeof(Number),
cudaMemcpyDeviceToHost);
AssertCuda(error_code);
// Add the two vectors
for (unsigned int i=0; i<n_elements; ++i)
- val[i] += tmp[i];
+ values[i] += tmp[i];
}
}
#endif
ReadWriteVector<Number>::swap (ReadWriteVector<Number> &v)
{
std::swap(stored_elements, v.stored_elements);
- std::swap(val, v.val);
+ std::swap(values, v.values);
}
out << std::endl;
unsigned int i=0;
for (const auto &idx : this->stored_elements)
- out << "[" << idx << "]: " << val[i++] << '\n';
+ out << "[" << idx << "]: " << values[i++] << '\n';
out << std::flush;
AssertThrow (out, ExcIO());