Skip to content
Snippets Groups Projects
Commit 3b394252 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Merge branch 'develop' of gitlab.delpinux.fr:code/pastis into feature/backtrace

parents 1dda0a42 a5d90560
No related branches found
No related tags found
No related merge requests found
......@@ -42,6 +42,10 @@ include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
add_subdirectory(utils)
include_directories(utils)
# Pastis algebra
#add_subdirectory(algebra)
include_directories(algebra)
# Pastis experimental
add_subdirectory(experimental)
include_directories(experimental)
......
#ifndef TINY_VECTOR_HPP
#define TINY_VECTOR_HPP
#include <cassert>
#include <iostream>
template <size_t N, typename T=double>
class TinyVector
{
private:
T m_values[N];
static_assert((N>0),"TinyVector size must be strictly positive");
public:
KOKKOS_INLINE_FUNCTION
T operator,(const TinyVector& v)
{
T t = m_values[0]*v.m_values[0];
for (size_t i=1; i<N; ++i) {
t += m_values[i]*v.m_values[i];
}
return std::move(t);
}
KOKKOS_INLINE_FUNCTION
friend TinyVector operator*(const T& t, const TinyVector& v)
{
TinyVector tv;
for (size_t i=0; i<N; ++i) {
tv.m_values[i] = t * v.m_values[i];
}
return std::move(tv);
}
KOKKOS_INLINE_FUNCTION
friend std::ostream& operator<<(std::ostream& os, const TinyVector& v)
{
os << '(' << v.m_values[0];
for (size_t i=1; i<N; ++i) {
os << ',' << v.m_values[i];
}
os << ')';
return os;
}
KOKKOS_INLINE_FUNCTION
TinyVector operator+(const TinyVector& v) const
{
TinyVector sum;
for (size_t i=0; i<N; ++i) {
sum[i] = m_values[i]+v.m_values[i];
}
return std::move(sum);
}
KOKKOS_INLINE_FUNCTION
TinyVector operator-(const TinyVector& v) const
{
TinyVector difference;
for (size_t i=0; i<N; ++i) {
difference[i] = m_values[i]-v.m_values[i];
}
return std::move(difference);
}
KOKKOS_INLINE_FUNCTION
TinyVector& operator+=(const TinyVector& v)
{
for (size_t i=0; i<N; ++i) {
m_values[i] += v.m_values[i];
}
return *this;
}
KOKKOS_INLINE_FUNCTION
TinyVector& operator-=(const TinyVector& v)
{
for (size_t i=0; i<N; ++i) {
m_values[i] -= v.m_values[i];
}
return *this;
}
KOKKOS_INLINE_FUNCTION
TinyVector& operator=(const T& t)
{
for (size_t i=0; i<N; ++i) {
m_values[i] = t;
}
return *this;
}
KOKKOS_INLINE_FUNCTION
T& operator[](const size_t& i)
{
assert(i<N);
return m_values[i];
}
KOKKOS_INLINE_FUNCTION
const T& operator[](const size_t& i) const
{
assert(i<N);
return m_values[i];
}
KOKKOS_INLINE_FUNCTION
const TinyVector& operator=(const TinyVector& v)
{
for (size_t i=0; i<N; ++i) {
m_values[i] = v.m_values[i];
}
return *this;
}
KOKKOS_INLINE_FUNCTION
TinyVector& operator=(TinyVector&& v) = default;
KOKKOS_INLINE_FUNCTION
TinyVector()
{
;
}
KOKKOS_INLINE_FUNCTION
TinyVector(const T& t)
{
for (size_t i=0; i<N; ++i) {
m_values[i] = t;
}
}
KOKKOS_INLINE_FUNCTION
TinyVector(const TinyVector& v)
{
for (size_t i=0; i<N; ++i) {
m_values[i] = v.m_values[i];
}
}
KOKKOS_INLINE_FUNCTION
TinyVector(TinyVector&& v) = default;
KOKKOS_INLINE_FUNCTION
~TinyVector()
{
;
}
};
#endif // TINYVECTOR_HPP
......@@ -11,6 +11,8 @@
#include <AcousticSolver.hpp>
#include <AcousticSolverTest.hpp>
#include <TinyVector.hpp>
#include <CLI/CLI.hpp>
#include <cassert>
#include <limits>
......@@ -107,6 +109,12 @@ int main(int argc, char *argv[])
method_cost_map["AcousticSolver"] = timer.seconds();
}
Kokkos::View<TinyVector<2,double>*[2]> test("test", 10);
constexpr size_t N = 3;
std::cout << "sizeof(TinyVector<" << N << ",double>)=" << sizeof(TinyVector<N,double>) << std::endl;
std::cout << "sizeof(double)=" << sizeof(double) << std::endl;
Kokkos::finalize();
std::cout << "----------------------\n";
......@@ -125,5 +133,13 @@ int main(int argc, char *argv[])
<< rang::style::reset << '\n';
}
TinyVector<2> x=1;
TinyVector<2> y=2;
std::cout << x << "-" << y << "=" << x-y << std::endl;
std::cout << x << "+" << y << "=" << x+y << std::endl;
std::cout << "3*" << x << '=' << 3*x << std::endl;
x[1]=3; y[1]=0.1;
std::cout << "< " << x << " | " << y << " > = " << (x,y) << std::endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment