17 #ifndef dealii__aligned_vector_h 18 #define dealii__aligned_vector_h 20 #include <deal.II/base/config.h> 21 #include <deal.II/base/std_cxx11/type_traits.h> 22 #include <deal.II/base/exceptions.h> 23 #include <deal.II/base/memory_consumption.h> 24 #include <deal.II/base/utilities.h> 25 #include <deal.II/base/parallel.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> 41 DEAL_II_NAMESPACE_OPEN
74 typedef std::size_t size_type;
102 #ifdef DEAL_II_WITH_CXX11 120 #ifdef DEAL_II_WITH_CXX11 148 void resize (
const size_type size_in,
149 const T &init = T());
159 void reserve (
const size_type size_alloc);
182 const_reference
back ()
const;
188 template <
typename ForwardIterator>
190 ForwardIterator
end);
200 void fill (
const T &element);
215 size_type
size ()
const;
232 const_reference
operator [] (
const size_type index)
const;
247 const_iterator
begin ()
const;
252 const_iterator
end ()
const;
265 template <
class Archive>
266 void save (Archive &ar,
const unsigned int version)
const;
272 template <
class Archive>
273 void load (Archive &ar,
const unsigned int version);
275 BOOST_SERIALIZATION_SPLIT_MEMBER()
320 template <
typename T>
323 static const std::size_t minimum_parallel_grain_size = 160000/
sizeof(T)+1;
338 const bool copy_source)
340 source_ (source_begin),
341 destination_ (destination),
342 copy_source_ (copy_source)
345 const std::size_t size = source_end - source_begin;
346 if (size < minimum_parallel_grain_size)
347 apply_to_subrange (0, size);
349 apply_parallel (0, size, minimum_parallel_grain_size);
357 const std::size_t
end)
const 366 if (std_cxx11::is_trivial<T>::value ==
true)
367 std::memcpy ((
void *)(destination_+begin), (
void *)(source_+begin),
368 (end-begin)*
sizeof(T));
369 else if (copy_source_ ==
false)
370 for (std::size_t i=begin; i<
end; ++i)
374 new (&destination_[i]) T(source_[i]);
378 for (std::size_t i=begin; i<
end; ++i)
379 new (&destination_[i]) T(source_[i]);
385 const bool copy_source_;
399 template <
typename T,
bool initialize_memory>
402 static const std::size_t minimum_parallel_grain_size = 160000/
sizeof(T)+1;
413 destination_ (destination),
414 trivial_element (false)
422 if (std_cxx11::is_trivial<T>::value ==
true &&
425 const unsigned char zero [
sizeof(T)] = {};
429 if (std::memcmp(zero, (
void *)&element,
sizeof(T)) == 0)
430 trivial_element =
true;
432 if (size < minimum_parallel_grain_size)
433 apply_to_subrange (0, size);
435 apply_parallel (0, size, minimum_parallel_grain_size);
442 const std::size_t
end)
const 448 if (std_cxx11::is_trivial<T>::value ==
true && trivial_element)
449 std::memset ((
void *)(destination_+begin), 0, (end-begin)*
sizeof(T));
451 copy_construct_or_assign(begin, end,
457 mutable T *destination_;
458 bool trivial_element;
461 void copy_construct_or_assign(
const std::size_t
begin,
462 const std::size_t
end,
465 for (std::size_t i=begin; i<
end; ++i)
466 destination_[i] = element_;
470 void copy_construct_or_assign(
const std::size_t begin,
471 const std::size_t end,
474 for (std::size_t i=begin; i<
end; ++i)
475 new (&destination_[i]) T(element_);
536 #ifdef DEAL_II_WITH_CXX11 566 #ifdef DEAL_II_WITH_CXX11 593 const size_type old_size =
size();
594 if (std_cxx11::is_trivial<T>::value ==
false && size_in < old_size)
607 if (std_cxx11::is_trivial<T>::value ==
false && size_in > old_size)
619 const size_type old_size =
size();
620 if (std_cxx11::is_trivial<T>::value ==
false && size_in < old_size)
632 if (size_in > old_size)
645 if (size_alloc > allocated_size)
650 size_type new_size = size_alloc;
651 if (size_alloc < (2 * allocated_size))
652 new_size = 2 * allocated_size;
654 const size_type size_actual_allocate = new_size *
sizeof(T);
663 std::swap (_data, new_data);
675 else if (size_alloc == 0)
688 if (std_cxx11::is_trivial<T>::value ==
false)
709 if (std_cxx11::is_trivial<T>::value ==
false)
719 typename AlignedVector<T>::reference
731 typename AlignedVector<T>::const_reference
742 template <
typename ForwardIterator>
748 const unsigned int old_size =
size();
749 reserve (old_size + (end-begin));
752 if (std_cxx11::is_trivial<T>::value ==
false)
794 typename AlignedVector<T>::size_type
804 typename AlignedVector<T>::size_type
814 typename AlignedVector<T>::reference
825 typename AlignedVector<T>::const_reference
836 typename AlignedVector<T>::iterator
846 typename AlignedVector<T>::iterator
856 typename AlignedVector<T>::const_iterator
866 typename AlignedVector<T>::const_iterator
875 template <
class Archive >
880 size_type vec_size (
size());
883 ar &boost::serialization::make_array(
_data, vec_size);
889 template <
class Archive >
894 size_type vec_size = 0;
900 ar &boost::serialization::make_array(
_data, vec_size);
909 typename AlignedVector<T>::size_type
912 size_type memory =
sizeof(*this);
920 #endif // ifndef DOXYGEN 934 for (
typename AlignedVector<T>::const_iterator lit = lhs.
begin(),
935 rit = rhs.
begin(); lit != lhs.
end(); ++lit, ++rit)
957 DEAL_II_NAMESPACE_CLOSE
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const
virtual void apply_to_subrange(const std::size_t begin, const std::size_t end) const
size_type capacity() const
#define AssertIndexRange(index, range)
size_type memory_consumption() const
void load(Archive &ar, const unsigned int version)
AlignedVector & operator=(const AlignedVector< T > &vec)
void reserve(const size_type size_alloc)
void push_back(const T in_data)
reference operator[](const size_type index)
void save(Archive &ar, const unsigned int version) const
AlignedVectorSet(const std::size_t size, const T &element, T *destination)
bool operator==(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
#define Assert(cond, exc)
void resize(const size_type size_in, const T &init=T())
void posix_memalign(void **memptr, size_t alignment, size_t size)
void insert_back(ForwardIterator begin, ForwardIterator end)
void swap(AlignedVector< T > &vec)
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
void resize_fast(const size_type size)
bool operator!=(const AlignedVector< T > &lhs, const AlignedVector< T > &rhs)
void fill(const T &element)
AlignedVectorMove(T *source_begin, T *source_end, T *destination, const bool copy_source)
static::ExceptionBase & ExcInternalError()