diff --git a/checks/check_1d.cpp b/checks/check_1d.cpp index ede4ee075c97cc235a0a0ce27532dd7450aec3a5..ff1438e0bb9e439f488be7129548d888c27bd0fd 100644 --- a/checks/check_1d.cpp +++ b/checks/check_1d.cpp @@ -57,9 +57,9 @@ namespace local_args { struct matrix_kernel { - cpp_tools::cl_parser::str_vec flags = {"--kernel", "--k"}; + cpp_tools::cl_parser::str_vec flags = {"--kernel", "-k"}; std::string description = "Matrix kernels: \n 0) 1/r, 2) 1/r^2, " - "2) shift(ln r)-> grad 3) val_grad( 1/r)"; + "2) val_grad( 1/r)"; using type = int; type def = 0; }; @@ -329,26 +329,9 @@ auto run_general(const int& tree_height, const int& group_size, const std::size_ check, displayCells, displayParticles); } else if(kernel == 2) - { // shift_ln_r - // using far_matrix_kernel_type = scalfmm::matrix_kernels::laplace::ln_2d; - // using near_matrix_kernel_type = scalfmm::matrix_kernels::laplace::grad_ln_2d; - // using near_field_type = scalfmm::operators::near_field_operator<near_matrix_kernel_type>; - // // - // using interpolation_type = interpolator_alias<double, Dimension, far_matrix_kernel_type>; - - // // using interpolation_type = - // // scalfmm::interpolation::uniform_interpolator<value_type, Dimension, far_matrix_kernel_type>; - // using far_field_type = scalfmm::operators::far_field_operator<interpolation_type, true>; - - // using fmm_operators_type = scalfmm::operators::fmm_operators<near_field_type, far_field_type>; - - // return run<Dimension, value_type, fmm_operators_type>(tree_height, group_size, order, input_file, output_file, - // check, displayCells, displayParticles); - } - else if(kernel == 3) { // val_grad_one_over_r - using far_matrix_kernel_type = scalfmm::matrix_kernels::laplace::val_grad_one_over_r<2>; - using near_matrix_kernel_type = scalfmm::matrix_kernels::laplace::val_grad_one_over_r<2>; + using far_matrix_kernel_type = scalfmm::matrix_kernels::laplace::val_grad_one_over_r<1>; + using near_matrix_kernel_type = scalfmm::matrix_kernels::laplace::val_grad_one_over_r<1>; using near_field_type = scalfmm::operators::near_field_operator<near_matrix_kernel_type>; // using interpolation_type = interpolator_alias<double, Dimension, far_matrix_kernel_type>; diff --git a/checks/check_2d.cpp b/checks/check_2d.cpp index 97030f1a22269ae363747e987329dfc824f9c2c9..7ca992d3f2d476eb2ccb00b824f4c5ce1cd5e2ac 100644 --- a/checks/check_2d.cpp +++ b/checks/check_2d.cpp @@ -251,6 +251,9 @@ auto run(const int& tree_height, const int& group_size, const std::size_t order, typename FMM_OPERATOR_TYPE::far_field_type far_field(interpolator); // + auto memory = interpolator.memory_usage(); + std::cout << "memory " << memory << std::endl; + // near_matrix_kernel_type mk_near{}; const bool mutual_near = false; @@ -268,7 +271,7 @@ auto run(const int& tree_height, const int& group_size, const std::size_t order, int const& separation_criterion = fmm_operator.near_field().separation_criterion(); bool const& mutual = fmm_operator.near_field().mutual(); scalfmm::list::sequential::build_interaction_lists(tree, tree, separation_criterion, mutual); - scalfmm::io::trace(std::cout, tree, 4); + // scalfmm::io::trace(std::cout, tree, 4); auto operator_to_proceed = scalfmm::algorithms::all; // auto operator_to_proceed = scalfmm::algorithms::operators_to_proceed::farfield; @@ -334,7 +337,7 @@ auto run_general(const int& tree_height, const int& group_size, const std::size_ // using far_matrix_kernel_type = // scalfmm::matrix_kernels::others::one_over_r2; using // near_matrix_kernel_type = scalfmm::matrix_kernels::others::one_over_r2; - // using options = scalfmm::options::uniform_<scalfmm::options::fft_>; + // using options = scalfmm::options::uniform_<scalfmm::options::fft_>; using options = scalfmm::options::chebyshev_<scalfmm::options::low_rank_>; // using options = scalfmm::options::chebyshev_<scalfmm::options::dense_>; if(kernel == 0) diff --git a/include/scalfmm/interpolation/barycentric/barycentric_interpolator.hpp b/include/scalfmm/interpolation/barycentric/barycentric_interpolator.hpp index f6786301390edfcc676a062acb2654c65e6bbbe9..d631bb50b06f821049b3053483c0e4504afe2585 100644 --- a/include/scalfmm/interpolation/barycentric/barycentric_interpolator.hpp +++ b/include/scalfmm/interpolation/barycentric/barycentric_interpolator.hpp @@ -9,6 +9,7 @@ #include "scalfmm/container/variadic_adaptor.hpp" #include "scalfmm/interpolation/grid_storage.hpp" #include "scalfmm/interpolation/interpolator.hpp" +#include "scalfmm/interpolation/m2l_handler.hpp" #include "scalfmm/interpolation/mapping.hpp" #include "scalfmm/interpolation/permutations.hpp" #include "scalfmm/interpolation/traits.hpp" @@ -349,6 +350,15 @@ namespace scalfmm::interpolation return xt::xarray<value_type>(std::vector{math::pow(order, dimension)}, value_type(1.)); #endif } + /** + * @brief Compute he memory in bytes used by the interpolator + * + * @return the memory used by the interpolator + */ + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + return base_m2l_handler_type::memory_usage(); + } private: /** diff --git a/include/scalfmm/interpolation/chebyshev/chebyshev_interpolator.hpp b/include/scalfmm/interpolation/chebyshev/chebyshev_interpolator.hpp index ffea501c2fca7bda1d36bec3a0c9200135c7b813..5d45d38d60d2a526c7c92814d2dfbd9d3d250a48 100644 --- a/include/scalfmm/interpolation/chebyshev/chebyshev_interpolator.hpp +++ b/include/scalfmm/interpolation/chebyshev/chebyshev_interpolator.hpp @@ -9,6 +9,7 @@ #include "scalfmm/container/variadic_adaptor.hpp" #include "scalfmm/interpolation/grid_storage.hpp" #include "scalfmm/interpolation/interpolator.hpp" +#include "scalfmm/interpolation/m2l_handler.hpp" #include "scalfmm/interpolation/mapping.hpp" #include "scalfmm/interpolation/permutations.hpp" #include "scalfmm/interpolation/traits.hpp" @@ -364,6 +365,15 @@ namespace scalfmm::interpolation meta::looper_range<dimension>{}(generate_weights, starts, stops); return roots_weights; } + /** + * @brief ompute he memory in bytes used by the interpolator + * + * @return the memory used by the interpolator + */ + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + return base_m2l_handler_type::memory_usage(); + } private: /** diff --git a/include/scalfmm/interpolation/interpolator.hpp b/include/scalfmm/interpolation/interpolator.hpp index 341aa998790fadc1abcbe999f0f9fabf01ef8735..0f4b1b1af22c825260f050fd31a032e6aa476cb1 100644 --- a/include/scalfmm/interpolation/interpolator.hpp +++ b/include/scalfmm/interpolation/interpolator.hpp @@ -7,7 +7,6 @@ #include "scalfmm/container/point.hpp" #include "scalfmm/interpolation/builders.hpp" -#include "scalfmm/interpolation/m2l_handler.hpp" #include "scalfmm/interpolation/mapping.hpp" #include "scalfmm/interpolation/permutations.hpp" #include "scalfmm/matrix_kernels/mk_common.hpp" @@ -522,48 +521,30 @@ namespace scalfmm::interpolation return *static_cast<derived_type*>(this); } - private: /** - * @brief number of terms of the expansion (1d) + * @brief ompute he memory in bytes used by the interpolator * + * @return the memory used by the interpolator */ - const size_type m_order{}; + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + return this->derived_cast().memory_usage(); + } - /** - * @brief number of modes m_order^dimension - * - */ - const size_type m_nnodes{}; + private: + const size_type m_order{}; ///< number of terms of the expansion (1d) - /** - * @brief height of the tree - * - */ - const size_type m_tree_height{}; + const size_type m_nnodes{}; ///< number of modes m_order^dimension - /** - * @brief width of the simulation box - * - */ - const value_type m_root_cell_width{}; + const size_type m_tree_height{}; ///< height of the tree - /** - * @brief width of the extension of the cell - * - */ - const value_type m_cell_width_extension{}; + const value_type m_root_cell_width{}; ///< width of the simulation box - /** - * @brief true if we use the cell extension - * - */ - const bool m_use_cell_width_extension{}; + const value_type m_cell_width_extension{}; ///< width of the extension of the cell - /** - * @brief - * - */ - array_type m_child_parent_interpolators{}; + const bool m_use_cell_width_extension{}; ///< true if we use the cell extension + + array_type m_child_parent_interpolators{}; ///< /** * @brief diff --git a/include/scalfmm/interpolation/m2l_handler.hpp b/include/scalfmm/interpolation/m2l_handler.hpp index e92e1122b18fa17bb08366be622c90a898813071..1a1b5fec45dba2a756f80ea93b6224903a3ed160 100644 --- a/include/scalfmm/interpolation/m2l_handler.hpp +++ b/include/scalfmm/interpolation/m2l_handler.hpp @@ -383,7 +383,44 @@ namespace scalfmm::interpolation { return m_interactions_matrices; } + /** + * @brief Compute he memory in bytes used by the interpolator + * + * @return the memory used by the interpolator + */ + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + std::size_t memory{0}; + auto size = m_interactions_matrices.size(); + for(auto& mat: m_interactions_matrices) + { + // mat xtensor knxkm + // std::cout << cpt++ << " "; + for(int i = 0; i < mat.shape()[0]; ++i) + { + for(int j = 0; j < mat.shape()[1]; ++j) + { + auto K = mat.at(i, j); + // dense case + if constexpr(std::is_same_v<settings, options::dense_> or + std::is_same_v<settings, options::fft_>) + { + memory += K.size() * sizeof(typename k_tensor_type::value_type); + } + else if constexpr(std::is_same_v<settings, options::low_rank_>) + { + // Low rang (tuple of two matricies) + auto const& A = std::get<0>(K); + auto const& B = std::get<1>(K); + memory += (A.size() + B.size()) * + sizeof(typename std::tuple_element_t<0, k_tensor_type>::value_type); + } + } + } + } + return memory; + } /** * @brief * @@ -1234,12 +1271,8 @@ namespace scalfmm::interpolation } private: - /** - * @brief - * - */ std::vector<interaction_matrix_type, XTENSOR_DEFAULT_ALLOCATOR(interaction_matrix_type)> - m_interactions_matrices{}; + m_interactions_matrices{}; ///< The M2L matricies /** * @brief diff --git a/include/scalfmm/interpolation/uniform/uniform_interpolator.hpp b/include/scalfmm/interpolation/uniform/uniform_interpolator.hpp index 612e322fb4bafbedc21bf2bee402fb2b36e7a051..635d23eb2a2cc80237e0749943959a869e898b58 100644 --- a/include/scalfmm/interpolation/uniform/uniform_interpolator.hpp +++ b/include/scalfmm/interpolation/uniform/uniform_interpolator.hpp @@ -17,6 +17,7 @@ #include "scalfmm/interpolation/generate_circulent.hpp" #include "scalfmm/interpolation/grid_storage.hpp" #include "scalfmm/interpolation/interpolator.hpp" +#include "scalfmm/interpolation/m2l_handler.hpp" #include "scalfmm/interpolation/mapping.hpp" #include "scalfmm/interpolation/traits.hpp" #include "scalfmm/interpolation/uniform/uniform_storage.hpp" @@ -284,7 +285,7 @@ namespace scalfmm::interpolation } /** - * @brief + * @brief Compute the weights of the quadrature * * @param order * @return xt::xarray<value_type> @@ -293,6 +294,16 @@ namespace scalfmm::interpolation { return xt::xarray<value_type>(std::vector{math::pow(order, dimension)}, value_type(1.)); } + + /** + * @brief ompute he memory in bytes used by the interpolator + * + * @return the memory used by the interpolator + */ + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + return base_m2l_handler_type::memory_usage(); + } }; /** @@ -662,7 +673,15 @@ namespace scalfmm::interpolation } return L * sum; } - + /** + * @brief ompute he memory in bytes used by the interpolator + * + * @return the memory used by the interpolator + */ + [[nodiscard]] inline auto memory_usage() const noexcept -> std::size_t const + { + return base_m2l_handler_type::memory_usage(); + } /** * @brief Returns the buffers initialized for the optimized fft *