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;
static inline float fu(float x) { return ( std::sin(x) ); }
static inline float dfu(float x) { return ( std::cos(x) ); }
#ifdef USE_SCALAR_SINCOS
r[i] = std::sin(x[i]);
}
return r;
#else
#endif
}
#ifdef USE_SCALAR_SINCOS
r[i] = std::cos(x[i]);
}
return r;
#else
#endif
}
Vc::free(dy_points - float_v::Size + 1);
return 0;
}
MemoryVectorIterator< V, Flags > end(Flags flags=Flags())
Return a (vectorized) iterator to the end of this memory object.
MemoryVectorIterator< V, Flags > begin(Flags flags=Flags())
Return a (vectorized) iterator to the start of this memory object.
vector_reference< Flags > lastVector(Flags f=Flags())
static constexpr size_t Size
Returns the number of scalar components ( ) in a vector of this type.
fixed_size_simd< T, N > sin(const SimdArray< T, N, V, M > &x)
Applies the std::sin function component-wise and concurrently.
fixed_size_simd< T, N > cos(const SimdArray< T, N, V, M > &x)
Applies the std::cos function component-wise and concurrently.
void free(T *p)
Frees memory that was allocated with Vc::malloc.
T * malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
constexpr VectorSpecialInitializerIndexesFromZero IndexesFromZero
The special object Vc::IndexesFromZero can be used to construct Vector objects initialized to values ...
constexpr UnalignedTag Unaligned
Use this object for a flags parameter to request unaligned loads and stores.
constexpr StreamingTag Streaming
Use this object for a flags parameter to request streaming loads and stores.