Public Member Functions | |
| context () | |
| default constructor | |
| virtual | ~context () |
| destructor | |
| template<typename TagColl, typename Step, typename Tuner, typename Arg> | |
| error_type | prescribe (TagColl &tc, const Step &step, const Tuner &tuner, Arg &arg) |
| Convenient was to declare the prescription relationship between a tag collection and a step collection. | |
| error_type | wait () |
| wait until all the steps prescribed by this context have completed execution. | |
| void | flush_gets () |
| used with the preschedule tuner to finalize 'gets' in the pre-execution of a step | |
| void | reset () |
| reset all collections of this context | |
| template<class Index, class Functor> | |
| Functor | parallel_for (Index first, Index last, Index step, const Functor &f, bool gets_items=true) |
| Execute f( i ) for every i in {first <= i=first+step*x < last and 0 <= x}. | |
| template<class Index, class Functor, class Tuner> | |
| Functor | parallel_for (Index first, Index last, Index step, const Functor &f, const Tuner &tuner) |
| Execute f( i ) for every i in {first <= i=first+step*x < last and 0 <= x}. | |
The user needs to derive his or her own context from the CnC::context. The template argument to context is the user's context class itself.
For example,
struct my_context : public CnC::context< my_context > { CnC::tag_collection<int> oddNums; CnC::item_collection<int,int> primes; my_context() : CnC::context< my_context >(), oddNums( this ), primes( this ) { prescribe( oddNums, FindPrimes() ); } };
Several contexts can be created and executed simultaneously.
Execution starts as soon as a step is prescribed. All ready steps will be executed even if CnC::context::wait() is never be called.
It is recommended to declare collections as members of a context derived from CnC::context. This yields more maintanable code and future versions of CnC may require this convention.
Definition at line 267 of file cnc.h.
| error_type prescribe | ( | TagColl & | tc, | |
| const Step & | step, | |||
| const Tuner & | tuner, | |||
| Arg & | arg | |||
| ) | [inline] |
Convenient was to declare the prescription relationship between a tag collection and a step collection.
| step | class/object representing step collection. | |
| tuner | is optional. By default this argument is CnC:default_tuner. | |
| arg | is optional. By default this argument is the derived context class. |
| error_type wait | ( | ) |
wait until all the steps prescribed by this context have completed execution.
| void flush_gets | ( | ) |
used with the preschedule tuner to finalize 'gets' in the pre-execution of a step
Call this after last call to the non-blocking item_collection::unsafe_get method.
| Functor parallel_for | ( | Index | first, | |
| Index | last, | |||
| Index | step, | |||
| const Functor & | f, | |||
| bool | gets_items = true | |||
| ) | [inline] |
Execute f( i ) for every i in {first <= i=first+step*x < last and 0 <= x}.
For different values of i, function execution might occur in parallel. Returns functor object ocne all iterations have been executed. Type Index must support operator+. It uses the tuner default_tuner< Index, derived >
| first | starting index of parallel iteration | |
| last | iteration stops before reaching last | |
| step | iteration step: increase ireation index by step in each iteration | |
| f | function to be executed | |
| gets_items | true (default) if function gets items, false otherwise (might perform better) |
| Functor parallel_for | ( | Index | first, | |
| Index | last, | |||
| Index | step, | |||
| const Functor & | f, | |||
| const Tuner & | tuner | |||
| ) | [inline] |
Execute f( i ) for every i in {first <= i=first+step*x < last and 0 <= x}.
For different values of i, function execution might occur in parallel. Returns functor object ocne all iterations have been executed. Type Index must support operator+.
| first | starting index of parallel iteration | |
| last | iteration stops before reaching last | |
| step | iteration step: increase ireation index by step in each iteration | |
| f | function to be executed | |
| tuner | tuner, must accept Index as tag and derived as Arg |
1.5.6