libMesh
|
The StoredRange
class defines a contiguous, divisible set of objects.
More...
#include <stored_range.h>
Public Types | |
typedef std::vector< object_type > | vec_type |
Allows an StoredRange to behave like an STL container. More... | |
typedef vec_type::const_iterator | const_iterator |
typedef std::unique_ptr< vec_type, std::function< void(vec_type *)> > | ptr_type |
Public Member Functions | |
StoredRange (const unsigned int new_grainsize=1000) | |
Constructor. More... | |
StoredRange (const iterator_type &first, const iterator_type &last, const unsigned int new_grainsize=1000) | |
Constructor. More... | |
StoredRange (vec_type *objs, const unsigned int new_grainsize=1000) | |
Constructor. More... | |
StoredRange (const StoredRange< iterator_type, object_type > &er) | |
Copy constructor. More... | |
StoredRange (const StoredRange< iterator_type, object_type > &er, const const_iterator &begin_range, const const_iterator &end_range) | |
NOTE: When using pthreads this constructor is MANDATORY!!! More... | |
StoredRange (StoredRange< iterator_type, object_type > &r, Threads::split) | |
Splits the range r . More... | |
~StoredRange ()=default | |
Destructor. More... | |
StoredRange< iterator_type, object_type > & | reset (const iterator_type &first, const iterator_type &last) |
Resets the StoredRange to contain [first,last). More... | |
StoredRange< iterator_type, object_type > & | reset () |
Resets the range to the last specified range. More... | |
const_iterator | begin () const |
Beginning of the range. More... | |
const_iterator | end () const |
End of the range. More... | |
std::size_t | first_idx () const |
Index in the stored vector of the first object. More... | |
std::size_t | last_idx () const |
Index in the stored vector of the last object. More... | |
std::size_t | grainsize () const |
The grain size for the range. More... | |
void | grainsize (const unsigned int &gs) |
Set the grain size. More... | |
std::size_t | size () const |
bool | empty () const |
bool | is_divisible () const |
Private Attributes | |
const_iterator | _end |
const_iterator | _begin |
std::size_t | _last |
std::size_t | _first |
std::size_t | _grainsize |
ptr_type | _objs |
The StoredRange
class defines 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.
Definition at line 54 of file stored_range.h.
typedef vec_type::const_iterator libMesh::StoredRange< iterator_type, object_type >::const_iterator |
Definition at line 61 of file stored_range.h.
typedef std::unique_ptr<vec_type, std::function<void (vec_type *)> > libMesh::StoredRange< iterator_type, object_type >::ptr_type |
Definition at line 62 of file stored_range.h.
typedef std::vector<object_type> libMesh::StoredRange< iterator_type, object_type >::vec_type |
Allows an StoredRange
to behave like an STL container.
Definition at line 60 of file stored_range.h.
|
inline |
Constructor.
Optionally takes the grainsize
parameter, which is the smallest chunk the range may be broken into for parallel execution.
Definition at line 69 of file stored_range.h.
|
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 84 of file stored_range.h.
|
inline |
Constructor.
Takes a std::vector of objects. Optionally takes the grainsize
parameter, which is the smallest chunk the range may be broken into for parallel execution.
Definition at line 107 of file stored_range.h.
|
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 131 of file stored_range.h.
|
inline |
NOTE: When using pthreads this constructor is MANDATORY!!!
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. This version allows you to set the beginning and ending of this new range to be different from that of the one we're copying.
Definition at line 159 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, libMesh::StoredRange< iterator_type, object_type >::_first, libMesh::StoredRange< iterator_type, object_type >::_last, and distance().
|
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 180 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, libMesh::StoredRange< iterator_type, object_type >::_first, libMesh::StoredRange< iterator_type, object_type >::_last, and distance().
|
default |
Destructor.
Releases the object array if we created it.
|
inline |
Beginning of the range.
Definition at line 260 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin.
|
inline |
true
if the range is empty. Definition at line 300 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, and libMesh::StoredRange< iterator_type, object_type >::_end.
|
inline |
End of the range.
Definition at line 265 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_end.
|
inline |
Index in the stored vector of the first object.
Definition at line 270 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_first.
|
inline |
The grain size for the range.
The range will be subdivided into subranges not to exceed the grain size.
Definition at line 281 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_grainsize.
Referenced by libMesh::StoredRange< iterator_type, object_type >::is_divisible().
|
inline |
Set the grain size.
Definition at line 286 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_grainsize.
|
inline |
true
if the range can be subdivided. Definition at line 305 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, distance(), and libMesh::StoredRange< iterator_type, object_type >::grainsize().
|
inline |
Index in the stored vector of the last object.
Definition at line 275 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_last.
|
inline |
Resets the StoredRange
to contain [first,last).
StoredRange<>
can be passed e.g. foo.reset(begin,end). Definition at line 215 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, libMesh::StoredRange< iterator_type, object_type >::_first, libMesh::StoredRange< iterator_type, object_type >::_last, libMesh::StoredRange< iterator_type, object_type >::_objs, and libMesh::libmesh_assert().
Referenced by libMesh::FEMSystem::assemble_qoi(), libMesh::FEMSystem::assemble_qoi_derivative(), libMesh::FEMSystem::assembly(), and libMesh::FEMSystem::postprocess().
|
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.
Definition at line 243 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, libMesh::StoredRange< iterator_type, object_type >::_first, libMesh::StoredRange< iterator_type, object_type >::_last, libMesh::StoredRange< iterator_type, object_type >::_objs, and libMesh::libmesh_assert().
|
inline |
Definition at line 291 of file stored_range.h.
References libMesh::StoredRange< iterator_type, object_type >::_begin, libMesh::StoredRange< iterator_type, object_type >::_end, and distance().
|
private |
Definition at line 310 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::begin(), libMesh::StoredRange< iterator_type, object_type >::empty(), libMesh::StoredRange< iterator_type, object_type >::is_divisible(), libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::StoredRange< iterator_type, object_type >::size(), and libMesh::StoredRange< iterator_type, object_type >::StoredRange().
|
private |
Definition at line 309 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::empty(), libMesh::StoredRange< iterator_type, object_type >::end(), libMesh::StoredRange< iterator_type, object_type >::is_divisible(), libMesh::StoredRange< iterator_type, object_type >::reset(), libMesh::StoredRange< iterator_type, object_type >::size(), and libMesh::StoredRange< iterator_type, object_type >::StoredRange().
|
private |
Definition at line 312 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::first_idx(), libMesh::StoredRange< iterator_type, object_type >::reset(), and libMesh::StoredRange< iterator_type, object_type >::StoredRange().
|
private |
Definition at line 313 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::grainsize().
|
private |
Definition at line 311 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::last_idx(), libMesh::StoredRange< iterator_type, object_type >::reset(), and libMesh::StoredRange< iterator_type, object_type >::StoredRange().
|
private |
Definition at line 315 of file stored_range.h.
Referenced by libMesh::StoredRange< iterator_type, object_type >::reset().