Poster of Linux kernelThe best gift for a Linux geek
Parallel::Histogram

Parallel::Histogram

Section: C Library Functions (3) Updated: Thu Apr 7 2011
Local index Up
 

NAME

Parallel::Histogram -  

SYNOPSIS


#include <parallel_histogram.h>  

Public Member Functions


Histogram (const std::vector< KeyType > &d)

void make_histogram (const unsigned int nbins, KeyType max, KeyType min)

void build_histogram ()

const std::vector< unsigned int > & get_histogram () const

unsigned int n_bins () const

unsigned int local_bin_size (const unsigned int bin) const

unsigned int global_bin_size (const unsigned int bin) const

double lower_bound (const unsigned int bin) const

double upper_bound (const unsigned int bin) const
 

Private Types


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

Private Attributes


const std::vector< KeyType > & data

std::vector< unsigned int > hist

std::vector< double > bin_bounds

std::vector< IterType > bin_iters
 

Detailed Description

 

template<typename KeyType> class Parallel::Histogram< KeyType >

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

Definition at line 41 of file parallel_histogram.h.  

Member Typedef Documentation

 

template<typename KeyType> typedef std::vector<KeyType>::const_iterator Parallel::Histogram< KeyType >::IterType [private]

Definition at line 44 of file parallel_histogram.h.  

Constructor & Destructor Documentation

 

template<typename KeyType > Parallel::Histogram< KeyType >::Histogram (const std::vector< KeyType > &d)

Definition at line 38 of file parallel_histogram.C.

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

                                                          :
  data(d)
{
  libmesh_assert (Parallel::Utils::is_sorted (data));
}
 

Member Function Documentation

 

template<typename KeyType > void Parallel::Histogram< KeyType >::build_histogram ()

Definition at line 91 of file parallel_histogram.C.

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

{
  // Build a local histogram
  std::vector<unsigned int> local_hist (this->n_bins());

  for (unsigned int b=0; b<this->n_bins(); b++)
    local_hist[b] = this->local_bin_size(b);

  // Add all the local histograms to get the global histogram
  hist = local_hist;
  Parallel::sum(hist);
  
  // All done!  
}
 

template<typename KeyType > const std::vector< unsigned int > & Parallel::Histogram< KeyType >::get_histogram () const [inline]

Definition at line 98 of file parallel_histogram.h.

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

{
  return hist;
}
 

template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::global_bin_size (const unsigned intbin) const [inline]

Definition at line 131 of file parallel_histogram.h.

{
  libmesh_assert (bin < hist.size());

  // The number of entries in the bin (globally)
  return hist[bin];
}
 

template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::local_bin_size (const unsigned intbin) const [inline]

Definition at line 119 of file parallel_histogram.h.

{
  libmesh_assert ((bin+1) < bin_iters.size());

  // The number of entries in the bin (locally)
  return std::distance (bin_iters[bin], bin_iters[bin+1]);
}
 

template<typename KeyType > double Parallel::Histogram< KeyType >::lower_bound (const unsigned intbin) const [inline]

Definition at line 143 of file parallel_histogram.h.

{
  libmesh_assert ((bin+1) < bin_bounds.size());

  return bin_bounds[bin];
}
 

template<typename KeyType > void Parallel::Histogram< KeyType >::make_histogram (const unsigned intnbins, KeyTypemax, KeyTypemin)

Definition at line 47 of file parallel_histogram.C.

References Parallel::Utils::to_double().

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

{
  libmesh_assert (min < max);
  
  // The width of each bin.  Store this as a floating point value
  double bin_width = (Parallel::Utils::to_double(max)-
                      Parallel::Utils::to_double(min))/static_cast<double>(nbins);


  // The idea for 4 bins of size d is this:
  //
  //  0          1          2           3          4
  //  |----------|----------|-----------|----------|
  // min   0   min+d  1   min+2d  2  min+3d   3   max


  
  // Set the iterators corresponding to the boundaries
  // as defined above.  This takes nbins * O(log N) time. 
  bin_bounds.resize (nbins+1);
  bin_iters.resize  (nbins+1, data.begin());

  // Set the minimum bin boundary iterator
  bin_iters[0]  = data.begin();
  bin_bounds[0] = Parallel::Utils::to_double(min);
  
  // Set the internal bin boundary iterators
  for (unsigned int b=1; b<nbins; ++b)
    {
      bin_bounds[b] = Parallel::Utils::to_double(min) + bin_width * b;

      bin_iters[b]  = std::lower_bound (bin_iters[b-1], data.end(), 
                                        Parallel::Utils::to_key_type<KeyType>(bin_bounds[b]));
    }

  bin_iters[nbins]  = data.end();
  bin_bounds[nbins] = Parallel::Utils::to_double(max);
}  
 

template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::n_bins () const [inline]

Definition at line 107 of file parallel_histogram.h.

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

{
  if (bin_iters.empty())
    return 0;

  return (bin_iters.size()-1);
}
 

template<typename KeyType > double Parallel::Histogram< KeyType >::upper_bound (const unsigned intbin) const [inline]

Definition at line 154 of file parallel_histogram.h.

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

{
  libmesh_assert ((bin+1) < bin_bounds.size());

  return bin_bounds[bin+1];
}
 

Member Data Documentation

 

template<typename KeyType> std::vector<double> Parallel::Histogram< KeyType >::bin_bounds [private]

Definition at line 87 of file parallel_histogram.h.  

template<typename KeyType> std::vector<IterType> Parallel::Histogram< KeyType >::bin_iters [private]

Definition at line 88 of file parallel_histogram.h.  

template<typename KeyType> const std::vector<KeyType>& Parallel::Histogram< KeyType >::data [private]

Definition at line 85 of file parallel_histogram.h.

Referenced by Parallel::Histogram< KeyType >::Histogram().  

template<typename KeyType> std::vector<unsigned int> Parallel::Histogram< KeyType >::hist [private]

Definition at line 86 of file parallel_histogram.h.

 

Author

Generated automatically by Doxygen for libMesh from the source code.


 

Index

NAME
SYNOPSIS
Public Member Functions
Private Types
Private Attributes
Detailed Description
template<typename KeyType> class Parallel::Histogram< KeyType >
Member Typedef Documentation
template<typename KeyType> typedef std::vector<KeyType>::const_iterator Parallel::Histogram< KeyType >::IterType [private]
Constructor & Destructor Documentation
template<typename KeyType > Parallel::Histogram< KeyType >::Histogram (const std::vector< KeyType > &d)
Member Function Documentation
template<typename KeyType > void Parallel::Histogram< KeyType >::build_histogram ()
template<typename KeyType > const std::vector< unsigned int > & Parallel::Histogram< KeyType >::get_histogram () const [inline]
template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::global_bin_size (const unsigned intbin) const [inline]
template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::local_bin_size (const unsigned intbin) const [inline]
template<typename KeyType > double Parallel::Histogram< KeyType >::lower_bound (const unsigned intbin) const [inline]
template<typename KeyType > void Parallel::Histogram< KeyType >::make_histogram (const unsigned intnbins, KeyTypemax, KeyTypemin)
template<typename KeyType > unsigned int Parallel::Histogram< KeyType >::n_bins () const [inline]
template<typename KeyType > double Parallel::Histogram< KeyType >::upper_bound (const unsigned intbin) const [inline]
Member Data Documentation
template<typename KeyType> std::vector<double> Parallel::Histogram< KeyType >::bin_bounds [private]
template<typename KeyType> std::vector<IterType> Parallel::Histogram< KeyType >::bin_iters [private]
template<typename KeyType> const std::vector<KeyType>& Parallel::Histogram< KeyType >::data [private]
template<typename KeyType> std::vector<unsigned int> Parallel::Histogram< KeyType >::hist [private]
Author

This document was created by man2html, using the manual pages.
Time: 21:52:00 GMT, April 16, 2011