#include <accumulate.h>
Inheritance diagram for rpa::accumulate_loop_t< Args, Task, Thread >:
Public Types | |
typedef Args::result_type | result_type |
Public Member Functions | |
const result_type & | reduction (Args *ptrArgs) |
Private Types | |
typedef thread_stack< Task, Thread > | ThrStack |
typedef Args::result_type rpa::accumulate_loop_t< Args, Task, Thread >::result_type |
Reimplemented from rpa::thread_stack< Task, Thread >.
typedef thread_stack< Task, Thread > rpa::accumulate_loop_t< Args, Task, Thread >::ThrStack [private] |
const result_type& rpa::accumulate_loop_t< Args, Task, Thread >::reduction | ( | Args * | ptrArgs | ) | [inline] |
This can be called only when all sub-threads were run. That is, the method loop_t::run() is recursive, with one call per sub-thread. When it has reached the end of sub-threads to run, that is, when it is at the top of the stack, it calls 'reduction' which can then access all results of each sub-thread, and which are stored on the stack. There may be some thrashing due to the access of several threads to the stack of the main thread, but :
Waits until the complete end, with many join(). All intermediate results are in the stack.
Loops with iterators given by the object 'ThrStack', which has a list of all running sub-threads. The sub-threads are accessd in the same order as they were started. This increase the chance that when the first one is finished before the others.
This waits, with 'join', until the sub-thread has finished and and stored its result in the main thread stack. If the main thread has to wait a long time at reduction, it may be worth to add more threads.
Reimplemented in rpa::accumulate_vec< Args, range_step< ItIn, Mutex >, BinOp, ThrIter >::conditional_accumulate_args.