Commit 8b27a368 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

End first step test-compose. add verbose mode in fmaloader

parent 749f6a3e
......@@ -68,7 +68,8 @@ template<int Dimension>
void change_format(const std::string& input_file, bool& use_old_format, const std::string& visu_file,
const std::string& output_file)
{
scalfmm::tools::FFmaGenericLoader<value_type, Dimension> loader(input_file, use_old_format);
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<value_type, Dimension> loader(input_file, verbose, use_old_format);
const auto NbPoints = loader.getNumberOfParticles();
const auto nbData = loader.getNbRecordPerline();
......
......@@ -193,9 +193,10 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
}
std::vector<int> index;
index = parser.get<local_args::index_to_compare>();
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<value_type, dimension> loader1(filename1);
scalfmm::tools::FFmaGenericLoader<value_type, dimension> loader2(filename2);
scalfmm::tools::FFmaGenericLoader<value_type, dimension> loader1(filename1, verbose);
scalfmm::tools::FFmaGenericLoader<value_type, dimension> loader2(filename2, verbose);
//
// Allocation
......
......@@ -148,7 +148,8 @@ auto run(const int& tree_height, const int& group_size, const bool readFile, std
using particle_type = scalfmm::container::particle<double, Dimension, double, number_of_physical_values, double, 1>;
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, number_of_physical_values, 1>>;
using cell_type =
scalfmm::component::cell<scalfmm::component::grid_storage<double, Dimension, number_of_physical_values, 1>>;
using leaf_type = scalfmm::component::leaf<particle_type>;
using box3_type = scalfmm::component::box<position_type>;
using group_tree_type = scalfmm::component::group_tree<cell_type, leaf_type, box3_type>;
......@@ -162,7 +163,9 @@ auto run(const int& tree_height, const int& group_size, const bool readFile, std
std::size_t number_of_particles{};
if(readFile) // Read particles from a file
{
scalfmm::tools::FFmaGenericLoader<double, Dimension> loader(input_file);
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<double, Dimension> loader(input_file, verbose);
number_of_particles = loader.getNumberOfParticles();
box_width = loader.getBoxWidth();
......
......@@ -43,8 +43,9 @@ namespace laplace
{
// std::cout << "READ DATA " << std::endl << std::flush;
using particle_type = typename CONTAINER_T::particle_type;
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<VALUE_T, dimension> loader(filename);
scalfmm::tools::FFmaGenericLoader<VALUE_T, dimension> loader(filename, verbose);
const int number_of_particles = loader.getNumberOfParticles();
width = loader.getBoxWidth();
......
......@@ -76,7 +76,8 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
std::cout << scalfmm::colors::blue << "<params> Output file : " << output_file << scalfmm::colors::reset
<< '\n';
}
scalfmm::tools::FFmaGenericLoader<value_type> loader(input_file);
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<value_type> loader(input_file, verbose);
//
auto nb_particles = loader.getNumberOfParticles();
const unsigned int n_data_per_particle = loader.getNbRecordPerline();
......
......@@ -101,7 +101,7 @@ auto run(parallel_manager& para, const std::string& input_file, const std::strin
///
/// 1) read constants of the problem in file;
/// 2) each processor read N/P particles
scalfmm::tools::DistFmaGenericLoader<value_type, dimension> loader(input_file, para);
scalfmm::tools::DistFmaGenericLoader<value_type, dimension> loader(input_file, para, para.io_master());
//
const std::size_t number_of_particles = loader.getNumberOfParticles();
const int local_number_of_particles = loader.getMyNumberOfParticles();
......
#include <vector>
#include <algorithm>
#include <vector>
//
// ScalFMM includes
//
#include "parameters.hpp"
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/matrix_kernels/laplace.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"
#include <scalfmm/utils/io_helpers.hpp> // for out::print
//
// Maphyspp includes
//
//#include <maphys.hpp>
//#include <maphys/loc_data/DenseMatrix.hpp>
///
/////////////////////////////////////////////////////////////////
///
/// Example to run the program
///
/// seq
/// ./examples/Release/test-compose --input-file ../data/debug/circle2d_r3.fma --dimension 2 --tree-height 2
///
/// parallel
///
/////////////////////////////////////////////////////////////////
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;
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);
scalfmm::tools::DistFmaGenericLoader<ValueType, Dimension> loader(filename, para, para.io_master());
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;
}
container[idx] = p;
}
return number_of_particles;
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
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_blocs)
{
// using morton_type = std::size_t;
using index_type = std::int64_t;
using morton_distrib_type = std::array<index_type, 2>;
///
/// sort particles according to their Morton index
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
///
for(std::size_t part = 0; part < localNumberOfParticles; ++part)
{
leafMortonIdx[part] = scalfmm::index::get_morton_index(particle_container[part].position(), box, level);
}
/// construct the particle distribution particles_distrib and in
/// leafMortonIdx whe have the lorton index of the leaf = blocs
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));
// the morton index of the leaf
auto last = std::unique(leafMortonIdx.begin(), leafMortonIdx.end());
leafMortonIdx.erase(last, leafMortonIdx.end());
/// Put the particles on the good processor
scalfmm::tree::distrib::fit_particles_in_distrib(para, particle_container, leafMortonIdx, particles_distrib, box,
level, number_of_particles);
///
/// build the distribution of rows/column or columns per leaf or bloc )
///
auto nbBlocs = leafMortonIdx.size();
index_blocs.resize(nbBlocs + 1, 0);
std::size_t row{0};
index_blocs[nbBlocs] = particle_container.size();
auto rank = para.get_process_id();
auto myDistrib = particles_distrib[rank];
// scalfmm::out::print("rank(" + std::to_string(rank) + ") particles_distrib: ", particles_distrib);
// scalfmm::out::print("rank(" + std::to_string(rank) + ") leafMortonIdx: ", leafMortonIdx);
auto nb_part = particles_distrib.size();
for(std::size_t b = 0; b < nbBlocs - 1; ++b)
{
while(scalfmm::index::get_morton_index(particle_container[row].position(), box, level) == leafMortonIdx[b])
{
row++;
}
index_blocs[b + 1] = row;
}
// std::cout << "Bloc distribution of rows: " << nbBlocs << std::endl;
// scalfmm::out::print("rank(" + std::to_string(rank) + ") blocs: ", blocs);
// // Check the output
// std::cout << "Particles \n";
// for(std::size_t p = 0; p < particle_container.size(); ++p)
// {
// std::cout << p << " " << particle_container[p] << " "
// << scalfmm::index::get_morton_index(particle_container[p].position(), box, level) << std::endl;
// }
// //
// std::cout << "Bloc distribution of rows:\n ";
// scalfmm::out::print("rank(" + std::to_string(rank) + ") blocs: ", blocs);
}
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);
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>;
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);
///
///////////////////////////////////////////////////////////////////////////////////
// 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>()};
build_matrix();
/// 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);
if(para.io_master())
{
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);
//
auto rank = para.get_process_id();
scalfmm::out::print("rank(" + std::to_string(rank) + ") blocs distrib: ", index_dist);
build_matrix();
////
para.end();
////
para.end();
return 0;
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)
{
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;
constexpr std::size_t dim = 2;
return run<dim>(parser,para);
break;
return run<dim>(parser, para);
break;
}
case 3:
{
constexpr std::size_t dim = 3;
return run<dim>(parser,para);
break;
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;
}
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;
}
}
......@@ -89,7 +89,9 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
scalfmm::container::point<double, dimension> box_center{};
double box_width{};
scalfmm::tools::FFmaGenericLoader<double, dimension> loader(input_file);
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<double, dimension> loader(input_file, verbose);
box_center = scalfmm::container::point<double, dimension>{loader.getBoxCenter()[0], loader.getBoxCenter()[1],
loader.getBoxCenter()[2]};
......

#include <array>
#include <array>
#include <bits/c++config.h>
#include <chrono>
#include <cstdio>
......@@ -21,6 +19,7 @@
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/container/point.hpp"
#include "scalfmm/interpolation/grid_storage.hpp"
#include "scalfmm/operators/generic/tags.hpp"
#include "scalfmm/tools/colorized.hpp"
#include "scalfmm/tree/box.hpp"
......@@ -30,7 +29,6 @@
#include "scalfmm/utils/sort.hpp"
#include "scalfmm/utils/tensor.hpp"
#include "scalfmm/utils/timer.hpp"
#include "scalfmm/interpolation/grid_storage.hpp"
using Value_type = double;
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
......@@ -83,7 +81,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
// number_of_physical_values, Value_type, 1>;
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 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>;
......
......@@ -4,6 +4,7 @@
#include "scalfmm/container/particle.hpp"
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/container/point.hpp"
#include "scalfmm/interpolation/grid_storage.hpp"
#include "scalfmm/tools/colorized.hpp"
#include "scalfmm/tools/fma_loader.hpp"
#include "scalfmm/tree/box.hpp"
......@@ -12,7 +13,6 @@
#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>
......@@ -86,7 +86,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
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 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>;
......@@ -98,7 +98,9 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
scalfmm::container::point<double, dimension> box_center{};
double box_width{};
scalfmm::tools::FFmaGenericLoader<double> loader(input_file);
bool verbose = true;
scalfmm::tools::FFmaGenericLoader<double> loader(input_file, verbose);