Commit ab595023 authored by DUFOYER Benjamin's avatar DUFOYER Benjamin

Add Creation of GroupLetTree

parent 824bbc34
#ifndef _FGROUP_LINEAR_TREE_HPP_
#define _FGROUP_LINEAR_TREE_HPP_
#include <vector>
#include "../../Utils/FLog.hpp"
#include "FDistributedGroupTreeBuilder.hpp"
using FReal = double;
template<class node_t>
class FGroupLinearTree {
protected:
int block_size;
int nb_block;
std::vector<node_t>* linear_tree;
std::vector<std::pair<unsigned long long int,unsigned long long int>> particle_repartition;
public:
////////////////////////////////////////////////
// constructor
////////////////////////////////////////////////
/**
* FBlockedLinearTree Constructor of blocked linear tree
* @author benjamin.dufoyer@inria.fr
* @param in_block_size Block size needed
* @param in_linear_tree Linear tree
* @param in_box_center Box Center of particle container
* @param in_box_width Box Width of particle container
*/
FGroupLinearTree(){}
/**
* This function create a blocked linear tree from the current distributed
* linear tree
* This function stock the linear tree with his adress
* @author benjamin.dufoyer@inria.fr
* @param in_linear_tree linear tree
* @param in_block_size block size
*/
void create_local_blocked_linear_tree(
std::vector<node_t>* in_linear_tree,
int in_block_size
){
this->create(in_linear_tree,in_block_size);
}
/**
* this function create a blocked linear tree from the current distributed
* linear tree and she redistribute block according to the block size
* the function stock the linear tree with his adress
* @author benjamin.dufoyer@inria.fr
* @param in_linear_tree linear tree
* @param in_block_size blocksize needed
* @param conf [description]
*/
void create_global_blocked_linear_tree(
std::vector<node_t>* in_linear_tree,
int in_block_size,
const inria::mpi_config& conf
){
this->create(in_linear_tree,in_block_size);
this->redistribute_block(conf);
}
void create(
std::vector<node_t>* in_linear_tree,
int in_block_size
){
this->block_size = in_block_size;
this->linear_tree = in_linear_tree;
this->nb_block = (int)in_linear_tree->size()/in_block_size;
if(this->linear_tree->size()%this->block_size != 0)
this->nb_block += 1;
}
////////////////////////////////////////////////
// destructor
////////////////////////////////////////////////
~FGroupLinearTree(){
linear_tree = nullptr;
}
////////////////////////////////////////////////
// Function
////////////////////////////////////////////////
/**
* redistribute_block redistribute leaf of the linear_tree with the good
* block size. For N proc, N-1 proc have the same number of leaf,
* the rest is for the proc N
* @author benjamin.dufoyer@inria.fr
* @param conf mpi configuration to work with the other process
*/
void redistribute_block(const inria::mpi_config& conf){
dstr_grp_tree_builder::parrallel_build_block(
conf,
this->linear_tree,
this->block_size);
//Update nb_block
if(this->linear_tree->size()%block_size == 0)
this->nb_block = (int)this->linear_tree->size()/block_size;
else
this->nb_block = (int)this->linear_tree->size()/block_size+1;
}
size_t get_nb_leaf() const{
return this->linear_tree->size();
}
int get_nb_block() const{
return this->nb_block;
}
int get_block_size() const{
return this->block_size;
}
/**
* get_block_size_at return the block size of the number of the block
* placed in parametter,
* [INFO] first block is 0
* [INFO] last block is this->nb_block-1
* @author benjamin.dufoyer@inria.fr
* @param num_block number of the block
* @return size of the block
*/
int get_block_size_at(int num_block) const{
FAssertLF(num_block < this->nb_block);
int size;
if(num_block == this->nb_block-1){
size = this->linear_tree->size() - ((this->nb_block-1)*this->block_size);
} else {
size = this->block_size;
}
return size;
}
/**
* get_leaf_at return the leaf at the position placed in parameter
* @author benjamin.dufoyer@inria.fr
* @param position position of the leaf
* @return the leaf
*/
node_t get_leaf_at(int position){
return this->linear_tree->at(position);
}
/**
* get_leaf_at return the leaf at the position placed in parameter
* @author benjamin.dufoyer@inria.fr
* @param position position of the leaf
* @return the leaf
*/
node_t at(int position){
return this->get_leaf_at(position);
}
size_t get_leaf_level() const{
return this->linear_tree->back().level;
}
size_t get_tree_height() const{
return this->get_leaf_level();
}
size_t get_first_morton_index(){
return this->linear_tree->front().morton_index;
}
size_t get_last_morton_index(){
return this->linear_tree->back().morton_index;
}
void print_info_tree(){
std::cout << " nb_leaf : " << this->linear_tree->size() << std::endl;
std::cout << " nb_block : " << nb_block << std::endl;
std::cout << " block_size : " << block_size << std::endl;
for(int i = 0 ; i < this->linear_tree->size() ; i++){
std::cout << linear_tree->at(i) << std::endl;
}
}
std::vector<node_t>* get_tree(){
return this->linear_tree;
}
/**
* This function fill the particle_repartition with a call of the function
* from FDistributedGroupTreeBuilder
* @author benjamin.dufoyer@inria.fr
* @param conf [description]
* @param particle_container [description]
*/
template<class particle_t>
void set_particle_repartition(const inria::mpi_config& conf,
std::vector<particle_t> particle_container)
{
this->particle_repartition.resize(conf.comm.size());
dstr_grp_tree_builder::know_particle_division(
conf,
particle_container,
particle_repartition);
}
std::vector<std::pair<unsigned long long int,unsigned long long int>>*
get_particle_repartition(){
return &this->particle_repartition;
}
std::pair<unsigned long long int,unsigned long long int> get_particle_repartition_at(unsigned i){
FAssert(i < this->particle_repartition.size());
return this->particle_repartition.data()[i];
}
/**
* This function call a couple of function who add the LET part of the
* groupTree
* @author benjamin.dufoyer@inria.fr
* @param tree local group tree
*/
template<class GroupTreeClass>
void create_let_group_tree(
GroupTreeClass& tree,
const inria::mpi_config& conf,
int dim = 3){
FAssert(particle_repartition.size() != 0 );
// Compute min and max global morton index
const MortonIndex global_min_m_idx = this->particle_repartition.front().first;
const MortonIndex global_max_m_idx = this->particle_repartition.back().second;
// Compute min and max local morton index
const MortonIndex local_min_m_idx = tree.getParticleGroup(0)->getStartingIndex();
const MortonIndex local_max_m_idx = tree.getParticleGroup( (tree.getNbParticleGroup()-1) )->getEndingIndex();
// get leaf P2P
std::vector<size_t> leaf_P2P = dstr_grp_tree_builder::get_leaf_P2P_interaction(
tree,
global_min_m_idx,
global_max_m_idx,
local_min_m_idx,
local_max_m_idx);
// get leaf M2L
std::vector<size_t> leaf_M2L =
dstr_grp_tree_builder::get_leaf_M2L_interaction(
global_min_m_idx,
global_max_m_idx,
local_min_m_idx,
local_max_m_idx,
tree,
dim);
// concat result
std::vector<size_t> needed_leaf = dstr_grp_tree_builder::concat_M2L_P2P(leaf_P2P,leaf_M2L);
// Creation of interaction matrice
std::vector<size_t> global_matrix_interaction = dstr_grp_tree_builder::get_matrix_interaction(
needed_leaf,
particle_repartition,
conf);
// Send and get leaf
auto let_block = dstr_grp_tree_builder::send_get_symbolic_leaf(
needed_leaf,
global_matrix_interaction,
tree,
conf);
dstr_grp_tree_builder::add_let_block_to_tree(
tree,
let_block,
local_min_m_idx);
}
};
#endif //_FGROUP_LINEAR_TREE_HPP_
This diff is collapsed.
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