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

Check a random bug in Let construction

parent aa5c38ff
......@@ -205,7 +205,7 @@ auto main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) -> int
///
///////////////////////////////////////////////////////////////////////////////////////////////////////
delete letGroupTree;
// delete letGroupTree;
para.end();
return 0;
......
......@@ -39,14 +39,16 @@ namespace scalfmm::component
void set_leaf_distribution(const data_distrib_type& in_leaf_distrib)
{
// std::copy(in_leaf_distrib.begin(), in_leaf_distrib.end(), m_leaf_distrib.begin());
m_leaf_distrib = in_leaf_distrib;
m_leaf_distrib.resize(in_leaf_distrib.size());
std::copy(in_leaf_distrib.begin(), in_leaf_distrib.end(), m_leaf_distrib.begin());
// m_leaf_distrib = in_leaf_distrib;
}
void set_cell_distribution(const int in_level, const data_distrib_type& in_cell_distrib)
{
// std::copy(in_cell_distrib.begin(), in_cell_distrib.end(), m_cell_distrib[in_level].begin());
m_cell_distrib[in_level] = in_cell_distrib;
m_cell_distrib[in_level].resize(in_cell_distrib.size());
std::copy(in_cell_distrib.begin(), in_cell_distrib.end(), m_cell_distrib[in_level].begin());
// m_cell_distrib[in_level] = in_cell_distrib;
}
void print_distrib(std::ostream& out, bool verbose = true)
......@@ -67,6 +69,12 @@ namespace scalfmm::component
out::print(out, std::move(header), m_cell_distrib[l]);
}
}
~dist_group_tree()
{
std::cout << scalfmm::colors::red;
std::cout << " ~dist_group_tree() " << std::endl;
std::cout << scalfmm::colors::reset;
}
private:
std::vector<data_distrib_type> m_cell_distrib;
......
......@@ -792,11 +792,13 @@ namespace scalfmm::tree
inline auto build_upper_distribution(parallel_manager& para, const int& level, VectorMortonIdx& mortonCellIndex,
const MortonDistribution& cells_distrib) -> MortonDistribution
{
std::cout << scalfmm::colors::green << " --> Begin distrib::build_upper_distribution at level " << level
std::cout << scalfmm::colors::blue << " --> Begin distrib::build_upper_distribution at level " << level
<< scalfmm::colors::reset << std::endl;
std::cout << std::endl;
MortonDistribution parent_distrib(cells_distrib);
auto rank = para.get_process_id();
out::print("rank(" + std::to_string(rank) + ") cells_distrib: ", cells_distrib);
out::print("rank(" + std::to_string(rank) + ") mortonCellIndex: ", mortonCellIndex);
// get the parent distribution
for(auto& p: parent_distrib)
......@@ -806,11 +808,11 @@ namespace scalfmm::tree
}
/// Check if there are no shared bounds
///
auto local_right = parent_distrib[rank][1] << 2;
auto local_left = parent_distrib[rank][0] << 2;
// auto local_right = parent_distrib[rank][1] << 2;
// auto local_left = parent_distrib[rank][0] << 2;
bool need_comm = false;
std::size_t start = 0;
for(int p = 0; p < para.get_num_processes(); ++p)
for(int p = 0; p < para.get_num_processes() - 1; ++p)
{
if(parent_distrib[p][1] == parent_distrib[p + 1][0])
{
......@@ -857,6 +859,8 @@ namespace scalfmm::tree
{
mortonCellIndex[i] = mortonCellIndex[i] >> 2;
}
out::print("rank(" + std::to_string(rank) + ") mortonCellIndex: ", mortonCellIndex);
/// we have to remove some elements at the begining if start != 0
auto last = std::unique(mortonCellIndex.begin(), mortonCellIndex.end());
if(start > 0)
......@@ -871,7 +875,7 @@ namespace scalfmm::tree
}
out::print("rank(" + std::to_string(rank) + ") mortonCellIndex: ", mortonCellIndex);
std::cout << scalfmm::colors::green << " --> End distrib::build_upper_distribution at level " << level
std::cout << scalfmm::colors::blue << " --> End distrib::build_upper_distribution at level " << level
<< scalfmm::colors::reset << std::endl;
return parent_distrib;
}
......@@ -990,6 +994,7 @@ namespace scalfmm::tree
auto group_of_cell_begin = std::begin(*cell_level_it);
auto group_of_cell_end = std::end(*cell_level_it);
/// Get the theoretical M2L index
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) {
......@@ -1000,6 +1005,7 @@ namespace scalfmm::tree
// << cell_symbolics.number_of_neighbors << std::endl;
});
});
std::cout << " c--END FIRST PART " << std::endl;
///
/// Build a vector of morton indexes for all indexes outside my
......@@ -1012,19 +1018,19 @@ namespace scalfmm::tree
[&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;
std::cout << " cells " << cell.index();
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])
{
// keep only index inside the distribution
for(int r = 0; r < my_rank; ++r)
{
//
......@@ -1032,6 +1038,8 @@ namespace scalfmm::tree
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
std::cout << " -" << p;
break;
}
}
......@@ -1045,16 +1053,25 @@ namespace scalfmm::tree
if(between(p, interval[0], interval[1]))
{
outsideIndex_to_add.push_back(p);
std::cout << " +" << p;
break;
}
}
}
}
std::cout << std::endl << std::flush;
});
});
std::cout << " SORTTTTTTTT " << std::endl << std::flush;
std::sort(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
std::cout << " UNIQUE " << std::endl << std::flush;
auto last = std::unique(outsideIndex_to_add.begin(), outsideIndex_to_add.end());
std::cout << " ERASE " << std::endl << std::flush;
outsideIndex_to_add.erase(last, outsideIndex_to_add.end());
out::print("rank(" + std::to_string(my_rank) + ") outsideIndex_to_add : ", outsideIndex_to_add);
std::cout << scalfmm::colors::green << " --> End distrib::get_m2l_interaction_at_level "
<< scalfmm::colors::reset << std::endl;
return outsideIndex_to_add;
......@@ -1133,9 +1150,18 @@ namespace scalfmm::tree
}
}
///
/// \brief check if the morton index used in the vector of indexes exist
///
/// This step needs communication
/// \param para the parallel manager
/// \param needed_idx the index to check if they exits in the orther porcessors
/// \param distrib the index distribution on all processors
/// \param local_morton_idx My local morton index
///
template<typename VectorMortonIdx, typename MortonDistribution>
void check_if_morton_index_exist(parallel_manager& para, VectorMortonIdx& needed_idx,
const MortonDistribution distrib, const VectorMortonIdx& local_morton_idx)
const MortonDistribution& distrib, const VectorMortonIdx& local_morton_idx)
{
auto rank = para.get_process_id();
......@@ -1143,14 +1169,15 @@ namespace scalfmm::tree
<< scalfmm::colors::reset << std::endl;
using mortonIdx_type = typename VectorMortonIdx::value_type;
auto nb_proc = para.get_num_processes();
// auto rank = para.get_process_id();
std::vector<int> nb_messages_to_send(nb_proc, 0);
std::vector<int> nb_messages_to_receive(nb_proc, 0);
// beging index to send to process k
std::vector<int> start(nb_proc + 1, 0);
//
// Check the number of messages to send to the processes
// Check the number of messages to send to the processes = number of morton index insize the
// interval of the distribution
int k = 0;
int start_mine = 0;
start[nb_proc] = needed_idx.size();
for(std::size_t i = 0; i < needed_idx.size(); ++i)
{
......@@ -1160,27 +1187,28 @@ namespace scalfmm::tree
}
else
{
// find the new processor onwing the index
k = find_proc_for_index(needed_idx[i], distrib, k);
start[k] = i;
nb_messages_to_send[k]++;
}
}
start[rank] = start[rank + 1];
// out::print("rank(" + std::to_string(rank) + ") local_idx : ", local_morton_idx);
// out::print("rank(" + std::to_string(rank) + ") start : ", start);
// out::print("rank(" + std::to_string(rank) + ") needed_idx : ", needed_idx);
// out::print("rank(" + std::to_string(rank) + ") Nb msg send : ", nb_messages_to_send);
out::print("rank(" + std::to_string(rank) + ") local_idx : ", local_morton_idx);
out::print("rank(" + std::to_string(rank) + ") start : ", start);
out::print("rank(" + std::to_string(rank) + ") needed_idx : ", needed_idx);
out::print("rank(" + std::to_string(rank) + ") Nb msg send : ", nb_messages_to_send);
// exchange the vector all to all to know which process send us a
// message
auto comm = para.get_communicator();
auto mpi_type = inria::mpi::get_datatype<int>();
comm.alltoall(nb_messages_to_send.data(), 1, mpi_type, nb_messages_to_receive.data(), 1, mpi_type);
// out::print("rank(" + std::to_string(rank) + ") Nb msg receiv : ",
// nb_messages_to_receive);
out::print("rank(" + std::to_string(rank) + ") Nb msg receiv : ", nb_messages_to_receive);
// _to_send
// check if the morton index exist locally
// bad_index the largest morton index in the whole indexes + 1
auto bad_index = distrib[nb_proc - 1][1] + 1;
std::vector<inria::mpi::request> tab_mpi_status;
std::vector<mortonIdx_type*> buffer(nb_proc, nullptr);
......@@ -1197,8 +1225,7 @@ namespace scalfmm::tree
if(nb_messages_to_receive[i] != 0)
{
buffer[i] = new mortonIdx_type[nb_messages_to_receive[i]];
// std::cout << "Receive message from " << i << " of size " <<
// nb_messages_to_receive[i] << std::endl;
std::cout << "Receive message from " << i << " of size " << nb_messages_to_receive[i] << std::endl;
tab_mpi_status.push_back(comm.irecv(buffer[i], nb_messages_to_receive[i], mpi_type, i, 200));
}
}
......@@ -1229,6 +1256,9 @@ namespace scalfmm::tree
{
//‡ std::cout << ki << " " << elt[ki] << " " << start << "
//";
// check if morton index exists in my local morton vector
// if not we hust insert a teh bad_index in order not to change the size of the buddfer to
// send.
auto pos = find_index(elt[ki], local_morton_idx, start);
if(pos < 0)
{
......@@ -1279,6 +1309,7 @@ namespace scalfmm::tree
delete[] buffer[i];
}
}
// We remove the bad_index in order to have only the existing components (leaf/cell)
std::sort(needed_idx.begin(), needed_idx.end());
auto last = std::unique(needed_idx.begin(), needed_idx.end());
out::print("rank(" + std::to_string(rank) + ") needed_idx : ", needed_idx);
......@@ -1289,7 +1320,8 @@ namespace scalfmm::tree
needed_idx.erase(last, needed_idx.end());
out::print("rank(" + std::to_string(rank) + ") needed_idx : ", needed_idx);
std::cout << scalfmm::colors::green << " (" << rank << ") --> End distrib::check_if_morton_index_exist "
<< scalfmm::colors::reset << std::endl;
<< scalfmm::colors::reset << std::endl
<< std::flush;
}
} // namespace distrib
......@@ -1332,15 +1364,12 @@ namespace scalfmm::tree
// we compute the cells needed in the M2L operators
auto 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(m2l) ";
for(auto p: needed_idx)
{
std::cout << p << " ";
}
std::cout << std::endl;
out::print("rank(" + std::to_string(my_rank) + ") needed_idx(m2l) : ", needed_idx);
std::cout << std::flush;
/// Look if the morton index really exists in the distributed tree
distrib::check_if_morton_index_exist(para, needed_idx, cells_distrib, local_morton_idx);
out::print("rank(" + std::to_string(my_rank) + ") final idx(m2l) : ", needed_idx);
std::cout << std::flush;
///
tree.insert_cells_at_level(level, needed_idx);
std::cout << scalfmm::colors::green << " --> End let::build_let_at_level() at level = " << level
......@@ -1357,16 +1386,15 @@ namespace scalfmm::tree
// we compute the cells needed in the P2P operators
auto needed_idx = std::move(distrib::get_p2p_interaction(para, tree, local_morton_idx, leaves_distrib));
std::cout << "rank(" << my_rank << ") needed_idx(p2p) ";
for(auto p: needed_idx)
{
std::cout << p << " ";
}
std::cout << std::endl;
out::print("rank(" + std::to_string(my_rank) + ") needed_idx(p2p) : ", needed_idx);
std::cout << std::flush;
/// Look if the morton index really exists in the distributed tree
distrib::check_if_morton_index_exist(para, needed_idx, leaves_distrib, local_morton_idx);
///
out::print("rank(" + std::to_string(my_rank) + ") final idx(p2p) : ", needed_idx);
tree.insert_leaves(needed_idx);
std::cout << scalfmm::colors::green << " --> End let::build_let_leaves()" << scalfmm::colors::reset
<< std::endl;
......@@ -1551,6 +1579,11 @@ namespace scalfmm::tree
localGroupTree->set_leaf_distribution(particles_distrib);
std::cout << std::flush;
manager.get_communicator().barrier();
std::cout << scalfmm::colors::red;
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 have to redistribute the
/// morton index according to the good distribution
/// Todo inria::dist::distribute()
......@@ -1576,12 +1609,18 @@ namespace scalfmm::tree
/// Find and add the cells to add at the leaves level
std::vector<morton_distrib_type> level_dist(localGroupTree->height());
level_dist[leaf_level] = leaves_distrib;
manager.get_communicator().barrier();
build_let_at_level(manager, *localGroupTree, leafMortonIdx, level_dist[leaf_level], leaf_level);
localGroupTree->set_cell_distribution(leaf_level, level_dist[leaf_level]);
for(int l = leaf_level - 1; l >= localGroupTree->top_level(); --l)
{
std::cout << "level: " << l << " leaf_level " << leaf_level << "top "
std::cout << std::flush;
manager.get_communicator().barrier();
std::cout << scalfmm::colors::red;
std::cout << "level: " << l << " leaf_level " << leaf_level << " top "
<< localGroupTree->top_level() << std::endl;
std::cout << scalfmm::colors::reset;
level_dist[l] =
std::move(distrib::build_upper_distribution(manager, l, leafMortonIdx, level_dist[l + 1]));
out::print("rank(" + std::to_string(rank) + ") leafMortonIdx: ", leafMortonIdx);
......
......@@ -96,6 +96,8 @@ class parallel_manager
void end()
{
#ifdef SCALFMM_USE_MPI
m_communicator.barrier();
MPI_Finalize();
std::cout << " Fin version parallel" << std::endl;
#endif
......
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