Commit 94de3af9 authored by DUFOYER Benjamin's avatar DUFOYER Benjamin

Modification of blocked linear tree + adding GroupTree building from blocked linear tree

parent c9c0457e
......@@ -12,11 +12,7 @@ class FBlockedLinearTree {
protected:
const int block_size;
int nb_leaf;
const FPoint<FReal> box_center;
const FReal box_width;
int block_size;
int nb_block;
std::vector<node_t>* linear_tree;
......@@ -28,46 +24,65 @@ public:
////////////////////////////////////////////////
/**
* FBlockedLinearTree This constructer create a blocked linear tree
* from a linear tree. This linear tree will be balanced BEFORE calling
* this constructer
* FBlockedLinearTree Constructor of blocked linear tree
* @author benjamin.dufoyer@inria.fr
* @param in_linear_tree current linear_tree
* @param in_block_size block_size needed
* @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
*/
FBlockedLinearTree(const int in_block_size ,std::vector<node_t>* in_linear_tree
, FPoint<FReal> in_box_center, FReal in_box_width):
block_size(in_block_size),
nb_leaf((int)in_linear_tree->size()),
box_center(in_box_center),
box_width(in_box_width)
{
init_blocked_linear_tree(in_linear_tree);
}
template<class Box>
FBlockedLinearTree(const int in_block_size, std::vector<node_t>* in_linear_tree,const Box box,int dim = 3):
block_size(in_block_size),
nb_leaf((int)in_linear_tree->size()),
box_center(box.center()),
box_width(box.width(dim))
{
init_blocked_linear_tree(in_linear_tree);
}
void init_blocked_linear_tree(std::vector<node_t>* in_linear_tree){
if(this->nb_leaf%this->block_size == 0)
this->nb_block = this->nb_leaf/this->block_size;
else
this->nb_block = this->nb_leaf/this->block_size+1;
std::swap(in_linear_tree,this->linear_tree);
FBlockedLinearTree(){}
/**
* 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
////////////////////////////////////////////////
~FBlockedLinearTree(){
//delete linear_tree;
linear_tree = nullptr;
}
////////////////////////////////////////////////
......@@ -82,22 +97,21 @@ public:
* @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_leaf and nb_block
this->nb_leaf = (int)this->linear_tree->size();
if(nb_leaf%block_size == 0)
this->nb_block = nb_leaf/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 = nb_leaf/block_size+1;
this->nb_block = (int)this->linear_tree->size()/block_size+1;
}
int get_nb_leaf() const{
return this->nb_leaf;
size_t get_nb_leaf() const{
return this->linear_tree->size();
}
int get_nb_block() const{
......@@ -121,29 +135,13 @@ public:
FAssertLF(num_block < this->nb_block);
int size;
if(num_block == this->nb_block-1){
size = this->nb_leaf - ((this->nb_block-1)*this->block_size);
size = this->linear_tree->size() - ((this->nb_block-1)*this->block_size);
} else {
size = this->block_size;
}
return size;
}
int get_idx_first_cell_for_block(int num_block){
FAssertLF(num_block < this->nb_block);
return this->block_size * num_block;
}
int get_idx_last_cell_for_block(int num_block){
FAssertLF(num_block < this->nb_block);
int last;
//if it's the last block
if(num_block == (this->nb_block-1))
last = nb_leaf-1;
else
last = (this->block_size * (num_block+1))-1;
return last;
}
/**
* get_leaf_at return the leaf at the position placed in parameter
* @author benjamin.dufoyer@inria.fr
......@@ -151,12 +149,21 @@ public:
* @return the leaf
*/
node_t get_leaf_at(int position){
FAssertLF(position < this->nb_leaf && position >=0);
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->front().level;
return this->linear_tree->back().level;
}
size_t get_tree_height() const{
......@@ -168,26 +175,22 @@ public:
}
size_t get_last_morton_index(){
return linear_tree->back().morton_index;
return this->linear_tree->back().morton_index;
}
void print_info_tree(){
std::cout << " nb_leaf : " << nb_leaf << std::endl;
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 < nb_leaf ; i++){
for(int i = 0 ; i < this->linear_tree->size() ; i++){
std::cout << linear_tree->at(i) << std::endl;
}
}
FPoint<FReal> get_box_center() const{
return this->box_center;
}
FReal get_box_width() const {
return this->box_width;
std::vector<node_t>* get_tree(){
return this->linear_tree;
}
};
#endif //_FBLOCKED_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