QMCPACK
vmath.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: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 /** @file vmath.h
15  *
16  * Define vectorized math functions.
17  * HAVE_MKL_VML
18  * HAVE_MASSV
19  */
20 #ifndef QMCPLUSPLUS_VECTORIZED_STDMATH_HPP
21 #define QMCPLUSPLUS_VECTORIZED_STDMATH_HPP
22 
23 #include <cmath>
24 #if defined(HAVE_MKL_VML)
25 #include <mkl_vml_functions.h>
26 #elif defined(HAVE_MASSV)
27 #include <massv.h>
28 #endif
29 
30 namespace qmcplusplus
31 {
32 namespace simd
33 {
34 /** mod on an array
35  * out[i]=in[i]-floor(in[i])
36  */
37 template<typename T, typename SIZET>
38 inline void remainder(const T* restrict in, T* restrict out, SIZET n)
39 {
40  for (SIZET i = 0; i < n; ++i)
41  out[i] = in[i] - std::floor(in[i]);
42 }
43 
44 template<typename T, typename SIZET>
45 inline void remainder(T* restrict inout, SIZET n)
46 {
47  for (SIZET i = 0; i < n; ++i)
48  inout[i] -= std::floor(inout[i]);
49 }
50 
51 template<typename T, typename SIZET>
52 inline void sqrt(T* restrict inout, SIZET n)
53 {
54  for (SIZET i = 0; i < n; ++i)
55  inout[i] = std::sqrt(inout[i]);
56 }
57 
58 template<typename T>
59 inline void sqrt(const T* restrict in, T* restrict out, int n)
60 {
61  for (int i = 0; i < n; ++i)
62  out[i] = std::sqrt(in[i]);
63 }
64 template<typename T>
65 inline void inv(const T* restrict in, T* restrict out, int n)
66 {
67  for (int i = 0; i < n; ++i)
68  out[i] = 1.0 / in[i];
69 }
70 
71 #if defined(HAVE_MKL_VML)
72 inline void sqrt(const double* in, double* out, int n) { vdSqrt(n, in, out); }
73 
74 inline void sqrt(const float* in, float* out, int n) { vsSqrt(n, in, out); }
75 
76 inline void inv(const double* in, double* out, int n) { vdInv(n, in, out); }
77 
78 inline void inv(const float* in, float* out, int n) { vsInv(n, in, out); }
79 
80 inline void inv_sqrt(const double* in, double* out, int n) { vdInvSqrt(n, in, out); }
81 
82 inline void inv_sqrt(const float* in, float* out, int n) { vsInvSqrt(n, in, out); }
83 
84 #elif defined(HAVE_MASSV)
85 // restrict is not a C++ keyword
86 inline void sqrt(double* in, double* out, int n) { vsqrt(out, in, &n); }
87 inline void sqrt(float* in, float* out, int n) { vssqrt(out, in, &n); }
88 inline void inv(double* in, double* out, int n) { vrec(out, in, &n); }
89 inline void inv(float* in, float* out, int n) { vsrec(out, in, &n); }
90 inline void inv_sqrt(double* in, double* out, int n) { vrsqrt(out, in, &n); }
91 inline void inv_sqrt(float* in, float* out, int n) { vsrsqrt(out, in, &n); }
92 #endif
93 
94 template<typename T>
95 inline void add(int n, const T* restrict in, T* restrict out)
96 {
97  for (int i = 0; i < n; ++i)
98  out[i] += in[i];
99 }
100 
101 } // namespace simd
102 } // namespace qmcplusplus
103 #endif
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void inv(const T *restrict in, T *restrict out, int n)
Definition: vmath.hpp:65
void add(int n, const T *restrict in, T *restrict out)
Definition: vmath.hpp:95
void remainder(const T *restrict in, T *restrict out, SIZET n)
mod on an array out[i]=in[i]-floor(in[i])
Definition: vmath.hpp:38
void sqrt(const T *restrict in, T *restrict out, int n)
Definition: vmath.hpp:59
void sqrt(T *restrict inout, SIZET n)
Definition: vmath.hpp:52
MakeReturn< UnaryNode< FnFloor, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t floor(const Vector< T1, C1 > &l)