StoredRange< iterator_type, object_type > Class Template Reference

#include <stored_range.h>

List of all members.

Public Types

typedef std::vector
< object_type >
::const_iterator 
const_iterator

Public Member Functions

 StoredRange (const unsigned int grainsize=1000)
 StoredRange (const iterator_type &first, const iterator_type &last, const unsigned int grainsize=1000)
 StoredRange (const StoredRange< iterator_type, object_type > &er)
 StoredRange (StoredRange< iterator_type, object_type > &r, Threads::split)
StoredRange< iterator_type,
object_type > & 
reset (const iterator_type &first, const iterator_type &last)
StoredRange< iterator_type,
object_type > & 
reset ()
const_iterator begin () const
const_iterator end () const
unsigned int first_idx () const
unsigned int last_idx () const
unsigned int grainsize () const
void grainsize (const unsigned int &gs)
unsigned int size () const
bool empty () const
bool is_divisible () const

Private Attributes

const_iterator _end
const_iterator _begin
unsigned int _last
unsigned int _first
unsigned int _grainsize
std::vector< object_type > _objs


Detailed Description

template<typename iterator_type, typename object_type>
class StoredRange< iterator_type, object_type >

The StoredRange class defined a contiguous, divisible set of objects This class is used primarily as the argument to function objects. The range can then be subdivided into a number of "tasks" which can be executed in parallel. This concept is central to the Threading Building Blocks template library which can optionally be used by libMesh to implement shared-memory parallelism.

The implementation takes a user-provided object range and packs it into a contiguous vector which can then be subdivided efficiently. A first-cut implementation using raw element iterators incurred simply too much overhead by using the predicated iterators, specifically operations such as advancing such iterators has a cost proportional to the amount the iterator is advanced. Hence in this implementation the user-provided range is packed into a vector.

Author:
Benjamin S. Kirk, 2008.

Definition at line 50 of file stored_range.h.


Member Typedef Documentation

template<typename iterator_type , typename object_type >
typedef std::vector<object_type>::const_iterator StoredRange< iterator_type, object_type >::const_iterator

Allows an StoredRange to behave like an STL container.

Definition at line 56 of file stored_range.h.


Constructor & Destructor Documentation

template<typename iterator_type , typename object_type >
StoredRange< iterator_type, object_type >::StoredRange ( const unsigned int  grainsize = 1000  )  [inline]

Constructor. Optionally takes the grainsize parameter, which is the smallest chunk the range may be broken into for parallel execution.

Definition at line 63 of file stored_range.h.

00063                                                     :
00064   _grainsize(grainsize)
00065   {}

template<typename iterator_type , typename object_type >
StoredRange< iterator_type, object_type >::StoredRange ( const iterator_type &  first,
const iterator_type &  last,
const unsigned int  grainsize = 1000 
) [inline]

Constructor. Takes the beginning and end of the range. Optionally takes the grainsize parameter, which is the smallest chunk the range may be broken into for parallel execution.

Definition at line 73 of file stored_range.h.

References StoredRange< iterator_type, object_type >::reset().

00075                                                     :
00076   _grainsize(grainsize)
00077   {
00078     this->reset(first, last);
00079   }

template<typename iterator_type , typename object_type >
StoredRange< iterator_type, object_type >::StoredRange ( const StoredRange< iterator_type, object_type > &  er  )  [inline]

Copy constructor. The StoredRange can be copied into subranges for parallel execution. In this way the initial StoredRange can be thought of as the root of a binary tree. The root element is the only element which interacts with the user. It takes a specified range of objects and packs it into a contiguous vector which can be split efficiently. However, there is no need for the child ranges to contain this vector, so long as the parent outlives the children. So we implement the copy constructor to specifically omit the _objs vector.

Definition at line 94 of file stored_range.h.

00094                                                                 :
00095     _end(er._end), 
00096     _begin(er._begin),
00097     _last(er._last),
00098     _first(er._first),
00099     _grainsize(er._grainsize)
00100   {
00101     // specifically, do *not* copy the vector
00102   }
    

template<typename iterator_type , typename object_type >
StoredRange< iterator_type, object_type >::StoredRange ( StoredRange< iterator_type, object_type > &  r,
Threads::split   
) [inline]

Splits the range r. The first half of the range is left in place, the second half of the range is placed in *this.

Definition at line 109 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, StoredRange< iterator_type, object_type >::_end, StoredRange< iterator_type, object_type >::_first, and StoredRange< iterator_type, object_type >::_last.

00109                                                                          : 
00110     _end(r._end),
00111     _begin(r._begin),
00112     _last(r._last),
00113     _first(r._first),
00114     _grainsize(r._grainsize)
00115   {
00116     const_iterator
00117       beginning = r._begin,
00118       ending    = r._end,
00119       middle    = beginning + std::distance(beginning, ending)/2u;
00120     
00121     r._end = _begin = middle;
00122 
00123     unsigned int
00124       first = r._first,
00125       last  = r._last,
00126       half  = first + (last-first)/2u;
00127 
00128     r._last = _first = half;
00129   }


Member Function Documentation

template<typename iterator_type , typename object_type >
const_iterator StoredRange< iterator_type, object_type >::begin (  )  const [inline]

template<typename iterator_type , typename object_type >
bool StoredRange< iterator_type, object_type >::empty (  )  const [inline]

Returns true if the range is empty.

Definition at line 215 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, and StoredRange< iterator_type, object_type >::_end.

00215 { return (_begin == _end); }

template<typename iterator_type , typename object_type >
const_iterator StoredRange< iterator_type, object_type >::end (  )  const [inline]

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::first_idx (  )  const [inline]

Index in the stored vector of the first object.

Definition at line 185 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_first.

00185 { return _first; }

template<typename iterator_type , typename object_type >
void StoredRange< iterator_type, object_type >::grainsize ( const unsigned int &  gs  )  [inline]

Set the grain size.

Definition at line 201 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_grainsize.

00201 {_grainsize = gs;}

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::grainsize (  )  const [inline]

The grain size for the range. The range will be subdivided into subranges not to exceed the grain size.

Definition at line 196 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_grainsize.

Referenced by StoredRange< iterator_type, object_type >::is_divisible().

00196 {return _grainsize;}

template<typename iterator_type , typename object_type >
bool StoredRange< iterator_type, object_type >::is_divisible (  )  const [inline]

Returns true if the range can be subdivided.

Definition at line 220 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, StoredRange< iterator_type, object_type >::_end, and StoredRange< iterator_type, object_type >::grainsize().

00220 { return this->grainsize() < static_cast<unsigned int>(std::distance(_begin, _end)); }

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::last_idx (  )  const [inline]

Index in the stored vector of the last object.

Definition at line 190 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_last.

00190 { return _last; }

template<typename iterator_type , typename object_type >
StoredRange<iterator_type, object_type>& StoredRange< iterator_type, object_type >::reset (  )  [inline]

Resets the range to the last specified range. This method only exists for efficiency -- it is more efficient to set the range to its previous value without rebuilding the underlying vector. Returns a reference to itself for convenience, so functions expecting a StoredRange<> can be passed e.g. foo.reset().

Definition at line 161 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, StoredRange< iterator_type, object_type >::_end, StoredRange< iterator_type, object_type >::_first, StoredRange< iterator_type, object_type >::_last, and StoredRange< iterator_type, object_type >::_objs.

Referenced by StoredRange< iterator_type, object_type >::StoredRange().

00162   {
00163     _begin = _objs.begin();
00164     _end   = _objs.end();
00165 
00166     _first = 0;
00167     _last  = _objs.size();
00168 
00169     return *this;
00170   }

template<typename iterator_type , typename object_type >
StoredRange<iterator_type, object_type>& StoredRange< iterator_type, object_type >::reset ( const iterator_type &  first,
const iterator_type &  last 
) [inline]

Resets the StoredRange to contain [first,last). Returns a reference to itself for convenience, so functions expecting a StoredRange<> can be passed e.g. foo.reset(begin,end).

Definition at line 137 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, StoredRange< iterator_type, object_type >::_end, StoredRange< iterator_type, object_type >::_first, StoredRange< iterator_type, object_type >::_last, and StoredRange< iterator_type, object_type >::_objs.

Referenced by DofMap::create_dof_constraints().

00139   {
00140     _objs.clear();
00141 
00142     for (iterator_type it=first; it!=last; ++it)
00143       _objs.push_back(*it);
00144     
00145     _begin = _objs.begin();
00146     _end   = _objs.end();
00147 
00148     _first = 0;
00149     _last  = _objs.size();
00150     
00151     return *this;
00152   }

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::size (  )  const [inline]

Returns:
the size of the range.

Definition at line 206 of file stored_range.h.

References StoredRange< iterator_type, object_type >::_begin, and StoredRange< iterator_type, object_type >::_end.

00206 { return std::distance(_begin, _end); }


Member Data Documentation

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::_first [private]

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::_grainsize [private]

template<typename iterator_type , typename object_type >
unsigned int StoredRange< iterator_type, object_type >::_last [private]

template<typename iterator_type , typename object_type >
std::vector<object_type> StoredRange< iterator_type, object_type >::_objs [private]

Definition at line 229 of file stored_range.h.

Referenced by StoredRange< iterator_type, object_type >::reset().


The documentation for this class was generated from the following file:

Site Created By: libMesh Developers
Last modified: November 25 2009 03:44:59.

Hosted By:
SourceForge.net Logo