Commit 76edb45b authored by ESTERIE Pierre's avatar ESTERIE Pierre

Some components on there way, not working yet, just backup.

parent 2797b894
......@@ -103,6 +103,12 @@ if(MORSE_DISTRIB_DIR OR EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/modules/morse_cmake"
set(FUSE_LIST "") # Construct during configure
set(FUSE_DEP_AVAILABLE "MPI;CUDA;STARPU;OMP4;BLAS;FFT;OPENCL") # List to compare against when compiling tests, etc...
#
# Boost
# -----
find_package(Boost 1.69.0 COMPONENTS serialization REQUIRED)
message(STATUS "${Boost_LIBRARIES}")
#
# OpenMP
# ------
......
......@@ -28,6 +28,10 @@ foreach(exec ${source_tests_files})
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BUILD_TYPE}
)
target_link_libraries( ${execname} ${CMAKE_PROJECT_NAME})
# TODO: Remove these include derectories, ust temporary to reuse old components
target_include_directories( ${execname} PRIVATE ${CMAKE_SOURCE_DIR}/../include/)
target_include_directories( ${execname} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions( ${execname} PRIVATE BYPASS_CONFIG)
install(TARGETS ${execname} RUNTIME DESTINATION bin)
endif()
endforeach(exec)
......
#ifndef TRAP_SCALFMM_CONFIG_HPP
#define TRAP_SCALFMM_CONFIG_HPP
#include <scalfmm/config/scalfmm-config.hpp>
#endif
......@@ -10,6 +10,11 @@
#include <inria/tcli/tcli.hpp>
#include <scalfmm/container/particle_container.hpp>
#include <scalfmm/container/point.hpp>
#include <scalfmm/container/particle.hpp>
#include <scalfmm/tree/tree.hpp>
#include <Files/FFmaGenericLoader.hpp>
namespace args
{
......@@ -69,13 +74,24 @@ struct params {
}
};
using namespace scalfmm;
int main()
struct curve {};
int main(int argc, char** argv)
{
using particle_t = std::tuple<float,float,float,float>;
struct curve{};
using container_t = container::particle_container<particle_t, curve>;
args::cli.parse(argc,argv);
params parameters(args::cli);
using source_t = container::particle<double,3,float>;
using target_t = container::point<double,3>;
using container_source_t = container::particle_container<source_t, curve>;
using container_target_t = container::particle_container<target_t, curve>;
//FFmaGenericLoader<particle_value_t> loader(parameters._filename);
return 0;
}
......
#ifndef SCALFMM_SPACE_CURVE_HPP_
#define SCALFMM_SPACE_CURVE_HPP_
// See LICENCE file at project root
//
#ifndef SCALFMM_CONTAINER_MORTON_CURVE_HPP
#define SCALFMM_CONTAINER_MORTON_CURVE_HPP
#include "Utils/FPoint.hpp"
#include <scalfmm/container/point.hpp>
#include <scalfmm/meta/const_functions.hpp>
/** Provides the corner traversal order of an N dimension hypercube
*
......@@ -22,77 +25,85 @@
*
* \tparam Dim The hypercube dimension.
*/
template<std::size_t _Dim>
class FZCurve {
public:
/// Space dimension count
constexpr static const std::size_t Dim = _Dim;
/// Position type used
using position_t = FPoint<bool, Dim>;
/// Position count in the grid
constexpr static std::size_t pos_count = Fpow(2,Dim);
namespace scalfmm::container
{
private:
/// Array of positions type
using position_array_t = std::array<position_t, pos_count>;
/// Array to cache the positions corresponding to indexes
static const position_array_t _positions;
template<std::size_t _Dim>
class z_curve
{
public:
/// Space dimension count
static const std::size_t Dim = _Dim;
/// Position type used
using position_t = point<bool, Dim>;
/// Position count in the grid
static const std::size_t pos_count = pow(2,Dim);
/** Creates an array of positions to initialize #_positions */
static position_array_t create_array() noexcept {
private:
/// Array of positions type
using position_array_t = std::array<position_t, pos_count>;
/// Array to cache the positions corresponding to indexes
static const position_array_t _positions;
/** Creates an array of positions to initialize #_positions */
static position_array_t create_array() noexcept {
position_array_t positions;
for(std::size_t i = 0; i < pos_count; ++i) {
for(std::size_t j = Dim-1, k = i; k != 0; --j, k >>=1) {
positions[i][j] = k % 2;
}
for(std::size_t j = Dim-1, k = i; k != 0; --j, k >>=1) {
positions[i][j] = k % 2;
}
}
return positions;
}
}
public:
/** The position corresponding to an index
*
* \param idx The index of the point in the space filling curve
* \return The position corresponding to the space filling curve index
*/
static position_t position(std::size_t idx) noexcept {
public:
/** The position corresponding to an index
*
* \param idx The index of the point in the space filling curve
* \return The position corresponding to the space filling curve index
*/
static position_t position(std::size_t idx) noexcept
{
return _positions[idx];
}
}
/** Index in the space filling curve of a boolean position
*
* \param p The position
* \return The space filling curve index corresponding to the position
*/
static std::size_t index(const position_t& p) noexcept {
/** Index in the space filling curve of a boolean position
*
* \param p The position
* \return The space filling curve index corresponding to the position
*/
static std::size_t index(const position_t& p) noexcept
{
std::size_t idx = 0;
for(auto i : p) {
idx <<= 1;
idx += i;
idx <<= 1;
idx += i;
}
return idx;
}
}
/** Index in the space filling curve of a real position relative to the center of the hypercube
*
* \param p The position
* \param center The center of the hypercube
* \return The space filling curve index corresponding to the position
*/
template<typename FReal>
static std::size_t index(const FPoint<FReal, Dim>& p, const FPoint<FReal, Dim>& center) noexcept {
std::size_t idx = 0;
for(std::size_t i = 0; i < Dim; ++i) {
/** Index in the space filling curve of a real position relative to the center of the hypercube
*
* \param p The position
* \param center The center of the hypercube
* \return The space filling curve index corresponding to the position
*/
template<typename T>
static std::size_t index(const point<T, Dim>& p, const point<T, Dim>& center) noexcept
{
std::size_t idx = 0;
for(std::size_t i = 0; i < Dim; ++i) {
idx <<= 1;
idx += p[i] > center[i];
}
return idx;
}
return idx;
}
};
};
// Initialization of static variable
template<std::size_t _Dim>
const typename FZCurve<_Dim>::position_array_t FZCurve<_Dim>::_positions(FZCurve<_Dim>::create_array());
// Initialization of static variable
template<std::size_t _Dim>
const typename z_curve<_Dim>::position_array_t z_curve<_Dim>::_positions(z_curve<_Dim>::create_array());
}
#endif
// --------------------------------
// See LICENCE file at project root
// File : particle.hpp
// --------------------------------
#ifndef SCALFMM_CONTAINER_PARTICLE_HPP
#define SCALFMM_CONTAINER_PARTICLE_HPP
#include <inria/integer_sequence.hpp>
#include <scalfmm/container/point.hpp>
#include <scalfmm/meta/type_pack.hpp>
/**
* \brief Multi-purpose particle implementation
*
* This template implementation of a particle allows simple reuse for several
* use cases. The aim it to provide an interface that is compatible with the
* rest of ScalFMM. It is mainly intended to be used as an interface for the
* particle containers.
*
* The Types parameter pack can accept any type that is to be considered as a
* particle attribute. You can also specify scalfmm::pack type to factorise
* several types.
*
* In the following example, the two specialisations of the class will give the
* same final structure.
*
* ```
* using FReal = double;
* static constexpr std::size_t Dim = 3;
*
* particle<FReal, Dim, int, float, float, float, float>;
* particle<FReal, Dim, int, scalfmm::pack<4, float> >;
* ```
*
* The base of these two classes is
* ```
* std::tuple<double, double, double, int, float, float, float, float>;
* ```
*
* \warning Although the classes will have the same final layout, C++ considers
* these two classes to be different !
*
* ##### Example
*
* ```
* // Define a 3D particle with an int attribute
* using Particle = particle<double, 3, int>;
*
* Particle p;
* p.get<>
* ```
*
*
* \tparam FReal Floating point type
* \tparam Dim Space dimension count
* \tparam Types Attributes type list
*
*/
namespace scalfmm::container
{
template<typename ValueType, std::size_t _Dim = 3, typename... Types>
class particle : public scalfmm::meta::pack_expand_tuple< scalfmm::meta::pack<_Dim, ValueType>, Types... >
{
public:
/// Storage class : std::tuple<FReal,...(Dim times), Types...>
using tuple_data_t = scalfmm::meta::
pack_expand_tuple< scalfmm::meta::pack<_Dim, ValueType>, Types... >;
/// Expand Types list
using types_tuple_t = scalfmm::meta::
pack_expand_tuple< Types... >;
/// Expand std::enable_if if possible
template<bool value>
using sfinae_check = typename std::enable_if<value, bool>::type;
/**
* \brief Check parameter pack size vs. attribute + dimension count at
* compile time
*
* \return true if the parameter pack is shorter than the attribute list
* size + the dimension
*/
template<typename... Ts>
constexpr static bool correct_attribute_list_size()
{
return std::tuple_size<tuple_data_t>::value >= sizeof...(Ts) + Dim;
}
/// Space dimensions
constexpr static std::size_t Dim = _Dim;
/// Size of #tuple_data_t tuple
constexpr static std::size_t NbAttributes = std::tuple_size<tuple_data_t>::value - Dim;
/// Floating point type
using value_type = ValueType;
/// Position type, required by the FVariadicParticleContainer
using position_t = point<value_type, Dim>;
/// Default constructor
particle() = default;
/// Default copy constructor
particle(const particle&) = default;
/// Default copy operator
particle& operator=(const particle&) = default;
/// Default move constructor
particle(particle&&) = default;
/// Default move operator
particle& operator=(particle&&) = default;
/**
* \brief Constructor from position and types
*
* \tparam Ts Attributes parameter pack; if Ts is too long, this will not
* compile.
*
* \param pos Particle position
* \param ts Attributes
*
* \warning There may be less attributes than defined by the particle, in
* that case the missing ones are zero constructed.
*/
template<typename... Ts, sfinae_check<correct_attribute_list_size<Ts...>()> = 0>
particle(const position_t& pos, Ts&&... ts)
: particle(inria::make_index_sequence<Dim>(),
inria::make_index_sequence<std::tuple_size<tuple_data_t>::value-sizeof...(ts)-Dim>(),
pos,
std::forward<Ts>(ts)...
)
{}
/// Constructor from tuple equivalent to #tuple_data_t
template<typename... Ts>
particle(const std::tuple<Ts...>& ts)
: tuple_data_t(ts)
{}
/**
* \brief Position getter
*
* The position is stored in the #_data tuple, to extract it we need to
* recreate a position_t object. This is done by the position_impl() method.
*
* \return A new position_t object
*/
position_t position() const
{
return position_impl(inria::make_index_sequence<Dim>());
}
/**
* \brief Position setter
*
* \parma pos The new position
*/
void set_position(const position_t& pos)
{
return set_position_impl(pos, inria::make_index_sequence<Dim>());
}
/**
* \brief Get a reference to the Ith attribute
*
* \tparam I Index of the attribute to get
*/
template<std::size_t I>
auto attribute() -> decltype(std::get<Dim+I>(*this))
{
return std::get<Dim+I>(*this);
}
/**
* \brief Get a const reference to the Ith attribute
*
* \tparam I Index of the attribute to get
*/
template<std::size_t I>
auto attribute() const -> decltype(std::get<Dim+I>(*this))
{
return std::get<Dim+I>(*this);
}
/**
* \brief Get a tuple filled with copies of the attributes
*/
types_tuple_t attributes() const
{
return attributes_impl(
inria::make_index_sequence<std::tuple_size<types_tuple_t>::value>());
}
/**
* \brief Convert particle to a tuple
*/
tuple_data_t& as_tuple()
{
return *this;
}
/**
* \brief Convert particle to a tuple
*/
const tuple_data_t& as_tuple() const
{
return *this;
}
private:
/**
* \brief Contructor implementation
*
* Builds the particle, zero constructing missing arguuments.
*/
template<typename... Ts, std::size_t... Is, std::size_t... Js>
particle(inria::index_sequence<Is...>, inria::index_sequence<Js...>,
const position_t& pos, Ts&&... ts)
: tuple_data_t(pos[Is]..., std::forward<Ts>(ts)...,
typename std::tuple_element<Dim+Js+sizeof...(ts), tuple_data_t>::type(0)...)
{
//static_assert(sizeof...(Ts) == NbAttributes, "Parameter count is incorrect");
}
/**
* \brief #position method implementation
*
* \tparam Is Index sequence of the position elements in the tuple, deduced
* using arguments
*/
template<std::size_t... Is>
position_t position_impl(inria::index_sequence<Is...>) const
{
return position_t(std::get<Is>(this->as_tuple())...);
}
/**
* \brief #setPosition method implementation
*
* \tparam Is Index sequence of the position elements in the tuple, deduced
* using arguments
*
* \param pos new position
*/
template<std::size_t... Is>
void set_position_impl(const position_t& pos, inria::index_sequence<Is...>)
{
auto l = {std::get<Is>(this->as_tuple()) = pos[Is] ...};
(void)l;
}
/**
* \brief #attributes method implementation
*
* \tparam Is Index sequence of the attributes in the tuple, deduced using
* arguments
*
* \param pos new position
*/
template<std::size_t... Is>
types_tuple_t attributes_impl(inria::index_sequence<Is...>) const
{
return types_tuple_t(std::get<Is+Dim>(*this)...);
}
};
}
#endif // SCALFMM_CONTAINER_PARTICLE_HPP
......@@ -5,21 +5,46 @@
#ifndef SCALFMM_CONTAINER_PARTICLE_CONTAINER_HPP
#define SCALFMM_CONTAINER_PARTICLE_CONTAINER_HPP
#include <vector>
#include <tuple>
#include <xsimd/config/xsimd_align.hpp>
#include <scalfmm/memory/aligned_allocator.hpp>
#include <scalfmm/container/variadic_container.hpp>
#include <scalfmm/meta/traits.hpp>
namespace scalfmm::container
{
//template<typename Tuple, typename Curve, typename Allocator = memory::aligned_allocator<Tuple, XSIMD_DEFAULT_ALIGNMENT>>
//class particle_container;
template<typename Tuple, typename Curve, typename Allocator = memory::aligned_allocator<XSIMD_DEFAULT_ALIGNMENT, Tuple>>
class particle_container : public variadic_container<Allocator, Tuple>
template<typename Particle, typename SpaceCurve>
class particle_container
: public variadic_container< memory::aligned_allocator<XSIMD_DEFAULT_ALIGNMENT
, typename meta::tuple_cat< typename Particle::tuple_data_t
, std::tuple<std::size_t>>::type
>
>
{
public:
//using tuple_t = decltype(std::tuple_cat(Particle{}.as_tuple(),std::make_tuple(std::size_t{})));
using particle_t = Particle;
using space_curve_t = SpaceCurve;
//using allocator_t = Allocator;
particle_container() = default;
particle_container(const particle_container& other) = default;
particle_container(particle_container&& other) = default;
particle_container& operator=(const particle_container& other) = default;
particle_container& operator=(particle_container&& other) = default;
//explicit particle_container()
//{
//}
private:
space_curve_t m_curve{};
//variadic_container<allocator_t, tuple_t> m_inner_container{};
};
}
#endif // SCALFMM_MEMORY_PARTICLE_CONTAINER_HPP
#endif // SCALFMM_CONTAINER_PARTICLE_CONTAINER_HPP
......@@ -10,17 +10,11 @@
#include <cmath>
#include <scalfmm/meta/traits.hpp>
#include <scalfmm/meta/const_functions.hpp>
namespace scalfmm::container
{
template<typename T, typename U,
typename = std::enable_if_t<std::is_floating_point<T>::value,T>,
typename = std::enable_if_t<std::is_floating_point<U>::value,U>>
constexpr bool feq(const T& a, const U& b, T epsilon = 1e-7) {
return a - b < epsilon && b - a < epsilon;
}
template <typename Arithmetic, std::size_t Dim = 3, typename Enable = void>
struct point
{
......@@ -71,17 +65,19 @@ namespace scalfmm::container
/** Default constructor */
point() noexcept = default;
/** Copy constructor */
point(const point &) noexcept = default;
/** Copy constructor from other point type */
template <typename A, must_be_arithmetic<A> = nullptr>
point(const point<A, Dim> &other) noexcept
{
for (std::size_t i = 0; i < Dim; ++i)
{
this->data()[i] = other.data()[i];
}
}
point(const point&) noexcept = default;
/** Copy constructor */
point(point&&) noexcept = default;
///** Copy constructor from other point type */
//template <typename A, must_be_arithmetic<A> = nullptr>
//point(const point<A, Dim> &other) noexcept
//{
// for (std::size_t i = 0; i < Dim; ++i)
// {
// this->data()[i] = other.data()[i];
// }
//}
/** Constructor from array */
point(const value_type array_[Dim]) noexcept
......@@ -145,7 +141,6 @@ namespace scalfmm::container
template <typename T, must_be_arithmetic<T> = nullptr>
inline point<T, Dim>& operator=(point<T, Dim> &&other) noexcept
{
std::cout << "in here !" << std::endl;
if(this != &other)
swap(other);
return *this;
......
// See LICENCE file at project root
//
#ifndef SCALFMM_META_CONST_FUNCTIONS_HPP
#define SCALFMM_META_CONST_FUNCTIONS_HPP
namespace scalfmm::meta
{
template<typename T, typename U,
typename = std::enable_if_t<std::is_floating_point<T>::value,T>,
typename = std::enable_if_t<std::is_floating_point<U>::value,U>>
constexpr bool feq(const T& a, const U& b, T epsilon = 1e-7)
{
return a - b < epsilon && b - a < epsilon;
}
template<typename T>
constexpr T pow(T a, std::size_t p)
{
return p == 0 ? 1 : a * pow<T>(a, p-1);
}
}
#endif
......@@ -45,6 +45,12 @@ namespace scalfmm::meta
// specialization recognizes types that do have a nested ::type member:
template< class T >
struct is_double<T, std::void_t<double>> : std::true_type { };
// Tuple cat
template<typename T, typename U>
struct tuple_cat
{ using type = decltype(std::tuple_cat(T{},U{})); };
} // namespace scalfmm::meta
#endif
// --------------------------------
// See LICENCE file at project root
// File : type_pack.hpp
// --------------------------------
#ifndef SCALFMM_META_TYPE_PACK_HPP
#define SCALFMM_META_TYPE_PACK_HPP
#include <tuple>
namespace scalfmm::meta
{
template<std::size_t I, typename T>
struct pack {
enum {size = I};
using type = T;
};
namespace details
{
template<
template<class...> class Final,
typename ExpandedTuple,
typename... ToExpand
>
struct pack_expand_impl;
template<
template<class...> class Final,
typename... Expanded
>
struct pack_expand_impl<Final, std::tuple<Expanded...> > {
using type = Final<Expanded...>;
};
template<
template<class...> class Final,
typename T,
typename... Args,
typename... Expanded
>
struct pack_expand_impl<Final, std::tuple<Expanded...>, pack<0, T>, Args...> {
using type = typename pack_expand_impl<Final, std::tuple<Expanded...>, Args...>::type;
};
template<
template<class...> class Final,
std::size_t count,
typename T,
typename... Args,
typename... Expanded
>
struct pack_expand_impl<Final, std::tuple<Expanded...>, pack<count, T>, Args...> {
using type = typename pack_expand_impl<Final, std::tuple<Expanded..., T>, pack<count-1, T>, Args...>::type;
};
template<
template<class...> class Final,
typename T,
typename... Args,
typename... Expanded
>
struct pack_expand_impl<Final, std::tuple<Expanded...>, T, Args...> {
using type = typename pack_expand_impl<Final, std::tuple<Expanded..., T>, Args...>::type;