Commit 749f6a3e authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

start test-compose

parent e268eb0e
......@@ -24,7 +24,7 @@ set(source_tests_files
trace-tree.cpp
test-time-loop.cpp
# test to move in compose/sandox project
compose.cpp
test-compose.cpp
)
#if(SCALFMM_USE_MPI)
# set(source_tests_files ${source_tests_files}
......
......@@ -5,7 +5,6 @@
#include "parameters.hpp"
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
//#include "scalfmm/meta/traits.hpp"
#include "scalfmm/tools/colorized.hpp"
#include "scalfmm/tools/fma_dist_loader.hpp"
#include "scalfmm/tools/fma_loader.hpp"
......
#include <vector>
//
// ScalFMM includes
//
#include "parameters.hpp"
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/tools/colorized.hpp"
#include "scalfmm/tools/fma_dist_loader.hpp"
#include "scalfmm/tools/fma_loader.hpp"
#include "scalfmm/tree/box.hpp"
#include "scalfmm/tree/group_let.hpp"
#include "scalfmm/utils/parallel_manager.hpp"
#include "scalfmm/matrix_kernels/laplace.hpp"
//
// Maphyspp includes
//
///
/////////////////////////////////////////////////////////////////
///
/// Example to run the program
///
///
///
/////////////////////////////////////////////////////////////////
namespace local_args {
struct dimension {
inria::tcli::str_vec flags = {"--dimension", "--d"};
const char* description =
"Dimension : \n 2 for dimension 2, 3 for dimension 3";
using type = int;
type def = 1;
};
struct input_file : inria::tcli::required_tag {
inria::tcli::str_vec flags = {"--input-file", "-fin"};
const char* description = "Input filename (.fma or .bfma).";
using type = std::string;
};
struct output_file {
inria::tcli::str_vec flags = {"--output-file", "-fout"};
const char* description =
"Output particle file (with extension .fma (ascii) or bfma (binary).";
using type = std::string;
};
} // namespace local_args
template <std::size_t Dimension, typename ContainerType, typename ValueType>
std::size_t read_data(parallel_manager& para, const std::string& filename,
ContainerType& container,
scalfmm::container::point<ValueType, Dimension>& Centre,
ValueType& width) {
using particle_type = typename ContainerType::value_type;
scalfmm::tools::DistFmaGenericLoader<ValueType, Dimension> loader(filename,
para);
const int number_of_particles = loader.getNumberOfParticles();
const int local_number_of_particles = loader.getMyNumberOfParticles();
width = loader.getBoxWidth();
Centre = loader.getBoxCenter();
auto nb_val_to_red_per_part = loader.getNbRecordPerline();
double* values_to_read = new double[nb_val_to_red_per_part]{0};
container.resize(local_number_of_particles);
std::cout << "number_of_particles " << number_of_particles << std::endl;
for (std::size_t idx = 0; idx < local_number_of_particles; ++idx) {
loader.fillParticle(values_to_read, nb_val_to_red_per_part);
particle_type p;
std::size_t ii{0};
for (auto& e : p.position()) {
e = values_to_read[ii++];
}
for (auto& e : p.inputs()) {
e = ValueType(1.0);
}
container[idx] = p;
}
return number_of_particles;
}
template <typename ContainerType, typename Box_type, typename Distrib_type>
void build_distrib(parallel_manager& para, ContainerType& particle_container,
std::size_t& number_of_particles, const Box_type& box,
const int& level, Distrib_type& index_dist) {
// using morton_type = std::size_t;
using index_type = std::int64_t;
using morton_distrib_type = std::array<index_type, 2>;
///
/// sort particles
scalfmm::tree::let::sort_particles_inplace(para, particle_container, box,
level);
const std::size_t localNumberOfParticles = particle_container.size();
std::vector<index_type> leafMortonIdx(localNumberOfParticles);
// As the particles are sorted the leafMortonIdx is sorted too
#pragma omp parallel for shared(localNumberOfParticles, box, level)
for (std::size_t part = 0; part < localNumberOfParticles; ++part) {
leafMortonIdx[part] = scalfmm::index::get_morton_index(
particle_container[part].position(), box, level);
}
std::vector<morton_distrib_type> particles_distrib(para.get_num_processes());
particles_distrib = std::move(scalfmm::tree::distrib::balanced_particles(
para, particle_container, leafMortonIdx, number_of_particles));
scalfmm::tree::distrib::fit_particles_in_distrib(
para, particle_container, leafMortonIdx, particles_distrib, box, level,
number_of_particles);
/// build the distribution of rows or columns
///
}
void build_matrix() {}
template <std::size_t Dimension, typename... Parameters>
auto run(inria::tcli::parser<Parameters...> const& parser,
parallel_manager& para) -> int {
////////////////////////////////////////////////
///
///
using value_type = double;
using matrix_kernel_type = scalfmm::matrix_kernels::laplace::one_over_r;
// ---------------------------------------
// The matrix kernel
static constexpr std::size_t nb_inputs_near{matrix_kernel_type::km};
static constexpr std::size_t nb_outputs_near{matrix_kernel_type::kn};
using particle_type =
scalfmm::container::particle<value_type, Dimension, value_type,
nb_inputs_near, value_type, nb_outputs_near,
std::size_t>;
using container_type = scalfmm::container::particle_container<particle_type>;
using position_type = typename particle_type::position_type;
using box_type = scalfmm::component::box<position_type>;
///
///////////////////////////////////////////////////////////////////////////////////
// parameters
const std::string input_file{parser.template get<local_args::input_file>()};
const std::string output_file{parser.template get<local_args::output_file>()};
const auto tree_height{parser.template get<args::tree_height>()};
/// Read the particles data
scalfmm::container::point<value_type, Dimension> box_center{};
value_type box_width{};
std::vector<particle_type> container{};
std::size_t number_of_particles{0};
if (input_file.empty()) {
std::cerr << scalfmm::colors::red << "input file is empty !\n";
return 0;
} else {
number_of_particles = read_data(para, input_file, container, box_center, box_width);
}
box_type box(box_width, box_center);
std::cout << scalfmm::colors::green << "... Done.\n"
<< scalfmm::colors::reset;
std::cout << scalfmm::colors::green << "Box center = " << box_center
<< " box width = " << box_width << scalfmm::colors::reset << '\n';
////
/// \brief build_distrib
auto level = tree_height - 1;
std::vector<int> index_dist;
build_distrib(para, container, number_of_particles, box, level, index_dist);
build_matrix();
////
para.end();
return 0;
}
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int {
parallel_manager para;
para.init();
//
// Parameter handling
auto parser = inria::tcli::make_parser(
inria::tcli::help{},
local_args::input_file{}, local_args::output_file{},
local_args::dimension{},args::tree_height{} );
parser.parse(argc, argv);
const std::size_t dimension = parser.get<local_args::dimension>();
switch(dimension)
{
case 2:
{
constexpr std::size_t dim = 2;
return run<dim>(parser,para);
break;
}
case 3:
{
constexpr std::size_t dim = 3;
return run<dim>(parser,para);
break;
}
default:
std::cout << "check 1/r Kernel for dimension 2 and 3. Value is \n"
<< " 2 for dimension 2 "
<< " 3 for dimension 3 " << std::endl;
break;
}
}
......@@ -52,8 +52,8 @@ namespace scalfmm::container
using proxy_type = typename Particle::proxy_type;
using const_proxy_type = typename Particle::const_proxy_type;
// Forwarding constructors
using base_type::base_type;
// Forwarding constructors
using base_type::base_type;
/// @brief
///
......
......@@ -1420,6 +1420,33 @@ namespace scalfmm::tree
<< std::endl;
}
template<typename Vector_type, typename Box_type>
void sort_particles_inplace(parallel_manager& manager, Vector_type& particle_container, const Box_type& box,
const int& leaf_level)
{
// out::print("rank(" + std::to_string(rank) + ") partArray ori: ", particle_container);
#ifdef SCALFMM_USE_MPI
inria::mpi_config conf(manager.get_communicator());
inria::sort(manager.get_communicator(), particle_container,
[&box, &leaf_level](const auto& p1, const auto& p2) {
auto m1 = scalfmm::index::get_morton_index(p1.position(), box, leaf_level);
auto m2 = scalfmm::index::get_morton_index(p2.position(), box, leaf_level);
return m1 < m2;
});
#else
std::sort(particle_container.begin(), particle_container.end(),
[&box, &leaf_level](const auto& p1, const auto& p2) {
auto m1 = scalfmm::index::get_morton_index(p1.position(), box, leaf_level);
auto m2 = scalfmm::index::get_morton_index(p2.position(), box, leaf_level);
return m1 < m2;
});
#endif
// out::print("rank(" + std::to_string(rank) + ") partArray final: ", particle_container);
}
///
/// \brief buildLetTree Build the let of the tree and the leaves and cells distributions
///
......@@ -1462,11 +1489,16 @@ namespace scalfmm::tree
auto nb_part = particle_container.size();
/// Sort the particles at the leaf level
///
// out::print("rank(" + std::to_string(rank) + ") partArray : ", particle_container);
// std::cout << " leaf_level: " << leaf_level << std::endl;
// out::print("rank(" + std::to_string(rank) + ")
// partArray : ", particle_container);
// std::cout << " leaf_level: " << leaf_level <<
// std::endl;
///
/// Sort the particles at the leaf level
///
#ifndef OLD_VERSION
sort_particles_inplace(manager, particle_container, box, leaf_level);
#else
#ifdef SCALFMM_USE_MPI
inria::mpi_config conf(manager.get_communicator());
......@@ -1486,7 +1518,7 @@ namespace scalfmm::tree
return m1 < m2;
});
#endif
// out::print("rank(" + std::to_string(rank) + ") partArray final: ", particle_container);
#endif
///
//
// std::cout << "sort at level " << level << " box " << box << std::endl;
......@@ -1526,7 +1558,7 @@ namespace scalfmm::tree
///
/// A morton index should be own by only one process
///
morton_distrib_type particles_distrib;
morton_distrib_type particles_distrib(manager.get_num_processes());
if(use_particle_distribution)
{
particles_distrib = std::move(
......@@ -1602,7 +1634,7 @@ namespace scalfmm::tree
// std::cout << "END LEAF LEVEL " << std::endl;
// std::cout << scalfmm::colors::reset;
/// If the distribution is not the same for the leaf and the cell we redistribute the
/// morton index according to ta unifom distribution of morton index
/// morton index according to the unifom distribution of morton index
///
//////////////////////////////////////////////////////////////////
/// Construct a uniform distribution of the morton index
......
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