rpa::range_size< It > Class Template Reference

#include <common.h>

Inheritance diagram for rpa::range_size< It >:

rpa::range_lambda< It > List of all members.

Public Member Functions

 range_size (It aBeg, It aEnd, size_t aSize, chunk_t aMinChkSz=chunk_t())
 range_size (It aBeg, It aEnd, chunk_t aMinChkSz=chunk_t())
 range_size (const range_size &aRS)
 Plain copy constructor.
void calc_wdth (thread_tree_core &aThrTree)
 Adjusts the threads number actually used, less or equal than the max threads number.
size_t size_thr (void) const
slice chop (void)
template<class Rng2>
tuple2< slice, typename Rng2::slice > chop (Rng2 &aSq2)
slice tail (void)
 Returns the sequences end, for algorithms working on one sequence: count,accumulate...
template<class Rng2>
tuple2< slice, typename Rng2::slice > tail (Rng2 &aSq2)

Private Types

typedef range_lambda< It > rl_base
 Does not need volatile iterators because chops are done by the main thread.

Private Member Functions

void check (void) const
 For debugging purpose only.
range_sizeoperator= (const range_size &)
 Not assignable. No technical reason for this, just for full control.

Private Attributes

const size_t _Size
 The number of elements in the input sequence, set by the constructor.
size_t _SizePerThr
 The 'nominal' number of elements that each sub-thread will process.

Classes

struct  range_out
struct  range_out< It2, std::output_iterator_tag >
class  slice
 Models a slice begin/end given by 'chop' or 'tail', processed by a single sub-thread. More...

Detailed Description

template<class It>
class rpa::range_size< It >

Typically used when the size of the input sequence is known. The input iterator category can be forward_iterator, random_access or bidirectionnal.


Member Typedef Documentation

template<class It>
typedef range_lambda< It > rpa::range_size< It >::rl_base [private]

Does not need volatile iterators because chops are done by the main thread.


Constructor & Destructor Documentation

template<class It>
rpa::range_size< It >::range_size ( It  aBeg,
It  aEnd,
size_t  aSize,
chunk_t  aMinChkSz = chunk_t() 
) [inline]

Maybe the iterators type do not allow to compute quickly the number of elements, for example if this is the begin and end of a std::list. In this case, we can provide it explicitely, for example the container size. If the given number of elements is different of the distance between the two operators, the results are unpredictable !!!

This checks, in debugging mode, if the given distance is really the distance between the iterators. This check cannot be done for input_iterator_tag.

template<class It>
rpa::range_size< It >::range_size ( It  aBeg,
It  aEnd,
chunk_t  aMinChkSz = chunk_t() 
) [inline]

If no number of elements is given, then we compute the iterators distance, which is very convenient for random_access iterators.

template<class It>
rpa::range_size< It >::range_size ( const range_size< It > &  aRS  )  [inline]

Plain copy constructor.


Member Function Documentation

template<class It>
void rpa::range_size< It >::calc_wdth ( thread_tree_core aThrTree  )  [inline]

Adjusts the threads number actually used, less or equal than the max threads number.

It is useless to have more threads than elements to process. But there must be at least one thread.

The minimum reasonable value for the chunk size, in order to be efficient, is stored in _SizePerThr by the constructor.

If the number of elements to process, _Size, is smaller that this minimum myInitSizePerThr, there must be at least one thread.

template<class It>
void rpa::range_size< It >::check ( void   )  const [inline, private]

For debugging purpose only.

The size per threads is zero, only if there were no elements at the beginning.

If no elements, then Beg and Equal identical.

template<class It>
template<class Rng2>
tuple2< slice, typename Rng2::slice > rpa::range_size< It >::chop ( Rng2 &  aSq2  )  [inline]

template<class It>
slice rpa::range_size< It >::chop ( void   )  [inline]

We do not need the return value because we known in advance how many elements are there. If the sequence is empty, we return an empty slice.

template<class It>
range_size& rpa::range_size< It >::operator= ( const range_size< It > &   )  [private]

Not assignable. No technical reason for this, just for full control.

template<class It>
size_t rpa::range_size< It >::size_thr ( void   )  const [inline]

Used by the comparison function for debugging. Necessary because some execution methods change the order of the output results, and this new order is dependent on the number of elements processed in one go. So we use this number to analyse if the algorithm worked correctly.

template<class It>
template<class Rng2>
tuple2< slice, typename Rng2::slice > rpa::range_size< It >::tail ( Rng2 &  aSq2  )  [inline]

Returns the last slice of the sequence, that is a number of elements between _SizePerThr and 2*_SizePerThr-1. It would perhaps be fine to replace the method 'tail' by a change to 'chop', which would check whether the next call to 'chop' would finish, would exhaust the sequence. Pros: Simplified interface, no need to choose between 'chop' and 'tail'. Same interface for all sequences. Con : 'chop' would be slightly more complicated, therefore slower.

template<class It>
slice rpa::range_size< It >::tail ( void   )  [inline]

Returns the sequences end, for algorithms working on one sequence: count,accumulate...


Member Data Documentation

template<class It>
const size_t rpa::range_size< It >::_Size [private]

The number of elements in the input sequence, set by the constructor.

template<class It>
size_t rpa::range_size< It >::_SizePerThr [private]

The 'nominal' number of elements that each sub-thread will process.

All the first sub-threads except the last one will process exactely this number. The last sub-thread, corresponding to the end of the sequence, will process a number of elements between _SizePerThr and 2*_SizePerThr-1. This, because of the rounding errors of the division of _Size by NbThreads.


The documentation for this class was generated from the following file:
Generated on Tue Sep 25 10:20:36 2007 for rpa by  doxygen 1.4.7