7 #ifndef NUKLEI_PARALLELIZER_DECL_H
8 #define NUKLEI_PARALLELIZER_DECL_H
15 #include <boost/filesystem.hpp>
16 #include <boost/asio.hpp>
17 #include <boost/thread.hpp>
23 typedef enum { OPENMP = 0, FORK, PTHREAD, SINGLE, UNKNOWN } Type;
24 static const Type defaultType = OPENMP;
25 static const std::string TypeNames[];
33 const Type& type = OPENMP,
34 const unsigned long seed = 0) :
35 n_(n), type_(type), seed_(seed) {}
40 std::string operator()(
const T& t)
49 const T& operator()(
const T& t)
56 <
typename R,
typename Callable>
57 std::vector<R> run(Callable callable)
const
63 <
typename R,
typename Callable,
typename PrintAccessor>
64 std::vector<R> run(Callable callable,
65 PrintAccessor pa)
const
70 return run_openmp<R>(callable, pa);
73 return run_fork<R>(callable, pa);
76 return run_pthread<R>(callable, pa);
79 return run_single<R>(callable, pa);
84 return std::vector<R>();
89 template<
typename R,
typename Callable,
typename Pr
intAccessor>
90 std::vector<R> run_openmp(Callable callable,
91 PrintAccessor pa)
const;
93 template<
typename R,
typename Callable,
typename Pr
intAccessor>
94 std::vector<R> run_fork(Callable callable,
95 PrintAccessor pa)
const;
97 template<
typename R,
typename Callable>
98 struct pthread_wrapper
100 pthread_wrapper(Callable callable) : callable_(callable) {}
101 void operator()(R& ret)
109 template<
typename R,
typename Callable,
typename Pr
intAccessor>
110 std::vector<R> run_pthread(Callable callable,
111 PrintAccessor pa)
const;
113 template<
typename R,
typename Callable,
typename Pr
intAccessor>
114 std::vector<R> run_single(Callable callable,
115 PrintAccessor pa)
const;