libMesh::Parallel::Histogram< KeyType, IdxType > Class Template Reference

#include <parallel_histogram.h>

List of all members.

Public Member Functions

 Histogram (const std::vector< KeyType > &d)
void make_histogram (const IdxType nbins, KeyType max, KeyType min)
void build_histogram ()
const std::vector< IdxType > & get_histogram () const
IdxType n_bins () const
IdxType local_bin_size (const IdxType bin) const
IdxType global_bin_size (const IdxType bin) const
double lower_bound (const IdxType bin) const
double upper_bound (const IdxType bin) const

Private Types

typedef std::vector< KeyType >
::const_iterator 
IterType

Private Attributes

const std::vector< KeyType > & data
std::vector< IdxType > hist
std::vector< double > bin_bounds
std::vector< IterTypebin_iters

Detailed Description

template<typename KeyType, typename IdxType = unsigned int>
class libMesh::Parallel::Histogram< KeyType, IdxType >

Defines a histogram to be used in parallel in conjuction with a BinSorter.

Definition at line 44 of file parallel_histogram.h.


Member Typedef Documentation

template<typename KeyType, typename IdxType = unsigned int>
typedef std::vector<KeyType>::const_iterator libMesh::Parallel::Histogram< KeyType, IdxType >::IterType [private]

Definition at line 47 of file parallel_histogram.h.


Constructor & Destructor Documentation

template<typename KeyType , typename IdxType >
libMesh::Parallel::Histogram< KeyType, IdxType >::Histogram ( const std::vector< KeyType > &  d  )  [inline, explicit]

Definition at line 37 of file parallel_histogram.C.

References libMesh::Parallel::Histogram< KeyType, IdxType >::data, and libMesh::Parallel::Utils::is_sorted().

00037                                                                   :
00038   data(d)
00039 {
00040   libmesh_assert (Parallel::Utils::is_sorted (data));
00041 }


Member Function Documentation

template<typename KeyType , typename IdxType >
void libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram (  )  [inline]

Definition at line 90 of file parallel_histogram.C.

References libMesh::CommWorld, libMesh::Parallel::Histogram< KeyType, IdxType >::hist, libMesh::Parallel::Histogram< KeyType, IdxType >::local_bin_size(), libMesh::Parallel::Histogram< KeyType, IdxType >::n_bins(), and libMesh::Parallel::Communicator::sum().

Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort().

00091 {
00092   // Build a local histogram
00093   std::vector<IdxType> local_hist (this->n_bins());
00094 
00095   for (IdxType b=0; b<this->n_bins(); b++)
00096     local_hist[b] = this->local_bin_size(b);
00097 
00098   // Add all the local histograms to get the global histogram
00099   hist = local_hist;
00100   CommWorld.sum(hist);
00101 
00102   // All done!
00103 }

template<typename KeyType , typename IdxType >
const std::vector< IdxType > & libMesh::Parallel::Histogram< KeyType, IdxType >::get_histogram (  )  const [inline]
template<typename KeyType , typename IdxType >
IdxType libMesh::Parallel::Histogram< KeyType, IdxType >::global_bin_size ( const IdxType  bin  )  const [inline]

Definition at line 136 of file parallel_histogram.h.

References libMesh::Parallel::Histogram< KeyType, IdxType >::hist.

00137 {
00138   libmesh_assert_less (bin, hist.size());
00139 
00140   // The number of entries in the bin (globally)
00141   return hist[bin];
00142 }

template<typename KeyType , typename IdxType >
IdxType libMesh::Parallel::Histogram< KeyType, IdxType >::local_bin_size ( const IdxType  bin  )  const [inline]

Definition at line 123 of file parallel_histogram.h.

References libMesh::Parallel::Histogram< KeyType, IdxType >::bin_iters.

Referenced by libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram().

00124 {
00125   libmesh_assert_less ((bin+1), bin_iters.size());
00126 
00127   // The number of entries in the bin (locally)
00128   return libmesh_cast_int<IdxType>
00129     (std::distance (bin_iters[bin], bin_iters[bin+1]));
00130 }

template<typename KeyType , typename IdxType >
double libMesh::Parallel::Histogram< KeyType, IdxType >::lower_bound ( const IdxType  bin  )  const [inline]

Definition at line 148 of file parallel_histogram.h.

References libMesh::Parallel::Histogram< KeyType, IdxType >::bin_bounds.

Referenced by libMesh::Parallel::Histogram< KeyType, IdxType >::make_histogram().

00149 {
00150   libmesh_assert_less ((bin+1), bin_bounds.size());
00151 
00152   return bin_bounds[bin];
00153 }

template<typename KeyType , typename IdxType >
void libMesh::Parallel::Histogram< KeyType, IdxType >::make_histogram ( const IdxType  nbins,
KeyType  max,
KeyType  min 
) [inline]

Definition at line 46 of file parallel_histogram.C.

References libMesh::Parallel::Histogram< KeyType, IdxType >::bin_bounds, libMesh::Parallel::Histogram< KeyType, IdxType >::bin_iters, libMesh::Parallel::Histogram< KeyType, IdxType >::data, libMesh::Parallel::Histogram< KeyType, IdxType >::lower_bound(), and libMesh::Parallel::Utils::to_double().

Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort().

00049 {
00050   libmesh_assert_less (min, max);
00051 
00052   // The width of each bin.  Store this as a floating point value
00053   double bin_width = (Parallel::Utils::to_double(max)-
00054                       Parallel::Utils::to_double(min))/static_cast<double>(nbins);
00055 
00056 
00057   // The idea for 4 bins of size d is this:
00058   //
00059   //  0          1          2           3          4
00060   //  |----------|----------|-----------|----------|
00061   // min   0   min+d  1   min+2d  2  min+3d   3   max
00062 
00063 
00064 
00065   // Set the iterators corresponding to the boundaries
00066   // as defined above.  This takes nbins * O(log N) time.
00067   bin_bounds.resize (nbins+1);
00068   bin_iters.resize  (nbins+1, data.begin());
00069 
00070   // Set the minimum bin boundary iterator
00071   bin_iters[0]  = data.begin();
00072   bin_bounds[0] = Parallel::Utils::to_double(min);
00073 
00074   // Set the internal bin boundary iterators
00075   for (IdxType b=1; b<nbins; ++b)
00076     {
00077       bin_bounds[b] = Parallel::Utils::to_double(min) + bin_width * b;
00078 
00079       bin_iters[b]  = std::lower_bound (bin_iters[b-1], data.end(),
00080                                         Parallel::Utils::to_key_type<KeyType>(bin_bounds[b]));
00081     }
00082 
00083   bin_iters[nbins]  = data.end();
00084   bin_bounds[nbins] = Parallel::Utils::to_double(max);
00085 }

template<typename KeyType , typename IdxType >
IdxType libMesh::Parallel::Histogram< KeyType, IdxType >::n_bins (  )  const [inline]

Definition at line 111 of file parallel_histogram.h.

References libMesh::Parallel::Histogram< KeyType, IdxType >::bin_iters.

Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort(), and libMesh::Parallel::Histogram< KeyType, IdxType >::build_histogram().

00112 {
00113   if (bin_iters.empty())
00114     return 0;
00115 
00116   return libmesh_cast_int<IdxType>(bin_iters.size()-1);
00117 }

template<typename KeyType , typename IdxType >
double libMesh::Parallel::Histogram< KeyType, IdxType >::upper_bound ( const IdxType  bin  )  const [inline]

Definition at line 159 of file parallel_histogram.h.

References libMesh::Parallel::Histogram< KeyType, IdxType >::bin_bounds.

Referenced by libMesh::Parallel::BinSorter< KeyType, IdxType >::binsort().

00160 {
00161   libmesh_assert_less ((bin+1), bin_bounds.size());
00162 
00163   return bin_bounds[bin+1];
00164 }


Member Data Documentation

template<typename KeyType, typename IdxType = unsigned int>
std::vector<double> libMesh::Parallel::Histogram< KeyType, IdxType >::bin_bounds [private]
template<typename KeyType, typename IdxType = unsigned int>
const std::vector<KeyType>& libMesh::Parallel::Histogram< KeyType, IdxType >::data [private]
template<typename KeyType, typename IdxType = unsigned int>
std::vector<IdxType> libMesh::Parallel::Histogram< KeyType, IdxType >::hist [private]

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:
SourceForge.net Logo