#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 | CharPtr2String |
Defines | |
#define | NB_THR 5 |
Our thread pool. The threads are 'create'-d by the algorithm. | |
#define | NB_SAMPLES ( ( ( 1 << 20 ) + 1 ) * TST_RATIO ) |
Typedefs | |
typedef list< string > | LstStrT |
typedef back_insert_iterator< LstStrT > | BackInsT |
Functions | |
template<class Thread> | |
static LstStrT | main_list_unbounded (int aArgC, const char *const *aArgV, rpa::thr_nb_t aNbThr, Thread *aThrArr) |
Test with an output buffer of unlimited size. | |
template<class Thread> | |
static LstStrT | main_list_bounded (int aArgC, const char *const *aArgV, rpa::thr_nb_t aNbThr, Thread *aThrArr, size_t aBufSz) |
'rpatransform' with bounded output buffers, needing periodic flush to the output iterator. | |
template<class Thread> | |
static void | mainIntern (size_t aArgC, const char *const *aArgV, size_t aBufSz, rpa::thr_nb_t aNbThr, Thread *aThrArr) |
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] |
static char * | myPtr [NB_SAMPLES] |
#define NB_SAMPLES ( ( ( 1 << 20 ) + 1 ) * TST_RATIO ) |
Biggest size of input elements. This is a number of two, plus one, because we multiply by two at each loop. This is multiplied by a ratio for tests duration.
#define NB_THR 5 |
Our thread pool. The threads are 'create'-d by the algorithm.
We use template specializations for lists. This file must be included before the templates are instantiated by the algorithms.
typedef list< string > LstStrT |
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. The number starts with 0, then 1, and then is multiplied by two at each loop.
For commodity, tests with the command line.
We intentionaly used 'fake' threads, deterministic ones, so we could check the output order.
static LstStrT main_list_bounded | ( | int | aArgC, | |
const char *const * | aArgV, | |||
rpa::thr_nb_t | aNbThr, | |||
Thread * | aThrArr, | |||
size_t | aBufSz | |||
) | [static] |
'rpatransform' with bounded output buffers, needing periodic flush to the output iterator.
Putting 'void' in an 'obuf_iterator' would mean 'limitless buffer'.
* 'buffer_back_inserter' does the same is 'back_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.
static LstStrT main_list_unbounded | ( | int | aArgC, | |
const char *const * | aArgV, | |||
rpa::thr_nb_t | aNbThr, | |||
Thread * | aThrArr | |||
) | [static] |
Test with an output buffer of unlimited size.
* 'obuf_iterator' does the same as 'back_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.
static void mainIntern | ( | size_t | aArgC, | |
const char *const * | aArgV, | |||
size_t | aBufSz, | |||
rpa::thr_nb_t | aNbThr, | |||
Thread * | aThrArr | |||
) | [static] |
Given a set of data, compares the results calculated with the parallel algorithms, with output buffers, when the buffers are bounded or not.
static void mainThr | ( | int | aArgC, | |
const char *const * | aArgV | |||
) | [static] |
Loops on several number of threads. Tries also several types of deterministic threads, to check that we can reproduce the right order.
This thread type executes the code when 'joined'.
This thread type executes the code when the method 'create' is called. ON top of that, the adapter counts how many times the thread's methods are called.
Depending on the compilation type, this is a real POSIX thread or a 'fake' testing thread such as rpa::thread_crea.
The maximum buffer's size is a power of two, plus one, because we multiply by two, at each loop, the tested value. The number of threads is incremented by two at each loop, because the point is to test ranges of values, not all possibilities.
Multiplied by four at each loop : So, we test a wide values range.
char* myPtr[NB_SAMPLES] [static] |
This array is stored as a global one, because it is too big to lay on the stack.
char myStr[NB_SAMPLES][RPA_INT_STR] [static] |
This array is stored as a global one, because it is too big to lay on the stack.