QMCPACK
aligned_allocator.hpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by:
8 //
9 // File created by: Jeongnim Kim, jeongnim.kim@intel.com, Intel Corp.
10 //////////////////////////////////////////////////////////////////////////////////////
11 // -*- C++ -*-
12 /** @file allocator.hpp
13  */
14 #ifndef QMCPLUSPLUS_ALLOCATOR_H
15 #define QMCPLUSPLUS_ALLOCATOR_H
16 
17 #include <vector>
18 #include <cstdlib>
19 #include "config.h"
20 #include "Mallocator.hpp"
21 
22 #if defined(__INTEL_COMPILER)
23  #define ASSUME_ALIGNED(x) __assume_aligned(x,QMC_SIMD_ALIGNMENT)
24 #elif defined(__GNUC__) && !defined(__ibmxl__)
25  #define ASSUME_ALIGNED(x) (x) = (__typeof__(x)) __builtin_assume_aligned(x,QMC_SIMD_ALIGNMENT)
26 #else
27  #define ASSUME_ALIGNED(x)
28 #endif
29 
30 namespace qmcplusplus
31 {
32 template<class T, size_t ALIGN = QMC_SIMD_ALIGNMENT>
34 template<class T>
35 using aligned_vector = std::vector<T, aligned_allocator<T>>;
36 
37 } // namespace qmcplusplus
38 
39 /** return size in T's of allocated aligned memory
40  */
41 template<typename T, size_t ALIGN = QMC_SIMD_ALIGNMENT>
42 inline size_t getAlignedSize(size_t n)
43 {
44  constexpr size_t ND = ALIGN / sizeof(T);
45  static_assert(ALIGN % sizeof(T) == 0, "getAlignedSize ALIGN must be a multiple of sizeof(T)");
46  return ((n + ND - 1) / ND) * ND;
47 }
48 
49 template<typename T, size_t ALIGN = QMC_SIMD_ALIGNMENT>
50 inline size_t getAlignment()
51 {
52  static_assert(ALIGN % sizeof(T) == 0, "getAlignedSize ALIGN must be a multiple of sizeof(T)");
53  return ALIGN / sizeof(T);
54 }
55 
56 #endif
size_t getAlignedSize(size_t n)
return size in T&#39;s of allocated aligned memory
std::vector< T, aligned_allocator< T > > aligned_vector
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
size_t getAlignment()