Commit 891fef3d authored by cheesema's avatar cheesema
Browse files

Minor bug fix with boundary issues on random iterators

parent 14e180df
......@@ -61,14 +61,16 @@ int main(int argc, char **argv) {
///
////////////////////////
std::cout << "Search for a Particle Cell that may not exist at (x,y,z,l) = (10,10,10,4)" << std::endl;
srand (time(NULL));
std::cout << "Search for a Particle Cell that may not exist at random (x,y,z) and level = level_max" << std::endl;
std::cout << "--------------------" << std::endl;
ParticleCell random_particle_cell;
random_particle_cell.x = 1;
random_particle_cell.y = 2;
random_particle_cell.z = 5;
random_particle_cell.level = apr.level_max() - 1;
random_particle_cell.x = (uint16_t)(apr.orginal_dimensions(1)-1)*((rand() % 10000)/10000.0f);
random_particle_cell.y = (uint16_t)(apr.orginal_dimensions(0)-1)*((rand() % 10000)/10000.0f);
random_particle_cell.z = (uint16_t)(apr.orginal_dimensions(2)-1)*((rand() % 10000)/10000.0f);
random_particle_cell.level = apr.level_max();
bool found = apr_iterator.set_iterator_by_particle_cell(random_particle_cell);
......@@ -78,211 +80,35 @@ int main(int argc, char **argv) {
std::cout << "Particle Cell exists with global index (particle number): " << random_particle_cell.global_index << " and has intensity value: " << apr.particles_intensities[apr_iterator] << std::endl;
}
///////////////////////
///
/// Set the iterator using random access by using a global co-ordinate (in original pixels), and setting the iterator, to the Particle Cell that contains the point in its spatial domain.
///
////////////////////////
srand (time(NULL));
float x = apr.orginal_dimensions(1)*((rand() % 10000)/10000.0f);
float y = apr.orginal_dimensions(0)*((rand() % 10000)/10000.0f);
float z = apr.orginal_dimensions(2)*((rand() % 10000)/10000.0f);
found = apr_iterator.set_iterator_by_global_coordinate(x,y,z);
std::cout << std::endl;
std::cout << "Searching for Particle Cell thats spatial domain contains (x,y,z)=(" << x << "," << y << "," << z << ") " << std::endl;
std::cout << "--------------------" << std::endl;
if(!found){
std::cout << "out of bounds" << std::endl;
} else {
std::cout << "Particle Cell found is at level: " << apr_iterator.level() << " with x: " << apr_iterator.x() << " y: " << apr_iterator.y() << " z: " << apr_iterator.z() << std::endl;
std::cout << " with global index: " << apr_iterator.global_index() << " and intensity " << apr.particles_intensities[apr_iterator] << std::endl;
}
///
// Testing of the random access against some alternative strategies
//
//
//
ExtraPartCellData<uint16_t> y_b;
y_b.initialize_structure_parts_empty(apr);
ExtraPartCellData<uint16_t> hint;
hint.initialize_structure_parts_empty(apr);
timer.start_timer("allocate vec");
std::vector<uint16_t> test;
test.resize(100000000);
timer.stop_timer();
timer.start_timer("allocate pixeldata");
PixelData<uint16_t> pixelData;
pixelData.init(100000000,1,1);
timer.stop_timer();
timer.start_timer("APR serial iterator loop");
for (unsigned int level = apr_iterator.level_min(); level <= apr_iterator.level_max(); ++level) {
int z = 0;
int x = 0;
for (int i = 0; i < 10; ++i) {
y_b.data[level].resize(apr.apr_access.gap_map.x_num[level]*apr.apr_access.gap_map.z_num[level]);
hint.data[level].resize(apr.apr_access.gap_map.x_num[level]*apr.apr_access.gap_map.z_num[level]);
float x = (apr.orginal_dimensions(1) - 1) * ((rand() % 10000) / 10000.0f);
float y = (apr.orginal_dimensions(0) - 1) * ((rand() % 10000) / 10000.0f);
float z = (apr.orginal_dimensions(2) - 1) * ((rand() % 10000) / 10000.0f);
for (z = 0; z < apr_iterator.spatial_index_z_max(level); z++) {
for (x = 0; x < apr_iterator.spatial_index_x_max(level); ++x) {
size_t offset = apr.apr_access.gap_map.x_num[level]*z + x;
found = apr_iterator.set_iterator_by_global_coordinate(x, y, z);
if(level == apr.level_max()){
offset = apr.apr_access.gap_map.x_num[level]*(z/2) + (x/2);
}
std::cout << std::endl;
std::cout << "Searching for Particle Cell thats spatial domain contains (x,y,z)=(" << x << "," << y << "," << z << ") " << std::endl;
std::cout << "--------------------" << std::endl;
if(apr.apr_access.gap_map.data[level][offset].size()>0){
for(auto it = apr.apr_access.gap_map.data[level][offset][0].map.begin(); it != apr.apr_access.gap_map.data[level][offset][0].map.end();++it){
y_b.data[level][offset].push_back(it->first);
}
}
}
}
}
timer.stop_timer();
unsigned int rep = 4;
timer.start_timer("loop map");
for (int k = 0; k < rep; ++k) {
for (unsigned int level = apr_iterator.level_min(); level <= apr_iterator.level_max(); ++level) {
int z = 0;
int x = 0;
#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic) private(z, x) firstprivate(apr_iterator)
#endif
for (z = 0; z < apr_iterator.spatial_index_z_max(level); z++) {
for (x = 0; x < apr_iterator.spatial_index_x_max(level); ++x) {
size_t offset = apr.apr_access.gap_map.x_num[level] * z + x;
if (level == apr.level_max()) {
offset = apr.apr_access.gap_map.x_num[level] * (z / 2) + (x / 2);
}
size_t max_y = apr.apr_access.y_num[level];
ParticleCell pc;
pc.x = x;
pc.z = z;
pc.level = level;
pc.pc_offset = offset;
for (int i = 0; i < ceil(0.2 * max_y); ++i) {
pc.y = (uint16_t) (rand() % max_y);
//bool found = apr_iterator.set_iterator_by_particle_cell_test(pc);
}
}
}
if(!found){
std::cout << "out of bounds" << std::endl;
} else {
std::cout << "Particle Cell found is at level: " << apr_iterator.level() << " with x: " << apr_iterator.x()
<< " y: " << apr_iterator.y() << " z: " << apr_iterator.z() << std::endl;
std::cout << " with global index: " << apr_iterator.global_index() << " and intensity "
<< apr.particles_intensities[apr_iterator] << std::endl;
}
}
timer.stop_timer();
float t1 = timer.timings.back();
timer.start_timer("loop map");
for (int j = 0; j < rep; ++j) {
for (unsigned int level = apr_iterator.level_min(); level <= apr_iterator.level_max(); ++level) {
int z = 0;
int x = 0;
#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic) private(z, x) firstprivate(apr_iterator)
#endif
for (z = 0; z < apr_iterator.spatial_index_z_max(level); z++) {
for (x = 0; x < apr_iterator.spatial_index_x_max(level); ++x) {
size_t offset = apr.apr_access.gap_map.x_num[level] * z + x;
if (level == apr.level_max()) {
offset = apr.apr_access.gap_map.x_num[level] * (z / 2) + (x / 2);
}
size_t max_y = apr.apr_access.y_num[level];
auto curr_g = y_b.data[level][offset];
for (int i = 0; i < ceil(0.2 * max_y); ++i) {
uint16_t y_val = (uint16_t) (rand() % max_y);
auto it = curr_g.begin();
auto it_end = curr_g.rbegin();
uint16_t counter = 0;
if(it!= curr_g.end()) {
if ((y_val >= *it) && ((y_val <= *it_end))) {
if((y_val-*it) > (*it_end - y_val)) {
while ((it_end != curr_g.rend()) && (*it_end > y_val)) {
++it_end;
counter++;
}
} else {
while ((it != curr_g.end()) && (*it < y_val)) {
++it;
counter++;
}
}
}
}
//uint16_t found = *it;
}
}
}
}
}
timer.stop_timer();
float t2 = timer.timings.back();
float normt1 = t1/(1.0f*apr.total_number_particles());
float normt2 = t2/(1.0f*apr.total_number_particles());
std::cout << "Normed time: " << normt1 << std::endl;
std::cout << "Normed time2: " << normt2 << std::endl;
std::cout << "Ratio: " << t1/t2 << std::endl;
}
......
......@@ -238,11 +238,14 @@ public:
offset = map_iterator.global_offset;
}
if(map_iterator.iterator == current_pc_map.map.end()){
//check if pointing to a valid key
map_iterator.iterator = current_pc_map.map.begin();
}
if ((part_cell.y >= map_iterator.iterator->first) && (part_cell.y <= map_iterator.iterator->second.y_end)) {
// already pointing to the correct place
part_cell.global_index = map_iterator.iterator->second.global_index_begin_offset +
......@@ -250,6 +253,9 @@ public:
return true;
} else {
//first try next element
//if(map_iterator.iterator != current_pc_map.map.end()){
map_iterator.iterator++;
......@@ -271,12 +277,14 @@ public:
map_iterator.iterator = current_pc_map.map.upper_bound(part_cell.y);
if((map_iterator.iterator == current_pc_map.map.begin()) || (map_iterator.iterator == current_pc_map.map.end())){
//less then the first value
return false;
} else{
map_iterator.iterator--;
//less then the first value //check the last element
map_iterator.iterator = current_pc_map.map.end();
}
map_iterator.iterator--;
if ((part_cell.y >= map_iterator.iterator->first) & (part_cell.y <= map_iterator.iterator->second.y_end)) {
// already pointing to the correct place
part_cell.global_index = map_iterator.iterator->second.global_index_begin_offset +
......
......@@ -340,8 +340,15 @@ inline bool APRIterator::set_iterator_by_particle_cell(ParticleCell& random_part
//
// Have to have set the particle cells x,y,z,level, and it will move the iterator to this location if it exists
//
random_particle_cell.pc_offset = this->apr_access->gap_map.x_num[random_particle_cell.level] * random_particle_cell.z + random_particle_cell.x;
if(random_particle_cell.level==this->level_max()) {
random_particle_cell.pc_offset =
this->apr_access->gap_map.x_num[random_particle_cell.level-1] * (random_particle_cell.z/2) +
(random_particle_cell.x/2);
} else {
random_particle_cell.pc_offset =
this->apr_access->gap_map.x_num[random_particle_cell.level] * random_particle_cell.z +
random_particle_cell.x;
}
if(this->apr_access->find_particle_cell(random_particle_cell,this->current_gap)){
this->current_particle_cell = random_particle_cell;
......@@ -367,14 +374,16 @@ inline bool APRIterator::set_iterator_by_global_coordinate(float x,float y,float
//Then check from the highest level to lowest.
ParticleCell particle_cell;
particle_cell.y = round(y);
particle_cell.x = round(x);
particle_cell.z = round(z);
particle_cell.y = floor(y);
particle_cell.x = floor(x);
particle_cell.z = floor(z);
particle_cell.level = this->level_max();
this->current_gap.level = 0;
particle_cell.pc_offset = this->apr_access->gap_map.x_num[particle_cell.level] * (particle_cell.z/2) + (particle_cell.x/2);
while( (particle_cell.level >= this->level_min()) && !(this->apr_access->find_particle_cell(particle_cell,this->current_gap)) ){
while( (particle_cell.level > this->level_min()) & !(this->apr_access->find_particle_cell(particle_cell,this->current_gap)) ){
particle_cell.y = particle_cell.y/2;
particle_cell.x = particle_cell.x/2;
particle_cell.z = particle_cell.z/2;
......@@ -384,6 +393,7 @@ inline bool APRIterator::set_iterator_by_global_coordinate(float x,float y,float
}
this->current_particle_cell = particle_cell; //if its in bounds it will always have a particle cell responsible
this->set_neighbour_flag();
return true;
}
......
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