17 #ifndef dealii_aligned_vector_h 18 #define dealii_aligned_vector_h 29 #include <boost/version.hpp> 30 #if BOOST_VERSION >= 106400 31 # include <boost/serialization/array_wrapper.hpp> 33 # include <boost/serialization/array.hpp> 35 #include <boost/serialization/split_member.hpp> 38 #include <type_traits> 208 template <
typename ForwardIterator>
233 fill(
const T &element);
318 template <
class Archive>
320 save(Archive &ar,
const unsigned int version)
const;
326 template <
class Archive>
328 load(Archive &ar,
const unsigned int version);
335 template <
class Archive>
337 serialize(Archive &archive,
const unsigned int version);
341 BOOST_SERIALIZATION_SPLIT_MEMBER()
386 template <
typename T>
390 160000 /
sizeof(
T) + 1;
403 const T *
const source_end,
404 T *
const destination)
405 : source_(source_begin)
406 , destination_(destination)
409 Assert(source_end == source_begin || destination !=
nullptr,
411 const std::size_t size = source_end - source_begin;
412 if (size < minimum_parallel_grain_size)
413 AlignedVectorCopy::apply_to_subrange(0, size);
415 apply_parallel(0, size, minimum_parallel_grain_size);
424 const std::size_t
end)
const override 434 std::memcpy(static_cast<void *>(destination_ + begin),
435 static_cast<const void *>(source_ + begin),
436 (end - begin) *
sizeof(
T));
438 for (std::size_t i = begin; i <
end; ++i)
439 new (&destination_[i])
T(source_[i]);
453 template <
typename T>
457 160000 /
sizeof(
T) + 1;
471 T *
const destination)
472 : source_(source_begin)
473 , destination_(destination)
476 Assert(source_end == source_begin || destination !=
nullptr,
478 const std::size_t size = source_end - source_begin;
479 if (size < minimum_parallel_grain_size)
480 AlignedVectorMove::apply_to_subrange(0, size);
482 apply_parallel(0, size, minimum_parallel_grain_size);
491 const std::size_t
end)
const override 501 std::memcpy(static_cast<void *>(destination_ + begin),
502 static_cast<void *>(source_ + begin),
503 (end - begin) *
sizeof(
T));
505 for (std::size_t i = begin; i <
end; ++i)
509 new (&destination_[i])
T(std::move(source_[i]));
531 template <
typename T,
bool initialize_memory>
535 160000 /
sizeof(
T) + 1;
544 T *
const destination)
546 , destination_(destination)
547 , trivial_element(false)
559 const unsigned char zero[
sizeof(
T)] = {};
563 if (std::memcmp(
zero,
564 static_cast<const void *>(&element),
566 trivial_element =
true;
568 if (size < minimum_parallel_grain_size)
569 AlignedVectorSet::apply_to_subrange(0, size);
571 apply_parallel(0, size, minimum_parallel_grain_size);
579 const std::size_t
end)
const override 586 std::memset(static_cast<void *>(destination_ + begin),
588 (end - begin) *
sizeof(
T));
590 copy_construct_or_assign(
591 begin, end, std::integral_constant<bool, initialize_memory>());
602 const std::size_t
end,
603 std::integral_constant<bool, false>)
const 605 for (std::size_t i = begin; i <
end; ++i)
606 destination_[i] = element_;
612 const std::size_t
end,
613 std::integral_constant<bool, true>)
const 615 for (std::size_t i = begin; i <
end; ++i)
616 new (&destination_[i])
T(element_);
633 template <
typename T,
bool initialize_memory>
637 160000 /
sizeof(
T) + 1;
645 : destination_(destination)
651 if (size < minimum_parallel_grain_size)
652 AlignedVectorDefaultInitialize::apply_to_subrange(0, size);
654 apply_parallel(0, size, minimum_parallel_grain_size);
662 const std::size_t
end)
const override 669 std::memset(static_cast<void *>(destination_ + begin),
671 (end - begin) *
sizeof(
T));
673 default_construct_or_assign(
674 begin, end, std::integral_constant<bool, initialize_memory>());
683 const std::size_t
end,
684 std::integral_constant<bool, false>)
const 686 for (std::size_t i = begin; i <
end; ++i)
687 destination_[i] = std::move(
T());
693 const std::size_t
end,
694 std::integral_constant<bool, true>)
const 696 for (std::size_t i = begin; i <
end; ++i)
697 new (&destination_[i])
T;
743 reserve(vec.data_end - vec.data_begin);
756 vec.data_begin =
nullptr;
757 vec.data_end =
nullptr;
758 vec.allocated_end =
nullptr;
785 vec.data_begin =
nullptr;
786 vec.data_end =
nullptr;
787 vec.allocated_end =
nullptr;
836 if (size_in > old_size)
860 if (size_in > old_size)
874 if (size_alloc > allocated_size)
880 if (size_alloc < (2 * allocated_size))
881 new_size = 2 * allocated_size;
883 const size_type size_actual_allocate = new_size *
sizeof(
T);
890 size_actual_allocate);
907 else if (size_alloc == 0)
970 template <
typename ForwardIterator>
974 const unsigned int old_size =
size();
975 reserve(old_size + (end - begin));
1063 template <
typename T>
1072 template <
typename T>
1118 template <
class Archive>
1125 ar &boost::serialization::make_array(
data_begin, vec_size);
1131 template <
class Archive>
1141 ar &boost::serialization::make_array(
data_begin, vec_size);
1160 #endif // ifndef DOXYGEN 1172 if (lhs.size() != rhs.size())
void default_construct_or_assign(const std::size_t begin, const std::size_t end, std::integral_constant< bool, false >) const
void posix_memalign(void **memptr, std::size_t alignment, std::size_t size)
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const override
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const override
#define AssertIndexRange(index, range)
void load(Archive &ar, const unsigned int version)
AlignedVector & operator=(const AlignedVector< T > &vec)
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const override
void reserve(const size_type size_alloc)
void push_back(const T in_data)
void resize(const size_type size_in)
reference operator[](const size_type index)
void serialize(Archive &archive, const unsigned int version)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
#define Assert(cond, exc)
#define DEAL_II_NAMESPACE_CLOSE
void copy_construct_or_assign(const std::size_t begin, const std::size_t end, std::integral_constant< bool, true >) const
void insert_back(ForwardIterator begin, ForwardIterator end)
const value_type * const_iterator
size_type memory_consumption() const
void copy_construct_or_assign(const std::size_t begin, const std::size_t end, std::integral_constant< bool, false >) const
void default_construct_or_assign(const std::size_t begin, const std::size_t end, std::integral_constant< bool, true >) const
void swap(AlignedVector< T > &vec)
void resize_fast(const size_type size)
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)
void save(Archive &ar, const unsigned int version) const
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const override
AlignedVectorMove(T *const source_begin, T *const source_end, T *const destination)
#define DEAL_II_NAMESPACE_OPEN
AlignedVectorCopy(const T *const source_begin, const T *const source_end, T *const destination)
AlignedVectorSet(const std::size_t size, const T &element, T *const destination)
unsigned int minimum_parallel_grain_size
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
AlignedVectorDefaultInitialize(const std::size_t size, T *const destination)
static const types::blas_int zero
const value_type * const_pointer
const value_type & const_reference
T max(const T &t, const MPI_Comm &mpi_communicator)
size_type capacity() const
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
static ::ExceptionBase & ExcInternalError()