123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- #ifndef BOOST_MPI_ALLOCATOR_HPP
- #define BOOST_MPI_ALLOCATOR_HPP
- #include <boost/mpi/config.hpp>
- #include <boost/mpi/exception.hpp>
- #include <cstddef>
- #include <memory>
- #include <boost/limits.hpp>
- namespace boost { namespace mpi {
- #if defined(BOOST_MPI_HAS_MEMORY_ALLOCATION)
- template<typename T> class allocator;
- template<>
- class BOOST_MPI_DECL allocator<void>
- {
- public:
- typedef void* pointer;
- typedef const void* const_pointer;
- typedef void value_type;
- template <class U>
- struct rebind
- {
- typedef allocator<U> other;
- };
- };
- template<typename T>
- class BOOST_MPI_DECL allocator
- {
- public:
-
- typedef std::size_t size_type;
-
- typedef std::ptrdiff_t difference_type;
-
- typedef T* pointer;
-
- typedef const T* const_pointer;
-
- typedef T& reference;
-
- typedef const T& const_reference;
-
- typedef T value_type;
-
- template <typename U>
- struct rebind
- {
- typedef allocator<U> other;
- };
-
- allocator() throw() { }
-
- allocator(const allocator&) throw() { }
-
- template <typename U>
- allocator(const allocator<U>&) throw() { }
-
- ~allocator() throw() { }
-
- pointer address(reference x) const
- {
- return &x;
- }
-
- const_pointer address(const_reference x) const
- {
- return &x;
- }
-
- pointer allocate(size_type n, allocator<void>::const_pointer = 0)
- {
- pointer result;
- BOOST_MPI_CHECK_RESULT(MPI_Alloc_mem,
- (static_cast<MPI_Aint>(n * sizeof(T)),
- MPI_INFO_NULL,
- &result));
- return result;
- }
-
- void deallocate(pointer p, size_type )
- {
- BOOST_MPI_CHECK_RESULT(MPI_Free_mem, (p));
- }
-
- size_type max_size() const throw()
- {
- return (std::numeric_limits<std::size_t>::max)() / sizeof(T);
- }
-
- void construct(pointer p, const T& val)
- {
- new ((void *)p) T(val);
- }
-
- void destroy(pointer p)
- {
- ((T*)p)->~T();
- }
- };
- template<typename T1, typename T2>
- inline bool operator==(const allocator<T1>&, const allocator<T2>&) throw()
- {
- return true;
- }
- template<typename T1, typename T2>
- inline bool operator!=(const allocator<T1>&, const allocator<T2>&) throw()
- {
- return false;
- }
- #else
- using std::allocator;
- #endif
- } }
- #endif
|