Vc  1.4.2
SIMD Vector Classes for C++
Finite Differences

Finite difference method example

We calculate central differences for a given function and compare it to the analytical solution.

#include <Vc/Vc>
#include <iostream>
#include <iomanip>
#include <cmath>
#include "../tsc.h"
static constexpr std::size_t N = 10240000, PrintStep = 1000000;
static constexpr float epsilon = 1e-7f;
static constexpr float lower = 0.f;
static constexpr float upper = 40000.f;
static constexpr float h = (upper - lower) / N;
// dfu is the derivative of fu. This is really easy for sine and cosine:
static inline float fu(float x) { return ( std::sin(x) ); }
static inline float dfu(float x) { return ( std::cos(x) ); }
static inline Vc::float_v fu(Vc::float_v::AsArg x) {
#ifdef USE_SCALAR_SINCOS
for (size_t i = 0; i < Vc::float_v::Size; ++i) {
r[i] = std::sin(x[i]);
}
return r;
#else
return Vc::sin(x);
#endif
}
static inline Vc::float_v dfu(Vc::float_v::AsArg x) {
#ifdef USE_SCALAR_SINCOS
for (size_t i = 0; i < Vc::float_v::Size; ++i) {
r[i] = std::cos(x[i]);
}
return r;
#else
return Vc::cos(x);
#endif
}
Vc::free(dy_points - float_v::Size + 1);
return 0;
}
Vc::free
void free(T *p)
Frees memory that was allocated with Vc::malloc.
Definition: malloc.h:163
Vc::cos
fixed_size_simd< T, N > cos(const SimdArray< T, N, V, M > &x)
Applies the std:: cos function component-wise and concurrently.
Definition: simdarray.h:1812
Vc::Vector
Definition: fwddecl.h:53
Vc::float_v
Vector< float > float_v
vector of single precision
Definition: vector.h:54
Vc::Vector::Size
static constexpr size_t Size
Returns the number of scalar components ( ) in a vector of this type.
Definition: vector.h:771
Vc::sin
fixed_size_simd< T, N > sin(const SimdArray< T, N, V, M > &x)
Applies the std:: sin function component-wise and concurrently.
Definition: simdarray.h:1845