![]() |
Home | Libraries | People | FAQ | More |
While changing the default algorithm model allows one to adjust how parallelable algorithms run, you may also adjust the execution model explicitly at each call-site, overriding the default. This is performed by passing an algorithm model instantiation to a call to the index operation of provided parallelable algorithms.
#include <surge/act/algorithm.hpp>
#include <surge/act/parallel_safe.hpp>
#include <surge/act/common_algo_models.hpp>
#include <vector>
struct operation
: surge::act::parallel_safe
{
void operator ()( int value ) const
{
// Implementation here
}
};
int main()
{
using namespace surge::act;
using std::vector;
vector< int > dummy_data( 100 );
// Executes in parallel regardless of default algorithm model
for_each[ parallel_algo_model() ]( dummy_data.begin(), dummy_data.end()
, operation()
);
// Executes serially regardless of default algorithm model
for_each[ serial_algo_model() ]( dummy_data.begin(), dummy_data.end()
, operation()
);
}
Specifying act models during the instantiation of active types and actions is just as easy. For active types, use SURGE_ACTIVE_M and pass the act model as a second argument, encapsulated in parenthesis. For actions, pass the act model as a second template argument to the standard action template. Keep in mind that if you signal a function on an active object and wish to have a handle to the running operation in the form of an action, you must instantiate the action template with the same act model type.
#include <surge/act/active.hpp>
#include <surge/act/action.hpp>
#include <surge/act/common_act_models.hpp>
int main()
{
using namespace surge::act;
// Use the concurrent act model regardless of the default
SURGE_ACTIVE_M( (int), (concurrent_act_model) ) value = 0;
// Must use the same act model as above
action< int, concurrent_act_model > const other_value = value + 5;
}
| Copyright © 2006 Matthew Calabrese |