#include <deal.II/base/config.h>
+#include <deal.II/base/aligned_vector.h>
#include <deal.II/base/communication_pattern_base.h>
#include <deal.II/base/index_set.h>
#include <deal.II/base/memory_consumption.h>
unsigned int
global_to_local(const types::global_dof_index global_index) const;
- /**
- * A helper function that is used to resize the val array.
- */
- void
- resize_val(const size_type new_allocated_size);
-
#ifdef DEAL_II_WITH_TRILINOS
# ifdef DEAL_II_TRILINOS_WITH_TPETRA
/**
std::shared_ptr<Utilities::MPI::CommunicationPatternBase> comm_pattern;
/**
- * Pointer to the array of local elements of this vector.
+ * Locally stored elements.
*/
- std::unique_ptr<Number[], /*decltype(std::free) * */ void (*)(void *)>
- values;
+ AlignedVector<Number> values;
/**
* For parallel loops with TBB, this member variable stores the affinity
template <typename Number>
inline ReadWriteVector<Number>::ReadWriteVector()
- : Subscriptor()
- , values(nullptr, free)
{
// virtual functions called in constructors and destructors never use the
// override in a derived class
inline ReadWriteVector<Number>::ReadWriteVector(
const ReadWriteVector<Number> &v)
: Subscriptor()
- , values(nullptr, free)
{
this->operator=(v);
}
template <typename Number>
inline ReadWriteVector<Number>::ReadWriteVector(const size_type size)
- : Subscriptor()
- , values(nullptr, free)
{
// 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)
- : Subscriptor()
- , values(nullptr, free)
{
// virtual functions called in constructors and destructors never use the
// override in a derived class
inline typename ReadWriteVector<Number>::iterator
ReadWriteVector<Number>::begin()
{
- return values.get();
+ return values.begin();
}
inline typename ReadWriteVector<Number>::const_iterator
ReadWriteVector<Number>::begin() const
{
- return values.get();
+ return values.begin();
}
inline typename ReadWriteVector<Number>::iterator
ReadWriteVector<Number>::end()
{
- return values.get() + this->locally_owned_size();
+ return values.end();
}
inline typename ReadWriteVector<Number>::const_iterator
ReadWriteVector<Number>::end() const
{
- return values.get() + this->locally_owned_size();
+ return values.end();
}
} // namespace internal
- template <typename Number>
- void
- ReadWriteVector<Number>::resize_val(const size_type new_alloc_size)
- {
- if (new_alloc_size == 0)
- {
- values.reset();
- thread_loop_partitioner =
- std::make_shared<parallel::internal::TBBPartitioner>();
- }
- else
- {
- Number *new_values;
- Utilities::System::posix_memalign(reinterpret_cast<void **>(
- &new_values),
- 64,
- sizeof(Number) * new_alloc_size);
- values.reset(new_values);
-
- if (new_alloc_size >= 4 * dealii::internal::VectorImplementation::
- minimum_parallel_grain_size)
- thread_loop_partitioner =
- std::make_shared<parallel::internal::TBBPartitioner>();
- }
- }
-
-
template <typename Number>
void
ReadWriteVector<Number>::reinit(const size_type size,
const bool omit_zeroing_entries)
{
- // check whether we need to reallocate
- resize_val(size);
-
- stored_elements = complete_index_set(size);
- stored_elements.compress();
-
- // set entries to zero if so requested
- if (omit_zeroing_entries == false)
- this->operator=(Number());
-
- // reset the communication pattern
- source_stored_elements.clear();
- comm_pattern.reset();
+ reinit(complete_index_set(size), omit_zeroing_entries);
}
ReadWriteVector<Number>::reinit(const ReadWriteVector<Number2> &v,
const bool omit_zeroing_entries)
{
- resize_val(v.locally_owned_size());
+ thread_loop_partitioner = v.thread_loop_partitioner;
+ values.resize(v.locally_owned_size());
stored_elements = v.get_stored_elements();
ReadWriteVector<Number>::reinit(const IndexSet &locally_stored_indices,
const bool omit_zeroing_entries)
{
+ thread_loop_partitioner =
+ std::make_shared<parallel::internal::TBBPartitioner>();
stored_elements = locally_stored_indices;
-
- // set vector size and allocate memory
- resize_val(stored_elements.n_elements());
+ values.resize(stored_elements.n_elements());
// initialize to zero
if (omit_zeroing_entries == false)
// trilinos data but only if Number=double. Also update documentation that
// the argument's lifetime needs to be longer then. If we do this, we need
// to think about whether the view should be read/write.
-
- stored_elements = IndexSet(trilinos_vec.trilinos_partitioner());
-
- resize_val(stored_elements.n_elements());
+ reinit(IndexSet(trilinos_vec.trilinos_partitioner()), true);
TrilinosScalar *start_ptr;
int leading_dimension;
&leading_dimension);
AssertThrow(ierr == 0, ExcTrilinosError(ierr));
- std::copy(start_ptr, start_ptr + leading_dimension, values.get());
-
- // reset the communication pattern
- source_stored_elements.clear();
- comm_pattern.reset();
+ std::copy(start_ptr, start_ptr + leading_dimension, values.data());
}
#endif
if (locally_owned_size() > 0)
{
dealii::internal::VectorOperations::Vector_copy<Number, Number> copier(
- in_vector.values.get(), values.get());
+ in_vector.values.data(), values.data());
dealii::internal::VectorOperations::parallel_for(
copier, 0, locally_owned_size(), thread_loop_partitioner);
}
if (locally_owned_size() > 0)
{
dealii::internal::VectorOperations::Vector_copy<Number, Number2> copier(
- in_vector.values.get(), values.get());
+ in_vector.values.data(), values.data());
dealii::internal::VectorOperations::parallel_for(
copier, 0, locally_owned_size(), thread_loop_partitioner);
}
if (this_size > 0)
{
dealii::internal::VectorOperations::Vector_set<Number> setter(
- Number(), values.get());
+ Number(), values.data());
dealii::internal::VectorOperations::parallel_for(
setter, 0, this_size, thread_loop_partitioner);
}
const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
- Assert(size == 0 || values != nullptr,
+ Assert(size == 0 || values.size() > 0,
ExcInternalError("Import failed."));
for (int i = 0; i < size; ++i)
const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
- Assert(size == 0 || values != nullptr,
+ Assert(size == 0 || values.size() > 0,
ExcInternalError("Import failed."));
for (int i = 0; i < size; ++i)
const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
- Assert(size == 0 || values != nullptr,
+ Assert(size == 0 || values.size() > 0,
ExcInternalError("Import failed."));
// To ensure that this code also compiles with complex
const double *new_values = target_vector.Values();
const int size = target_vector.MyLength();
- Assert(size == 0 || values != nullptr,
+ Assert(size == 0 || values.size() > 0,
ExcInternalError("Import failed."));
for (int i = 0; i < size; ++i)
const unsigned int n_elements = stored_elements.n_elements();
if (operation == VectorOperation::insert)
{
- cudaError_t error_code = cudaMemcpy(values.get(),
+ cudaError_t error_code = cudaMemcpy(values.data(),
cuda_vec.get_values(),
n_elements * sizeof(Number),
cudaMemcpyDeviceToHost);