1 #ifndef QNANO_NEW_DISTRIBUTE_BLOCK_DEFINED_H_ 2 #define QNANO_NEW_DISTRIBUTE_BLOCK_DEFINED_H_ 15 size_t get_total_size()
const{
return total_size;}
16 size_t get_nr_blocks()
const{
return nr_blocks;}
17 size_t get_floor_blocksize()
const 19 return get_total_size()/get_nr_blocks();
21 size_t get_blocksize(
size_t bl)
const 23 if(bl<0 || bl>=nr_blocks)
25 std::cerr<<
"DistributeBlock out of bound: "<<bl<<
"/"<<nr_blocks<<std::endl
29 else if(bl<nr_onemore)
31 return get_total_size()/get_nr_blocks()+1;
35 return get_total_size()/get_nr_blocks();
38 size_t get_start(
size_t bl)
const 40 if(bl<0 || bl>=get_nr_blocks())
42 std::cerr<<
"DistributeBlock out of bound: "<<bl<<
"/"<<get_nr_blocks()<<std::endl;
47 return bl*get_blocksize(0);
51 return bl*get_floor_blocksize()+nr_onemore;
54 size_t lookup_element(
size_t el)
const 56 size_t max_size_before_onemore = (get_floor_blocksize()+1)*nr_onemore;
57 if(el<max_size_before_onemore)
return el/(get_floor_blocksize()+1);
58 return (el-max_size_before_onemore)/(get_floor_blocksize())+nr_onemore;
60 virtual void print()
const 62 for(
size_t i=0;i<get_nr_blocks();i++){
63 std::cout<<i<<
": start: "<<get_start(i)<<
" blocksize: "<<get_blocksize(i)<<std::endl;
66 void initialize(
size_t total_size_,
size_t nr_blocks_)
68 total_size=total_size_;
70 size_t div=total_size/nr_blocks;
71 nr_onemore=total_size-div*nr_blocks;
75 initialize(total_size_, nr_blocks_);
Definition: Distribute_Block.h:7