Highly Efficient FFT for Exascale: HeFFTe v2.3
heffte_stock_allocator.h
1 #ifndef HEFFTE_STOCK_ALLOCATOR_H
2 #define HEFFTE_STOCK_ALLOCATOR_H
3 
4 #include <memory>
5 #include <vector>
6 
7 #include "heffte_stock_complex.h"
8 
9 namespace heffte {
10 namespace stock{
11 
17 template<typename F>
19  public:
21  typedef F value_type;
22  typedef F* pointer;
23  typedef const F* const_pointer;
24  typedef F& reference;
25  typedef const F& const_reference;
26  typedef size_t size_type;
27  typedef std::ptrdiff_t difference_type;
28 
30  template <class U>
31  struct rebind {
33  };
34 
36  inline pointer address(reference r) { return &r; }
38  inline const_pointer address(const_reference r) const { return &r; }
39 
41  pointer allocate(size_type n, typename std::allocator<void>::const_pointer = nullptr) {
42  #ifdef Heffte_ENABLE_AVX
43  return reinterpret_cast<pointer>(aligned_alloc(alignof(F), n*sizeof(F)));
44  #else
45  return reinterpret_cast<pointer>(malloc(n*sizeof(F)));
46  #endif
47  }
49  inline void deallocate(pointer p, size_type) {
50  free(p);
51  };
52 
54  inline void construct(pointer p, const_reference value) { new (p) value_type(value); }
56  inline void destroy(pointer p) { p->~value_type(); }
57 
59  inline size_type max_size() const noexcept { return size_type(-1) / sizeof(F); }
60 
62  inline bool operator==(const complex_allocator_t&) { return true; }
64  inline bool operator!=(const complex_allocator_t& rhs) { return !operator==(rhs); }
65 };
66 
68 template<typename F, int L>
69 using complex_allocator = complex_allocator_t<Complex<F, L>>;
70 
72 template<typename F, int L>
73 using complex_vector = std::vector<Complex<F,L>, complex_allocator<F,L>>;
74 
75 }
76 }
77 #endif // End HEFFTE_STOCK_ALLOCATOR.H
Allocator to use with heffte::stock::Complex types Class to properly allocate heffte::stock::Complex<...
Definition: heffte_stock_allocator.h:18
void construct(pointer p, const_reference value)
Copy into pointer.
Definition: heffte_stock_allocator.h:54
pointer allocate(size_type n, typename std::allocator< void >::const_pointer=nullptr)
Define allocation for complex type.
Definition: heffte_stock_allocator.h:41
bool operator!=(const complex_allocator_t &rhs)
Define != operator.
Definition: heffte_stock_allocator.h:64
void deallocate(pointer p, size_type)
Define deallocation for complex type.
Definition: heffte_stock_allocator.h:49
size_type max_size() const noexcept
Define maximum size of an array of this.
Definition: heffte_stock_allocator.h:59
void destroy(pointer p)
Destroy a pointer to this type.
Definition: heffte_stock_allocator.h:56
F value_type
Mandatory aliases.
Definition: heffte_stock_allocator.h:21
bool operator==(const complex_allocator_t &)
Define == operator.
Definition: heffte_stock_allocator.h:62
const_pointer address(const_reference r) const
Get address from a const reference.
Definition: heffte_stock_allocator.h:38
pointer address(reference r)
Get address from a reference.
Definition: heffte_stock_allocator.h:36
Namespace containing all HeFFTe methods and classes.
Definition: heffte_backend_cuda.h:38
Defining rebind for the allocator.
Definition: heffte_stock_allocator.h:31