Commit fa88e2f4 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

add pgm to trace tree information (group, index, interaction lists, ..

parent 1c56acd9
......@@ -21,6 +21,7 @@ set(source_tests_files
count_kernel.cpp
test_l2p.cpp
test-build-let.cpp
trace-tree.cpp
)
#if(SCALFMM_USE_MPI)
# set(source_tests_files ${source_tests_files}
......

#include "parameters.hpp"
#include "scalfmm/algorithms/common.hpp"
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/container/point.hpp"
#include "scalfmm/tools/colorized.hpp"
#include "scalfmm/tools/fma_loader.hpp"
#include "scalfmm/tree/box.hpp"
#include "scalfmm/tree/cell.hpp"
#include "scalfmm/tree/group_tree.hpp"
#include "scalfmm/tree/leaf.hpp"
#include "scalfmm/utils/sort.hpp"
#include "scalfmm/utils/timer.hpp"
#include "scalfmm/interpolation/grid_storage.hpp"
#include <array>
#include <bits/c++config.h>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <thread>
#include <tuple>
#include <unistd.h>
#include <utility>
#include <vector>
struct isSorted
{
/// Unused type, mandatory per interface specification
using type = bool;
/// The parameter is a flag, it doesn't expect a following value
enum
{
flagged
};
inria::tcli::str_vec flags = {"--data-sorted", "--ds"};
std::string description = "Precise if the data are sorted by their morton index";
};
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
{
//
// Parameter handling
auto parser = inria::tcli::make_parser(inria::tcli::help{}, args::input_file(), args::output_file(),
args::tree_height{}, args::order{}, // args::thread_count{},
args::block_size{}, args::log_file{}, args::log_level{});
parser.parse(argc, argv);
// Getting command line parameters
const int tree_height{parser.get<args::tree_height>()};
std::cout << scalfmm::colors::blue << "<params> Tree height : " << tree_height << scalfmm::colors::reset << '\n';
const int group_size{parser.get<args::block_size>()};
std::cout << scalfmm::colors::blue << "<params> Group Size : " << group_size << scalfmm::colors::reset << '\n';
const std::string input_file{parser.get<args::input_file>()};
if(!input_file.empty())
{
std::cout << scalfmm::colors::blue << "<params> Input file : " << input_file << scalfmm::colors::reset << '\n';
}
const auto output_file{parser.get<args::output_file>()};
if(!output_file.empty())
{
std::cout << scalfmm::colors::blue << "<params> Output file : " << output_file << scalfmm::colors::reset
<< '\n';
}
// Parameter handling
std::cout << scalfmm::colors::blue << "Entering tree test...\n" << scalfmm::colors::reset;
static constexpr std::size_t dimension = 3;
static constexpr std::size_t inputs = 2;
static constexpr std::size_t outputs = 2;
const auto order{parser.get<args::order>()};
std::cout << scalfmm::colors::blue << "<params> Runtime order : " << order << scalfmm::colors::reset << '\n';
// const auto log_level{parser.get<args::log_level>()};
// Open particle file
std::size_t number_of_particles{};
scalfmm::utils::timer time{};
// ---------------------------------------
// scalfmm 3.0 tree tests and benchmarks.
// ---------------------------------------
using particle_type = scalfmm::container::particle<double, dimension, double, inputs, double, outputs, std::size_t>;
using container_type = scalfmm::container::particle_container<particle_type>;
using position_type = typename particle_type::position_type;
using cell_type = scalfmm::component::cell<scalfmm::component::grid_storage<double,dimension,inputs,outputs>>;
using leaf_type = scalfmm::component::leaf<particle_type>;
using box_type = scalfmm::component::box<position_type>;
using group_tree_type = scalfmm::component::group_tree<cell_type, leaf_type, box_type>;
std::cout << scalfmm::colors::green << "Creating & Inserting " << number_of_particles
<< "particles for version .0 ...\n"
<< scalfmm::colors::reset;
scalfmm::container::point<double, dimension> box_center{};
double box_width{};
scalfmm::tools::FFmaGenericLoader<double> loader(input_file);
box_center = scalfmm::container::point<double, dimension>{loader.getBoxCenter()[0], loader.getBoxCenter()[1],
loader.getBoxCenter()[2]};
number_of_particles = loader.getNumberOfParticles();
box_width = loader.getBoxWidth();
std::cout << scalfmm::colors::green << "Box center = " << box_center << scalfmm::colors::reset << '\n';
time.tic();
auto nb_val_to_red_per_part = loader.get_dimension() + loader.get_number_of_input_per_record();
double* values_to_read = new double[nb_val_to_red_per_part]{};
container_type* container = new container_type(number_of_particles);
for(std::size_t idx = 0; idx < number_of_particles; ++idx)
{
loader.fillParticle(values_to_read, nb_val_to_red_per_part);
particle_type p(position_type(0.), 0., 0., idx);
std::size_t ii{0};
for(auto& e: p.position())
{
e = values_to_read[ii++];
}
for(auto& e: p.inputs())
{
e = values_to_read[ii++];
}
container->push_particle(idx, p);
}
time.tac();
std::cout << scalfmm::colors::green << "... Done.\n" << scalfmm::colors::reset;
std::cout << scalfmm::colors::yellow << "Container loaded in " << time.elapsed() << "ms\n"
<< scalfmm::colors::reset;
box_type box(box_width, box_center);
group_tree_type gtree(static_cast<std::size_t>(tree_height), order, box,
static_cast<std::size_t>(group_size), *container);
gtree.update_interaction_list();
int log_level = 5;
gtree.trace(log_level);
return 0;
}
......@@ -410,8 +410,17 @@ namespace scalfmm::component
std::cerr << " insert_component_at_level not yet implemented" << std::endl;
}
///
/// \brief trace
/// \param level_trace
/// \brief trace the index of the cells and leaves in the tree
///
/// Depending on the level we print more or less details
/// level_trace = 1 print minimal information (height, order, group size)
/// level_trace = 2 print information of the tree (group interval and index inside)
/// level_trace = 3 print information of the tree (leaf interval and index inside and their p2p interaction
/// list) level_trace = 4 print information of the tree (cell interval and index inside and their m2l
/// interaction list) level_trace = 5 print information of the tree (leaf and cell interval and index inside
/// and their p2p and m2l interaction lists)
///
/// \param[in] level_trace level of the trace
///
inline auto trace(std::size_t level_trace = 0) -> void
{
......@@ -427,43 +436,118 @@ namespace scalfmm::component
auto level_2 = [this]() {
std::size_t id_group{0};
std::cout << "======================================================================\n";
std::cout << "========== leaf level : " << m_tree_height - 1 << " ============================\n";
std::cout << m_group_of_leaf.size() << " groups at leaf level.\n";
std::for_each(
std::cbegin(m_group_of_leaf), std::cend(m_group_of_leaf), [&id_group](auto const& ptr_group) {
auto const& current_group_symbolics = ptr_group->csymbolics();
std::cout << "*** Group of leaf " << ++id_group << " ***\n";
std::cout << "starting index = " << current_group_symbolics.starting_index << " ***\n";
std::cout << "ending index = " << current_group_symbolics.ending_index << " ***\n";
std::cout << "number of components in group = "
<< current_group_symbolics.number_of_component_in_group << " ***\n";
std::cout << "global index = " << current_group_symbolics.idx_global << " ***\n";
std::cout << "*** Group of leaf index " << ++id_group << " *** index in ["
<< current_group_symbolics.starting_index << ", "
<< current_group_symbolics.ending_index << "]\n";
std::cout << " group size: " << current_group_symbolics.number_of_component_in_group << ", ";
std::cout << "global index = " << current_group_symbolics.idx_global << " \n";
std::cout << " index: ";
component::for_each(std::begin(*ptr_group), std::end(*ptr_group),
[](auto& leaf) { std::cout << leaf.index() << "(" << leaf.size() << ") "; });
std::cout << std::endl;
});
std::cout << "======================================================================\n";
std::cout << "======================================================================\n";
auto cell_level_it = std::cbegin(m_group_of_cell_per_level) + (m_tree_height - 1);
id_group = 0;
for(std::size_t level = m_tree_height - 1; level > 0; --level)
for(std::size_t level = m_tree_height - 1; level > 1; --level)
{
std::cout << "========== level : " << level << " ============================\n";
auto group_of_cell_begin = std::cbegin(*(cell_level_it));
auto group_of_cell_end = std::cend(*(cell_level_it));
std::for_each(group_of_cell_begin, group_of_cell_end, [&id_group](auto const& ptr_group) {
auto const& current_group_symbolics = ptr_group->csymbolics();
std::cout << "*** Group of cell " << ++id_group << " ***\n";
std::cout << "starting index = " << current_group_symbolics.starting_index << " ***\n";
std::cout << "ending index = " << current_group_symbolics.ending_index << " ***\n";
std::cout << "number of components in group = "
<< current_group_symbolics.number_of_component_in_group << " ***\n";
std::cout << "global index = " << current_group_symbolics.idx_global << " ***\n";
std::cout << "*** Group of cell index " << ++id_group << " *** index in ["
<< current_group_symbolics.starting_index << ", "
<< current_group_symbolics.ending_index << "]\n";
std::cout << " group size: " << current_group_symbolics.number_of_component_in_group
<< ", ";
std::cout << "global index = " << current_group_symbolics.idx_global << " \n";
std::cout << " index: ";
component::for_each(std::begin(*ptr_group), std::end(*ptr_group),
[](auto& cell) { std::cout << cell.index() << " "; });
std::cout << std::endl;
});
--cell_level_it;
}
};
auto level_leaf_p2p = [this]() {
std::size_t id_group{0};
std::cout << "========================== P2P interaction list ========================= \n";
std::cout << m_group_of_leaf.size() << " groups at leaf level.\n";
std::for_each(
std::cbegin(m_group_of_leaf), std::cend(m_group_of_leaf), [&id_group](auto const& ptr_group) {
auto const& current_group_symbolics = ptr_group->csymbolics();
std::cout << "*** Group of leaf index " << ++id_group << " *** index in ["
<< current_group_symbolics.starting_index << ", "
<< current_group_symbolics.ending_index << "]\n";
std::cout << " group size: " << current_group_symbolics.number_of_component_in_group << ", ";
std::cout << "global index = " << current_group_symbolics.idx_global << " \n";
std::cout << " index: \n";
component::for_each(std::begin(*ptr_group), std::end(*ptr_group), [](auto& leaf) {
auto& leaf_symbolics = leaf.symbolics();
std::cout << " " << leaf.index() << " p2p_list (" << leaf_symbolics.number_of_neighbors
<< "): ";
// get the p2p interacion list
auto index = leaf_symbolics.interaction_indexes;
for(int idx = 0; idx < leaf_symbolics.number_of_neighbors; ++idx)
{
std::cout << index[idx] << " ";
}
std::cout << std::endl;
});
std::cout << std::endl;
});
};
auto level_leaf_m2l = [this]() {
std::size_t id_group{0};
std::cout << "========================== M2L interaction list ========================= \n";
auto cell_level_it = std::cbegin(m_group_of_cell_per_level) + (m_tree_height - 1);
id_group = 0;
for(std::size_t level = m_tree_height - 1; level > 1; --level)
{
std::cout << "========== level : " << level << " ============================\n";
auto group_of_cell_begin = std::cbegin(*(cell_level_it));
auto group_of_cell_end = std::cend(*(cell_level_it));
std::for_each(group_of_cell_begin, group_of_cell_end, [&id_group](auto const& ptr_group) {
auto const& current_group_symbolics = ptr_group->csymbolics();
std::cout << "*** Group of cell index " << ++id_group << " *** index in ["
<< current_group_symbolics.starting_index << ", "
<< current_group_symbolics.ending_index << "]\n";
std::cout << " group size: " << current_group_symbolics.number_of_component_in_group
<< ", ";
std::cout << "global index = " << current_group_symbolics.idx_global << " \n";
std::cout << " index: \n";
component::for_each(std::begin(*ptr_group), std::end(*ptr_group), [](auto& cell) {
auto& cell_symbolics = cell.symbolics();
std::cout << " " << cell.index() << " m2l_list ("
<< cell_symbolics.number_of_neighbors << "): ";
// get the m2l interacion list
auto index = cell_symbolics.interaction_indexes;
for(int idx = 0; idx < cell_symbolics.number_of_neighbors; ++idx)
{
std::cout << index[idx] << " ";
}
std::cout << std::endl;
});
std::cout << std::endl;
});
--cell_level_it;
}
};
switch(level_trace)
{
case 0:
......@@ -472,6 +556,17 @@ namespace scalfmm::component
level_1();
case 2:
level_2();
case 3:
level_leaf_p2p();
break;
case 4:
level_leaf_m2l();
break;
case 5:
level_leaf_p2p();
level_leaf_m2l();
break;
default:
level_0();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment