#include <assert.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <list>
#include <set>
#include <rpa/testing.h>
#include <rpa/containers/list.h>
#include <rpa/algorithms/transform.h>
Classes | |
struct | Char2Str |
This because we want to use the algorithm 'transform'. More... | |
Defines | |
#define | NB_THR 20 |
Our thread pool. The threads are 'create'-d by the algorithm. | |
#define | NB_SAMPLES ( ( ( 1 << 20 ) + 1 ) * TST_RATIO ) |
Typedefs | |
typedef std::list< std::string > | LstStrT |
Used for storing the results of the algorithm 'transform'. | |
typedef std::back_insert_iterator< LstStrT > | BackInsT |
This is passed as input the the algorithm 'transform'. | |
Functions | |
static void | badRetVal (const char *funcName, const char *typeName) |
Tells that the return value is different from the output iterator. | |
template<class ThrType> | |
static void | main_list_unbounded (int aArgC, const char *const *aArgV, rpa::thr_nb_t aNbThr, ThrType *aThrArray, LstStrT &myLstStrs) |
template<class ThrType> | |
static void | main_list_bounded (int aArgC, const char *const *aArgV, rpa::thr_nb_t aNbThr, ThrType *aThrArray, LstStrT &myLstStrs) |
template<class ThrType> | |
static int | mainIntern (size_t aArgC, const char *const *aArgV, rpa::thr_nb_t aNbThr, ThrType *aThrArray) |
static void | mainThr (int aArgC, const char *const *aArgV) |
int | main (int aArgC, const char **aArgV) |
Variables | |
static char | myStr [NB_SAMPLES][RPA_INT_STR] |
Global variable because too big for the stack. | |
static char * | myPtr [NB_SAMPLES] |
Global variable because too big for the stack. |
#define NB_SAMPLES ( ( ( 1 << 20 ) + 1 ) * TST_RATIO ) |
Power of two, plus one. Multiplied by a ratio for adjusting the tests duration.
#define NB_THR 20 |
Our thread pool. The threads are 'create'-d by the algorithm.
This is passed as input the the algorithm 'transform'.
typedef std::list< std::string > LstStrT |
Used for storing the results of the algorithm 'transform'.
static void badRetVal | ( | const char * | funcName, | |
const char * | typeName | |||
) | [static] |
Tells that the return value is different from the output iterator.
int main | ( | int | aArgC, | |
const char ** | aArgV | |||
) |
Loops on internal data and on the command line. This ensures that a minimal and identical set of data is run, with the extra flexibility of adding other test samples on the command line.
Setup a buffer of random strings.
Tries the algorithm with various sizes, much smaller and much bigger than the number of threads and the size of buffers. Division by two at each step.
For commodity, tests with the command line.
static void main_list_bounded | ( | int | aArgC, | |
const char *const * | aArgV, | |||
rpa::thr_nb_t | aNbThr, | |||
ThrType * | aThrArray, | |||
LstStrT & | myLstStrs | |||
) | [static] |
This function receives an array of const char *, plus its size. It receives too an array of threads, and its size. This function must apply the transform algorithm in these input data, with these threads, an return the result. Note: Tests with a buffer of LIMITED size.
If the buffer has a limited size, we need a mutex for synchronization. That is, the sub-threads buffers must be periodically flushed into the output, and this must be protected.
* '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.
Temporary variable to check the return value.
static void main_list_unbounded | ( | int | aArgC, | |
const char *const * | aArgV, | |||
rpa::thr_nb_t | aNbThr, | |||
ThrType * | aThrArray, | |||
LstStrT & | myLstStrs | |||
) | [static] |
This function receives an array of const char *, plus its size. It receives too an array of threads, and its size. This function must apply the transform algorithm in these input data, with these threads, an return the result. Note: Test with an output buffer of UNLIMITED size.
* 'obuf_iterator' does the same as '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. No mutex is necessary because the buffers have an unlimited size and will be flushed at the end of the execution.
Temporary variable to check the return value.
static int mainIntern | ( | size_t | aArgC, | |
const char *const * | aArgV, | |||
rpa::thr_nb_t | aNbThr, | |||
ThrType * | aThrArray | |||
) | [static] |
Given a set of data, compares the results calculated with the parallel algorithms, with output buffers, when the buffers have a size limit and when they do not have one.
The order of the results is not deterministic, so we must sort before comparing. The input data are all different, so it must be for the results.
Both conditions must be true.
static void mainThr | ( | int | aArgC, | |
const char *const * | aArgV | |||
) | [static] |
This function receives an array of input data, and its size. It applies the tests with these input data, and different kind of threads.
Intermediate tests, to eliminate race conditions. This thread type executes the code 'created'.
In sequential test mode, this will be a 'fake' thread.
Having no threads is equivalent to single-threaded behaviour.
char* myPtr[NB_SAMPLES] [static] |
Global variable because too big for the stack.
char myStr[NB_SAMPLES][RPA_INT_STR] [static] |
Global variable because too big for the stack.