context Class Template Reference

CnC context bringing together collections and steps and specifies the prescription relationship. More...

List of all members.

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}.


Detailed Description

template<class Derived>
class CnC::context< Derived >

CnC context bringing together collections and steps and specifies the prescription relationship.

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.


Member Function Documentation

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.

See also:
tag_collection::prescribe
Parameters:
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.
Returns:
0 if succeeded, error code otherwise

error_type wait (  ) 

wait until all the steps prescribed by this context have completed execution.

Returns:
0 if succeeded, error code otherwise

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 >

Parameters:
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+.

Parameters:
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


The documentation for this class was generated from the following file:

Generated on Tue Aug 31 15:30:28 2010 for CnC by  doxygen 1.5.6