moab
initialize_tree.hpp
Go to the documentation of this file.
00001 #ifndef INIT_TREE_HPP
00002 #define INIT_TREE_HPP
00003 //TODO: refactor out to AdaptiveKDTree
00004 ErrorCode initialize_tree(){
00005   Range local_ents;
00006   typename Tree::Settings settings;
00007   settings.candidatePlaneSet = AdaptiveKDTree::SUBDIVISION;
00008 
00009     //get entities on the local part
00010   //TODO: fixme
00011   ErrorCode result = MB_SUCCESS;
00012   result = pc.get_part_entities( local_ents, 3);
00013   else local_ents = range;
00014 
00015   if (MB_SUCCESS != result || local_ents.empty()) {
00016     std::cout << "Problems getting source entities" 
00017           << std::endl;
00018     return result;
00019   }
00020 
00021     // build the tree for local processor
00022   for (int i = 0; i < num_iterations; i++) {
00023     tree = Tree( &impl);
00024     result = tree.build_tree( local_ents, local_root, &settings);
00025     if (MB_SUCCESS != result) {
00026       std::cout << "Problems building tree";
00027       if (num_iterations != i) {
00028         settings.maxEntPerLeaf *= 2;
00029         std::cout << "; increasing elements/leaf to " 
00030                   << settings.maxEntPerLeaf << std::endl;;
00031       }
00032       else {
00033         std::cout << "; exiting" << std::endl;
00034         return result;
00035       }
00036     }
00037     else
00038       break; // get out of tree building
00039   }
00040   
00041   boxes.resize(6*pc.proc_config().proc_size());
00042 
00043   unsigned int rank = (pc ? pc.proc_config().proc_rank() : 0);
00044   result = tree.get_tree_box( local_root, 
00045                  &boxes[6*rank], 
00046                  &boxes[6*rank+3]);
00047   if (MB_SUCCESS != result) return result;
00048   
00049     // now communicate to get all boxes
00050     // use "in place" option
00051   if (pc) {
00052     int mpi_err = MPI_Allgather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL,
00053                                 &boxes[0], 6, MPI_DOUBLE, 
00054                                 pc.proc_config().proc_comm());
00055     if (MPI_SUCCESS != mpi_err) return MB_FAILURE;
00056   }
00057 
00058 
00059 #ifndef NDEBUG
00060   double min[3] = {0,0,0}, max[3] = {0,0,0};
00061   unsigned int dep;
00062   tree.get_info(local_root, min, max, dep);
00063   std::cerr << "Proc " << rank << ": box min/max, tree depth = ("
00064             << min[0] << "," << min[1] << "," << min[2] << "), ("
00065             << max[0] << "," << max[1] << "," << max[2] << "), "
00066             << dep << std::endl;
00067 #endif  
00068 
00069   return result;
00070 }
00071 #endif // INIT_TREE_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines