libMesh::Parallel::BinSorter< KeyType, IdxType > Class Template Reference
#include <parallel_bin_sorter.h>
Public Member Functions | |
| BinSorter (const std::vector< KeyType > &d) | |
| void | binsort (const IdxType nbins, KeyType max, KeyType min) |
| IdxType | sizeof_bin (const IdxType bin) const |
Private Types | |
| typedef std::vector< KeyType > ::const_iterator | IterType |
Private Attributes | |
| const std::vector< KeyType > & | data |
| std::vector< IterType > | bin_iters |
Detailed Description
template<typename KeyType, typename IdxType = unsigned int>
class libMesh::Parallel::BinSorter< KeyType, IdxType >
Perform a parallel sort using a bin-sort method.
Definition at line 42 of file parallel_bin_sorter.h.
Member Typedef Documentation
typedef std::vector<KeyType>::const_iterator libMesh::Parallel::BinSorter< KeyType, IdxType >::IterType [private] |
Definition at line 45 of file parallel_bin_sorter.h.
Constructor & Destructor Documentation
| libMesh::Parallel::BinSorter< KeyType, IdxType >::BinSorter | ( | const std::vector< KeyType > & | d | ) | [inline, explicit] |
Definition at line 40 of file parallel_bin_sorter.C.
References libMesh::Parallel::BinSorter< KeyType, IdxType >::data, and libMesh::Parallel::Utils::is_sorted().
00040 : 00041 data(d) 00042 { 00043 // Assume (& libmesh_assert) we are working with a sorted range 00044 00045 // Ah... is_sorted is an STL extension! 00046 //libmesh_assert (std::is_sorted (data.begin(), data.end())); 00047 00048 // Home-grown is_sorted 00049 libmesh_assert (Parallel::Utils::is_sorted (data)); 00050 }
Member Function Documentation
| void libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort | ( | const IdxType | nbins, | |
| KeyType | max, | |||
| KeyType | min | |||
| ) | [inline] |
Definition at line 55 of file parallel_bin_sorter.C.
References libMesh::Parallel::BinSorter< KeyType, IdxType >::bin_iters, libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram(), libMesh::CommWorld, libMesh::Parallel::BinSorter< KeyType, IdxType >::data, libMesh::Parallel::Histogram< KeyType, IdxType >::get_histogram(), libMesh::Parallel::Histogram< KeyType, IdxType >::make_histogram(), libMesh::Parallel::Histogram< KeyType, IdxType >::n_bins(), libMesh::Parallel::Communicator::sum(), libMesh::Parallel::Utils::to_double(), and libMesh::Parallel::Histogram< KeyType, IdxType >::upper_bound().
Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::binsort().
00058 { 00059 libmesh_assert_less (min, max); 00060 00061 // Build a histogram in parallel from our data. 00062 // Use this to create quasi-uniform bins. 00063 Parallel::Histogram<KeyType,IdxType> phist (data); 00064 phist.make_histogram (nbins*50, max, min); 00065 phist.build_histogram (); 00066 00067 const std::vector<IdxType>& histogram = 00068 phist.get_histogram(); 00069 00070 00071 // Now we will locate the bin boundaries so 00072 // that each bin is roughly equal size 00073 { 00074 // Find the total size of the data set 00075 IdxType local_data_size = libmesh_cast_int<IdxType>(data.size()); 00076 IdxType global_data_size = libmesh_cast_int<IdxType>(local_data_size); 00077 00078 CommWorld.sum(global_data_size); 00079 00080 std::vector<IdxType> target_bin_size (nbins, global_data_size / nbins); 00081 00082 // Equally distribute the remainder 00083 for (IdxType i=0; i<(global_data_size % nbins); i++) 00084 ++target_bin_size[i]; 00085 00086 // Set the iterators corresponding to the bin boundaries 00087 { 00088 std::vector<double> bin_bounds (nbins+1); 00089 bin_iters.resize (nbins+1, data.begin()); 00090 00091 // Set the minimum bin boundary iterator 00092 bin_iters[0] = data.begin(); 00093 bin_bounds[0] = Parallel::Utils::to_double(min); 00094 00095 // The current location in the histogram 00096 IdxType current_histogram_bin = 0; 00097 00098 // How much above (+) or below (-) we are from the 00099 // target size for the last bin. 00100 // Note that when delta is (-) we will 00101 // accept a slightly larger size for the next bin, 00102 // the goal being to keep the whole mess average 00103 int delta = 0; 00104 00105 // Set the internal bin boundary iterators 00106 for (IdxType b=0; b<nbins; ++b) 00107 { 00108 // The size of bin b. We want this to 00109 // be ~= target_bin_size[b] 00110 int current_bin_size = 0; 00111 00112 // Step through the histogram until we have the 00113 // desired bin size 00114 while ((current_bin_size + histogram[current_histogram_bin] + delta) <= target_bin_size[b]) 00115 { 00116 // Don't index out of the histogram! 00117 if ((current_histogram_bin+1) == phist.n_bins()) 00118 break; 00119 00120 current_bin_size += histogram[current_histogram_bin++]; 00121 } 00122 00123 delta += current_bin_size - target_bin_size[b]; 00124 00125 // Set the upper bound of the bin 00126 bin_bounds[b+1] = phist.upper_bound (current_histogram_bin); 00127 bin_iters[b+1] = std::lower_bound(bin_iters[b], data.end(), 00128 Parallel::Utils::to_key_type<KeyType>(bin_bounds[b+1])); 00129 } 00130 00131 // Just be sure the last boundaries point to the right place 00132 bin_iters[nbins] = data.end(); 00133 bin_bounds[nbins] = Parallel::Utils::to_double(max); 00134 } 00135 } 00136 }
| IdxType libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin | ( | const IdxType | bin | ) | const [inline] |
Definition at line 76 of file parallel_bin_sorter.h.
References libMesh::Parallel::BinSorter< KeyType, IdxType >::bin_iters.
Referenced by libMesh::Parallel::Sort< KeyType, IdxType >::binsort().
Member Data Documentation
std::vector<IterType> libMesh::Parallel::BinSorter< KeyType, IdxType >::bin_iters [private] |
Definition at line 67 of file parallel_bin_sorter.h.
Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), and libMesh::Parallel::BinSorter< KeyType, IdxType >::sizeof_bin().
const std::vector<KeyType>& libMesh::Parallel::BinSorter< KeyType, IdxType >::data [private] |
Definition at line 66 of file parallel_bin_sorter.h.
Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), and libMesh::Parallel::BinSorter< KeyType, IdxType >::BinSorter().
The documentation for this class was generated from the following files:
Site Created By: libMesh Developers
Last modified: February 05 2013 19:55:45 UTC
Hosted By: