Commit 1c56acd9 authored by COULAUD Olivier's avatar COULAUD Olivier
Browse files

Build morton indexes to add in the let (in progress)

parent ae020f59
......@@ -20,7 +20,7 @@ set(source_tests_files
# debug & check
count_kernel.cpp
test_l2p.cpp
# test-build-let.cpp
test-build-let.cpp
)
#if(SCALFMM_USE_MPI)
# set(source_tests_files ${source_tests_files}
......
......@@ -24,7 +24,7 @@
///
///
/// ./examples/RelWithDebInfo/test-build-let --input-file ../data/prolate.fma --order 3 --tree-height 4 --group-size 3
/// mpirun --oversubscribe -np 3 ./examples/RelWithDebInfo/test-build-let --input-file ../buildMPI/prolate.fma --order 3 --tree-height 4 --group-size 3
/// mpirun --oversubscribe -np 3 ./examples/RelWithDebInfo/test-build-let --input-file ../buildMPI/prolate.fma --order 3 --tree-height 3 --group-size 3
auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
{
......
......@@ -8,6 +8,9 @@
//#include <scalfmm/tree/group_linear_tree.hpp>
#include "scalfmm/container/particle_container.hpp"
#include "scalfmm/operators/generic/tags.hpp"
#include "scalfmm/tree/for_each.hpp"
#include "scalfmm/tree/interaction_list.hpp"
#include <scalfmm/tree/utils.hpp>
#include <scalfmm/utils/io_helpers.hpp> // for out::print
#include <scalfmm/utils/parallel_manager.hpp>
......@@ -24,6 +27,11 @@ namespace scalfmm::tree
{
namespace distrib
{
template<typename Index1_type, typename Index_type>
bool between(const Index1_type& m, const Index_type& mmin, const Index_type& mmax)
{
return (mmin <= m) && (m <= mmax);
};
///
/// \brief send_get_min_morton_idx send the morton index to the left and get value from the right
///
......@@ -487,9 +495,9 @@ namespace scalfmm::tree
const MortonDistrib_type& morton_dist)
{
using Morton_type = typename MortonArray_type::value_type;
auto between = [](const Morton_type& m, const Morton_type& mmin, const Morton_type& mmax) {
return (mmin <= m) && (m <= mmax);
};
// auto between = [](const Morton_type& m, const Morton_type& mmin, const Morton_type& mmax) {
// return (mmin <= m) && (m <= mmax);
// };
std::vector<int> message(morton_dist.size());
std::vector<std::array<int, 2>> details_partL(morton_dist.size(), {0, 0}),
details_partR(morton_dist.size(), {0, 0});
......@@ -759,20 +767,67 @@ namespace scalfmm::tree
const MortonDistribution& leaves_distrib)
{
auto leaf_level = tree.leaf_level();
VectorMortonIdx outsideIndex_to_add();
// leaf level update only P2P ???
// component::for_each(std::get<0>(tree.begin()), std::get<0>(tree.end()), [this](auto& group) {
// std::size_t index_in_group{0};
// component::for_each(std::begin(*group), std::end(*group), [&group, &index_in_group,
// this](auto& leaf) {
// auto& leaf_symbolics = leaf.symbolics();
// leaf_symbolics.interaction_list_exists = false;
// leaf_symbolics.interaction_list_iterators_exists = false;
// component::update_interaction_list(*group, leaf, index_in_group++, m_tree_height - 1);
// component::build_symbolic_interaction_list(operators::impl::tag_p2p t, leaf,
// leaf_level)
// });
// });
VectorMortonIdx outsideIndex_to_add;
///
/// Construct the p2p inteaction list or all leaves
///
component::for_each(std::get<0>(tree.begin()), std::get<0>(tree.end()), [&tree, &leaf_level](auto& group) {
// std::size_t index_in_group{0};
component::for_each(std::begin(*group), std::end(*group), [&group, &leaf_level, &tree](auto& leaf) {
auto& leaf_symbolics = leaf.symbolics();
leaf_symbolics.interaction_list_exists = false;
component::build_symbolic_interaction_list(operators::impl::tag_p2p{}, leaf, leaf_level);
});
});
///
/// Build a vector of morton indexes for all indexes outside my
/// distribution
///
auto morton_begin{leaves_distrib[0]}, morton_end{leaves_distrib[1]};
auto my_rank = para.get_process_id();
component::for_each(
std::get<0>(tree.begin()), std::get<0>(tree.end()),
[&morton_begin, &morton_end, &outsideIndex_to_add, &leaves_distrib, &my_rank](auto& group) {
component::for_each(
std::begin(*group), std::end(*group),
[&morton_begin, &morton_end, &outsideIndex_to_add, &leaves_distrib, &my_rank](auto& leaf) {
auto& leaf_symbolics = leaf.symbolics();
auto index = leaf_symbolics.interaction_indexes;
for(auto p: index)
{
if(p < leaves_distrib[my_rank][0])
{
for(int r = 0; r < my_rank; ++r)
{
//
const auto& interval = leaves_distrib[r];
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
break;
}
}
}
else if(p > leaves_distrib[my_rank][1])
{
for(int r = my_rank + 1; r < leaves_distrib.size(); ++r)
{
//
const auto& interval = leaves_distrib[r];
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
break;
}
}
}
}
});
});
std::sort(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
auto last = std::unique(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
outsideIndex_to_add.erase(last, outsideIndex_to_add.end());
return outsideIndex_to_add;
}
......@@ -781,7 +836,79 @@ namespace scalfmm::tree
const VectorMortonIdx& local_morton_idx,
const MortonDistribution& cell_distrib, const int& level)
{
VectorMortonIdx outsideIndex_to_add();
VectorMortonIdx outsideIndex_to_add;
auto my_rank = para.get_process_id();
///
/// Construct the p2p inteaction list or all leaves
///
auto cell_level_it = std::get<1>(tree.begin()) + (level);
auto group_of_cell_begin = std::begin(*cell_level_it);
auto group_of_cell_end = std::end(*cell_level_it);
component::for_each(group_of_cell_begin, group_of_cell_end, [level, my_rank](auto& group) {
std::size_t index_in_group{0};
component::for_each(std::begin(*group), std::end(*group), [level, my_rank](auto& cell) {
auto& cell_symbolics = cell.symbolics();
cell_symbolics.interaction_list_exists = false;
component::build_symbolic_interaction_list(operators::impl::tag_m2l{}, cell, level);
// std::cout << "rank(" << my_rank << ") index " << cell.index() << " "
// << cell_symbolics.number_of_neighbors << std::endl;
});
});
///
/// Build a vector of morton indexes for all indexes outside my
/// distribution
///
component::for_each(group_of_cell_begin, group_of_cell_end,
[&tree, level, &outsideIndex_to_add, &cell_distrib, &my_rank](auto& group) {
component::for_each(
std::begin(*group), std::end(*group),
[&outsideIndex_to_add, &cell_distrib, &my_rank, level](auto& cell) {
auto& cell_symbolics = cell.symbolics();
auto index = cell_symbolics.interaction_indexes;
// std::cout << "rank(" << my_rank <<
// ") index "; for(auto p: index)
// {
// std::cout << p << " ";
// }
std::cout << std::endl;
for(int idx = 0; idx < cell_symbolics.number_of_neighbors; ++idx)
{
auto& p = index[idx];
if(p < cell_distrib[my_rank][0])
{
for(int r = 0; r < my_rank; ++r)
{
//
const auto& interval = cell_distrib[r];
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
break;
}
}
}
else if(p > cell_distrib[my_rank][1])
{
for(int r = my_rank + 1; r < cell_distrib.size(); ++r)
{
//
const auto& interval = cell_distrib[r];
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
break;
}
}
}
}
});
});
std::sort(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
auto last = std::unique(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
outsideIndex_to_add.erase(last, outsideIndex_to_add.end());
return outsideIndex_to_add;
}
......@@ -806,9 +933,11 @@ namespace scalfmm::tree
dst.erase(last, dst.end());
return dst;
}
template<typename VectorMortonIdx>
void morton_index_exist(parallel_manager& para, VectorMortonIdx& needed_idx)
template<typename VectorMortonIdx, typename MortonDistribution>
void check_if_morton_index_exist(parallel_manager& para, VectorMortonIdx& needed_idx,
MortonDistribution distrib)
{
std::cout << "check_if_morton_index_exist in progress \n";
}
} // namespace distrib
......@@ -842,46 +971,33 @@ namespace scalfmm::tree
template<typename OctreeTree, typename VectorMortonIdx, typename MortonDistribution>
void build_let_at_level(parallel_manager& para, OctreeTree& tree, const VectorMortonIdx& local_morton_idx,
const MortonDistribution& leaves_distrib, const MortonDistribution& cells_distrib,
int& level)
const int& level)
{
auto my_rank = para.get_process_id();
// stock in the variable if we are at the leaf level
bool leaf_level = (tree.leaf_level() == level);
// update the morton index
// if(!leaf_level)
// {
// gmin = gmin >> 3;
// gmax = gmax >> 3;
// }
// const MortonIndex global_min_m_idx = gmin;
// const MortonIndex global_max_m_idx = gmax;
// // Compute min and max local morton index at the level
// needed if(this->getNbCellGroupAtLevel(level) > 0)
// {
// lmin = this->getCellGroup(level, 0)->getStartingIndex();
// lmax = this->getCellGroup(level,
// this->getNbCellGroupAtLevel(level) -
// 1)->getEndingIndex()
// - 1;
// }
// else
// {
// lmin = -1;
// lmax = -1;
// }
// const MortonIndex local_min_m_idx = lmin;
// const MortonIndex local_max_m_idx = lmax;
// declare variable, needed because we fill it in a if case
VectorMortonIdx needed_idx;
if(leaf_level)
{
// we compute the cells needed in the M2L operators
auto m2l_idx = std::move(
distrib::get_m2l_interaction_at_level(para, tree, local_morton_idx, cells_distrib, leaf_level));
auto m2l_idx = std::move(distrib::get_m2l_interaction_at_level(para, tree, local_morton_idx,
cells_distrib, tree.leaf_level()));
// we compute the cells needed in the P2P operators
auto p2p_idx = std::move(get_p2p_interaction(para, tree, local_morton_idx, leaves_distrib));
auto p2p_idx = std::move(distrib::get_p2p_interaction(para, tree, local_morton_idx, leaves_distrib));
// wemerge the two contributions
std::cout << "rank(" << my_rank << ") m2l_idx ";
for(auto p: m2l_idx)
{
std::cout << p << " ";
}
std::cout << std::endl;
std::cout << "rank(" << my_rank << ") p2p_idx ";
for(auto p: p2p_idx)
{
std::cout << p << " ";
}
std::cout << std::endl;
needed_idx = distrib::merge_unique(m2l_idx, p2p_idx);
}
else
......@@ -890,9 +1006,14 @@ namespace scalfmm::tree
needed_idx =
std::move(distrib::get_m2l_interaction_at_level(para, tree, local_morton_idx, cells_distrib, level));
}
std::cout << "rank(" << my_rank << ") needed_idx ";
for(auto p: needed_idx)
{
std::cout << p << " ";
}
std::cout << std::endl;
/// Look if the morton index really exists in the distributed tree
distrib::morton_index_exist(para, needed_idx);
distrib::check_if_morton_index_exist(para, needed_idx);
///
tree.insert_component_at_level(level, needed_idx);
}
......@@ -910,7 +1031,7 @@ namespace scalfmm::tree
template</*typename Loader_type,*/ typename Index_type, typename Vector_type, typename Tree_type,
typename Box_type>
void buildLetTree(parallel_manager& manager, const std::size_t& number_of_particles,
Vector_type& particle_container, const Box_type& box, const int leaf_level,
Vector_type& particle_container, const Box_type& box, const int& leaf_level,
const int groupSizeLeaves, const int groupSizeCells, Tree_type*& localGroupTree,
std::vector<Index_type>& m_idx_distribution, int& nb_blocks, const int order)
{
......@@ -1022,11 +1143,13 @@ namespace scalfmm::tree
localGroupTree = new Tree_type(static_cast<std::size_t>(leaf_level + 1), order, box,
static_cast<std::size_t>(groupSizeCells), container);
///
/// Construct the let according to the distributions particles and cells
/// Construct the let according to the distributions particles and
/// cells
///
if(manager.get_num_processes() > 1)
{
build_let_at_level(localGroupTree, leafMortonIdx, particles_distrib, cells_distrib, leaf_level)
build_let_at_level(manager, *localGroupTree, leafMortonIdx, particles_distrib, cells_distrib,
leaf_level);
}
}
......
......@@ -17,6 +17,7 @@
#include "scalfmm/operators/generic/tags.hpp"
#include "scalfmm/tree/box.hpp"
#include "scalfmm/tree/for_each.hpp"
#include "scalfmm/tree/group.hpp"
#include "scalfmm/tree/interaction_list.hpp"
#include "scalfmm/tree/utils.hpp"
......
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