t05_ArgsReverseRngSize.cpp File Reference

#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <rpa/containers/vector.h>
#include <rpa/algorithms/transform.h>

Defines

#define NB_THR   3
 The maximum number of threads that will be used.
#define OUT_BUF_SIZ   10

Typedefs

typedef std::vector< std::string > VecStrT
 The output will be stored in such a container.
typedef std::string BufType [OUT_BUF_SIZ]
typedef BufType BufGen [NB_THR]
typedef std::back_insert_iterator<
VecStrT
BackInsT
typedef VecStrT::iterator IterOutT
 This applies for algorithms writing in a plain vector.

Functions

static std::string ReverseString (const std::string &aStr)
static void Tst05 (const char *ptrStr, bool mustBeFalse)
 Simple helper function for tests.
template<class InputRange>
VecStrT Tst05_BackInsBounded (const InputRange &refInpRng, size_t nbElts)
template<class InputRange>
VecStrT Tst05_PlainBounded (const InputRange &refInpRng, size_t nbElts)
 This writes with buffers into a vector which is already allocated.
static void Cmp05 (const VecStrT &refVecGood, const char *ptrComment, const VecStrT &refVecTest)
 The input vectors must be sorted before.
template<class InputRange>
void Tst05_Range (size_t nbElts, const InputRange &refInpRng)
int main (int aArgC, const char **aArgV)

Variables

static rpa::testing_thread myThr [NB_THR]
 Our thread pool. The threads are actually created by the algorithm.
BufGen buffersPool
 This pool of buffer is reused by all tests, for speeding up performanc performances.
static rpa::testing_mutex boundMtx
 This is used by all algorithms with a bounded buffer.

Define Documentation

#define NB_THR   3

The maximum number of threads that will be used.

Transforms the arguments of a C-style array into a std::array of std::string. It uses C-style fixed-size arrays as output buffers.

#define OUT_BUF_SIZ   10

The size of each buffer. Each thread is therefore able to process this number of elements and then must flush to the output iterator.


Typedef Documentation

typedef std::back_insert_iterator< VecStrT > BackInsT

The output will be stored in a vector, but with such an insertion iterator. As this kind of insertion is inherently serialised, we use 'obuf_iterator' which stores the results of each sub-thread in a buffer, before merging them at the end.

typedef BufType BufGen[NB_THR]

For eficiency, we provide the algorithm with several buffers, already allocated. There must be one buffer per sub-thread : These buffers are given in the same order as the thread tree. So it is straightforward, for example, to take into account the affinity of each processor for each memory zone.

typedef std::string BufType[OUT_BUF_SIZ]

This is the kind of buffer that each sub-thread uses for storing its intermediate results.

typedef VecStrT::iterator IterOutT

This applies for algorithms writing in a plain vector.

typedef std::vector< std::string > VecStrT

The output will be stored in such a container.


Function Documentation

static void Cmp05 ( const VecStrT refVecGood,
const char *  ptrComment,
const VecStrT refVecTest 
) [static]

The input vectors must be sorted before.

int main ( int  aArgC,
const char **  aArgV 
)

static std::string ReverseString ( const std::string &  aStr  )  [static]

This function will be applied to each argument of the command line, with the STL algorithm std::transform. It is slow but the point of this test is not performance.

static void Tst05 ( const char *  ptrStr,
bool  mustBeFalse 
) [static]

Simple helper function for tests.

template<class InputRange>
VecStrT Tst05_BackInsBounded ( const InputRange &  refInpRng,
size_t  nbElts 
)

This does a transform into a vector of strings accessed with a std::back_inserter. It returns the result which can then be checked. The buffers are bounded, with a maximum size.

The output iterator which is actually used by our algorithm. A mutex is necessary because the buffers have a limited size, and must be periodically flushed into the output vector.

The result to be returned.

* 'buffer_back_inserter' does the same is 'stdback_inserter', but allows more parallelization. 'make_thread_tree' creates, out of any threads iterator, a 'thread_tree' object which is necessary for parallel execution. A mutex is necessary because buffers have a limited size and will be periodically flushed into the output iterator.

Now, we want to ensure that the returned iterator is a back_insert_iterator which just points one position beyond the end of the vector.

template<class InputRange>
VecStrT Tst05_PlainBounded ( const InputRange &  refInpRng,
size_t  nbElts 
)

This writes with buffers into a vector which is already allocated.

The output iterator which is actually used by our algorithm. A mutex is necessary because the buffers have a limited size, and must be periodically flushed into the output vector.

Checks that the returned iterator points at the end of the vector.

template<class InputRange>
void Tst05_Range ( size_t  nbElts,
const InputRange &  refInpRng 
)

Creates an array of input strings and processes them with several scheduling policies.

First, calculates what the result should be.

At the same time, it checks that the ranges can be properly accessed in a sequential way (Plain begin() and end() methods).


Variable Documentation

rpa::testing_mutex boundMtx [static]

This is used by all algorithms with a bounded buffer.

BufGen buffersPool

This pool of buffer is reused by all tests, for speeding up performanc performances.

rpa::testing_thread myThr[NB_THR] [static]

Our thread pool. The threads are actually created by the algorithm.


Generated on Tue Sep 25 10:20:31 2007 for rpa by  doxygen 1.4.7