Skip to content

Instantly share code, notes, and snippets.

@pesterie
Created July 5, 2012 21:58
Show Gist options
  • Save pesterie/3056749 to your computer and use it in GitHub Desktop.
Save pesterie/3056749 to your computer and use it in GitHub Desktop.
register functor
#include <hpx/hpx.hpp>
#include <hpx/hpx_init.hpp>
#include <hpx/runtime/actions/plain_action.hpp>
#include <hpx/components/dataflow/dataflow.hpp>
#include <iostream>
#include <cstdlib>
template<class T>
struct add_
{
typedef T result_type;
T operator()(T const& a, T const& b)
{
return a+b;
}
};
typedef hpx::actions::
plain_result_action2< int
, int const&
, int const&
, add_<int>
> add_action;
HPX_REGISTER_PLAIN_ACTION(add_action);
int hpx_main()
{
using hpx::lcos::dataflow;
using hpx::lcos::dataflow_base;
hpx::naming::id_type here = hpx::find_here();
dataflow_base<int> flow = dataflow<add_action>(here, 3, 2);
int result = flow.get_future().get();
std::cout << "Result: " << result << std::endl;
return hpx::finalize();
}
int main(int argc, char **argv)
{
return hpx::init(argc, argv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment