35 #ifndef MADNESS_WORLD_TASKFN_H__INCLUDED
36 #define MADNESS_WORLD_TASKFN_H__INCLUDED
51 template <
typename ptrT,
typename memfnT,
typename resT>
71 volatile World* world;
88 void set_info(World* w, CallbackInterface*
c) {
97 virtual void run(
const TaskThreadEnv& env);
130 MADNESS_EXCEPTION(
"World TaskInterface: user did not implement one of run(world) or run(world, taskthreadenv)", 0);
137 MADNESS_EXCEPTION(
"World TaskInterface: user did not implement run(world, taskthreadenv) for multithreaded task", 0);
149 template <
typename T>
151 static const unsigned int value = 1u;
156 static const unsigned int value = 0u;
160 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T,
161 typename a6T,
typename a7T,
typename a8T,
typename a9T>
163 + ArgCountHelper<a2T>::value + ArgCountHelper<a3T>::value
164 + ArgCountHelper<a4T>::value + ArgCountHelper<a5T>::value
165 + ArgCountHelper<a6T>::value + ArgCountHelper<a7T>::value
166 + ArgCountHelper<a8T>::value + ArgCountHelper<a9T>::value> {
171 template <
typename Arg>
185 operator Arg&() {
return arg_; }
189 template <
typename T>
195 template <
typename T>
213 template <
typename fnT>
231 template <
typename fnT>
234 const voidT&,
const voidT&,
const voidT&,
const voidT&,
235 const voidT&,
const voidT&,
const voidT&,
const voidT&)
236 { fn(); result.
set(); }
238 template <
typename fnT,
typename a1T>
241 const voidT&,
const voidT&,
const voidT&,
const voidT&,
242 const voidT&,
const voidT&,
const voidT&,
const voidT&)
243 { fn(a1); result.
set(); }
245 template <
typename fnT,
typename a1T,
typename a2T>
248 const voidT&,
const voidT&,
const voidT&,
const voidT&,
249 const voidT&,
const voidT&,
const voidT&)
250 { fn(a1, a2); result.
set(); }
252 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T>
255 a3T& a3,
const voidT&,
const voidT&,
const voidT&,
const voidT&,
256 const voidT&,
const voidT&)
257 { fn(a1, a2, a3); result.
set(); }
259 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T>
262 a3T& a3, a4T& a4,
const voidT&,
const voidT&,
const voidT&,
263 const voidT&,
const voidT&)
264 { fn(a1, a2, a3, a4); result.
set(); }
266 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
270 a3T& a3, a4T& a4, a5T& a5,
const voidT&,
const voidT&,
271 const voidT&,
const voidT&)
272 { fn(a1, a2, a3, a4, a5); result.
set(); }
274 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
275 typename a5T,
typename a6T>
278 a3T& a3, a4T& a4, a5T& a5, a6T& a6,
const voidT&,
const voidT&,
280 { fn(a1, a2, a3, a4, a5, a6); result.
set(); }
282 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
283 typename a5T,
typename a6T,
typename a7T>
286 a3T& a3, a4T& a4, a5T& a5, a6T& a6, a7T& a7,
const voidT&,
288 { fn(a1, a2, a3, a4, a5, a6, a7); result.
set(); }
290 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
291 typename a5T,
typename a6T,
typename a7T,
typename a8T>
294 a3T& a3, a4T& a4, a5T& a5, a6T& a6, a7T& a7, a8T& a8,
const voidT&)
295 { fn(a1, a2, a3, a4, a5, a6, a7, a8); result.
set(); }
297 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
298 typename a5T,
typename a6T,
typename a7T,
typename a8T,
typename a9T>
301 a3T& a3, a4T& a4, a5T& a5, a6T& a6, a7T& a7, a8T& a8, a9T& a9)
302 { fn(a1, a2, a3, a4, a5, a6, a7, a8, a9); result.
set(); }
304 template <
typename fnT>
307 fnT fn,
const voidT&,
const voidT&,
const voidT&,
const voidT&,
308 const voidT&,
const voidT&,
const voidT&,
const voidT&,
const voidT&)
309 { result.
set(fn()); }
311 template <
typename fnT,
typename a1T>
314 fnT fn, a1T&
a1,
const voidT&,
const voidT&,
const voidT&,
315 const voidT&,
const voidT&,
const voidT&,
const voidT&,
const voidT&)
316 { result.
set(fn(a1)); }
318 template <
typename fnT,
typename a1T,
typename a2T>
321 fnT fn, a1T&
a1, a2T&
a2,
const voidT&,
const voidT&,
const voidT&,
322 const voidT&,
const voidT&,
const voidT&,
const voidT&)
323 { result.
set(fn(a1, a2)); }
325 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T>
328 fnT fn, a1T&
a1, a2T&
a2, a3T& a3,
const voidT&,
const voidT&,
329 const voidT&,
const voidT&,
const voidT&,
const voidT&)
330 { result.
set(fn(a1, a2, a3)); }
332 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T>
335 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4,
const voidT&,
336 const voidT&,
const voidT&,
const voidT&,
const voidT&)
337 { result.
set(fn(a1, a2, a3, a4)); }
339 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
343 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4, a5T& a5,
const voidT&,
344 const voidT&,
const voidT&,
const voidT&)
345 { result.
set(fn(a1, a2, a3, a4, a5)); }
347 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
348 typename a5T,
typename a6T>
351 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4, a5T& a5, a6T& a6,
352 const voidT&,
const voidT&,
const voidT&)
353 { result.
set(fn(a1, a2, a3, a4, a5, a6)); }
355 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
356 typename a5T,
typename a6T,
typename a7T>
359 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4, a5T& a5, a6T& a6,
360 a7T& a7,
const voidT&,
const voidT&)
361 { result.
set(fn(a1, a2, a3, a4, a5, a6, a7)); }
363 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
364 typename a5T,
typename a6T,
typename a7T,
typename a8T>
367 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4, a5T& a5, a6T& a6,
368 a7T& a7, a8T& a8,
const voidT&)
369 { result.
set(fn(a1, a2, a3, a4, a5, a6, a7, a8)); }
371 template <
typename fnT,
typename a1T,
typename a2T,
typename a3T,
typename a4T,
372 typename a5T,
typename a6T,
typename a7T,
typename a8T,
typename a9T>
375 fnT fn, a1T&
a1, a2T&
a2, a3T& a3, a4T& a4, a5T& a5, a6T& a6,
376 a7T& a7, a8T& a8, a9T& a9)
377 { result.
set(fn(a1, a2, a3, a4, a5, a6, a7, a8, a9)); }
384 template <
typename fnT,
typename arg1T = void,
typename arg2T = void,
385 typename arg3T = void,
typename arg4T = void,
typename arg5T = void,
386 typename arg6T = void,
typename arg7T = void,
typename arg8T = void,
387 typename arg9T =
void>
391 typedef TaskFn<fnT, arg1T, arg2T, arg3T, arg4T, arg5T, arg6T, arg7T,
404 arg4T, arg5T, arg6T, arg7T, arg8T, arg9T>::value;
411 const functionT func_;
426 template <
typename fT>
427 static fT& get_func(fT&
f) {
return f; }
429 template <
typename ptrT,
typename memfnT,
typename resT>
434 virtual void get_id(std::pair<void*,unsigned short>&
id)
const {
435 return make_id(
id, get_func(func_));
443 template <
typename T>
444 inline void check_dependency(Future<T>& fut) {
447 fut.register_callback(
this);
453 template <
typename T>
454 inline void check_dependency(detail::ArgHolder<std::vector<Future<T> > >&
arg) {
455 check_dependency(
static_cast<std::vector<Future<T>
>&>(
arg));
459 template <
typename T>
460 inline void check_dependency(std::vector<Future<T> >&
vec) {
461 for(
typename std::vector<Future<T> >::iterator it =
vec.begin(); it !=
vec.end(); ++it)
462 check_dependency(*it);
466 inline void check_dependency(
const std::vector<Future<void> >&) { }
469 template <
typename T>
470 inline void check_dependency(
const detail::ArgHolder<T>&) { }
473 inline void check_dependency(
const Future<void>&) { }
476 inline void check_dependency(
const Future<Void>&) { }
479 void check_dependencies() {
480 check_dependency(arg1_);
481 check_dependency(arg2_);
482 check_dependency(arg3_);
483 check_dependency(arg4_);
484 check_dependency(arg5_);
485 check_dependency(arg6_);
486 check_dependency(arg7_);
487 check_dependency(arg8_);
488 check_dependency(arg9_);
492 TaskFn(
const TaskFn_&);
493 TaskFn_ operator=(TaskFn_&);
498 TaskInterface(attr), result_(result), func_(func), arg1_(), arg2_(),
499 arg3_(), arg4_(), arg5_(), arg6_(), arg7_(), arg8_(), arg9_()
501 MADNESS_ASSERT(arity == 0u);
502 check_dependencies();
505 template <
typename a1T>
508 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(),
509 arg3_(), arg4_(), arg5_(), arg6_(), arg7_(), arg8_(), arg9_()
511 MADNESS_ASSERT(arity == 1u);
512 check_dependencies();
515 template <
typename a1T,
typename a2T>
518 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
519 arg3_(), arg4_(), arg5_(), arg6_(), arg7_(), arg8_(), arg9_()
521 MADNESS_ASSERT(arity == 2u);
522 check_dependencies();
525 template <
typename a1T,
typename a2T,
typename a3T>
526 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
528 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
529 arg3_(a3), arg4_(), arg5_(), arg6_(), arg7_(), arg8_(), arg9_()
531 MADNESS_ASSERT(arity == 3u);
532 check_dependencies();
535 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T>
536 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
538 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
539 arg3_(a3), arg4_(a4), arg5_(), arg6_(), arg7_(), arg8_(), arg9_()
541 MADNESS_ASSERT(arity == 4u);
542 check_dependencies();
545 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T>
546 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
547 const a3T& a3,
const a4T& a4,
const a5T& a5,
const TaskAttributes& attr) :
548 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
549 arg3_(a3), arg4_(a4), arg5_(a5), arg6_(), arg7_(), arg8_(), arg9_()
551 MADNESS_ASSERT(arity == 5u);
552 check_dependencies();
555 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T,
557 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
558 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
560 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
561 arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), arg7_(), arg8_(), arg9_()
563 MADNESS_ASSERT(arity == 6u);
564 check_dependencies();
567 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T,
568 typename a6T,
typename a7T>
569 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
570 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
572 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
573 arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), arg7_(a7), arg8_(), arg9_()
575 MADNESS_ASSERT(arity == 7u);
576 check_dependencies();
579 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T,
580 typename a6T,
typename a7T,
typename a8T>
581 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
582 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
const a7T& a7,
584 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
585 arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), arg7_(a7), arg8_(a8), arg9_()
587 MADNESS_ASSERT(arity == 8u);
588 check_dependencies();
591 template <
typename a1T,
typename a2T,
typename a3T,
typename a4T,
typename a5T,
592 typename a6T,
typename a7T,
typename a8T,
typename a9T>
593 TaskFn(
const futureT& result, functionT func,
const a1T& a1,
const a2T& a2,
594 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
595 const a7T& a7,
const a8T& a8,
const a9T& a9,
const TaskAttributes& attr) :
596 TaskInterface(attr), result_(result), func_(func), arg1_(a1), arg2_(a2),
597 arg3_(a3), arg4_(a4), arg5_(a5), arg6_(a6), arg7_(a7), arg8_(a8), arg9_(a9)
599 MADNESS_ASSERT(arity == 9u);
600 check_dependencies();
605 TaskInterface(attr), result_(result), func_(func), arg1_(input_arch),
606 arg2_(input_arch), arg3_(input_arch), arg4_(input_arch), arg5_(input_arch),
607 arg6_(input_arch), arg7_(input_arch), arg8_(input_arch), arg9_(input_arch)
614 const futureT&
result()
const {
return result_; }
617 #ifdef HAVE_INTEL_TBB
618 virtual tbb::task* execute() {
620 arg5_, arg6_, arg7_, arg8_, arg9_);
627 arg5_, arg6_, arg7_, arg8_, arg9_);
629 #endif // HAVE_INTEL_TBB
636 #endif // MADNESS_WORLD_TASKFN_H__INCLUDED
const Future< void > type
Definition: taskfn.h:203
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
futureT type
Definition: taskfn.h:217
TaskInterface(const TaskAttributes &attr)
Create a new task with zero dependencies and given attributes.
Definition: taskfn.h:112
void inc()
Increment the number of dependencies.
Definition: worlddep.h:108
ArgHolder(const Arg &arg)
Definition: taskfn.h:177
ArgHolder< T > holderT
Definition: taskfn.h:192
void notify()
Invoked by callbacks to notifiy of dependencies being satisfied.
Definition: worlddep.h:91
const Future< void > type
Definition: taskfn.h:209
const Future< void > holderT
Definition: taskfn.h:210
TaskInterface(int ndepend=0, const TaskAttributes attr=TaskAttributes())
Create a new task with ndepend dependencies (default 0) and given attributes.
Definition: taskfn.h:103
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const TaskAttributes &attr)
Definition: taskfn.h:557
Used to pass info about thread environment into users task.
Definition: worldthread.h:289
This class used for callbacks (e.g., for dependency tracking)
Definition: worlddep.h:51
const Future< void > holderT
Definition: taskfn.h:204
Specialization of Future for internal convenience ... does nothing useful!
Definition: worldfut.h:598
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const a7T &a7, const a8T &a8, const TaskAttributes &attr)
Definition: taskfn.h:581
static void set(const Future< void > &)
Definition: worldfut.h:616
TaskFn(const futureT &result, functionT func, const TaskAttributes &attr, archive::BufferInputArchive &input_arch)
Definition: taskfn.h:603
NDIM & f
Definition: mra.h:2179
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const TaskAttributes &attr)
Definition: taskfn.h:536
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const TaskAttributes &attr)
Definition: taskfn.h:546
disable_if from Boost for conditionally instantiating templates based on type
Definition: enable_if.h:78
Tensor< typename Tensor< T >::scalar_type > arg(const Tensor< T > &t)
Return a new tensor holding the argument of each element of t (complex types only) ...
Definition: tensor.h:2429
Multi-threaded queue to manage and run tasks.
Definition: worldtask.h:393
Lowest level task interface.
Definition: worldthread.h:636
virtual ~TaskInterface()
Definition: taskfn.h:143
virtual void run(World &world, const TaskThreadEnv &env)
Runs a multi-threaded task.
Definition: taskfn.h:134
T type
Definition: taskfn.h:191
const double a2
Definition: vnucso.cc:91
madness::remove_fcvr< typename madness::detail::result_of< fnT >::type >::type resultT
Definition: taskfn.h:215
static const unsigned int arity
Definition: taskfn.h:403
static const unsigned int value
Definition: taskfn.h:151
enable_if< std::is_void< typename detail::result_of< fnT >::type > >::type run_function(Future< void > &result, fnT fn, const voidT &, const voidT &, const voidT &, const voidT &, const voidT &, const voidT &, const voidT &, const voidT &, const voidT &)
Definition: taskfn.h:233
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
Provides interface for tracking dependencies.
Definition: worlddep.h:60
Vector< T, 1 > vec(T x)
Your friendly neighborhood factory function.
Definition: array.h:456
static void add(PoolTaskInterface *task)
Add a new task to the pool.
Definition: worldthread.h:984
TaskFn(const futureT &result, functionT func, const a1T &a1, const TaskAttributes &attr)
Definition: taskfn.h:506
static bool debug
Definition: taskfn.h:100
World * get_world() const
Definition: taskfn.h:141
Future< void > voidT
Definition: taskfn.h:222
Implements Dqueue, Thread, ThreadBase and ThreadPool.
virtual void run(const TaskThreadEnv &env)
Override this method to implement a multi-threaded task.
Definition: worldtask.cc:44
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const TaskAttributes &attr=TaskAttributes())
Definition: taskfn.h:516
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const a7T &a7, const TaskAttributes &attr)
Definition: taskfn.h:569
virtual ~TaskFn()
Definition: taskfn.h:612
int nthread() const
Definition: worldthread.h:307
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
Wrap a callable object and its arguments into a task function.
Definition: taskfn.h:388
TaskAttributes(unsigned long flags=0)
Definition: worldthread.h:216
Contains attributes of a task.
Definition: worldthread.h:208
const double a1
Definition: vnucso.cc:90
Definition: typestuff.h:77
static enable_if_c< detail::function_traits< fnT >::value||detail::memfunc_traits< fnT >::value >::type make_id(std::pair< void *, unsigned short > &id, fnT fn)
Definition: worldthread.h:680
fnT functionT
The task function type.
Definition: taskfn.h:396
A future is a possibly yet unevaluated value.
Definition: ref.h:210
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const a7T &a7, const a8T &a8, const a9T &a9, const TaskAttributes &attr)
Definition: taskfn.h:593
virtual void run(World &)
Runs a single-threaded task ... derived classes must implement this.
Definition: taskfn.h:128
detail::task_result_type< fnT >::resultT resultT
The result type of the function.
Definition: taskfn.h:397
Definition: integral_constant.h:7
ArgHolder(const archive::BufferInputArchive &input_arch)
Definition: taskfn.h:179
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
All world tasks must be derived from this public interface.
Definition: taskfn.h:68
virtual void run(const TaskThreadEnv &env)
Override this method to implement a multi-threaded task.
Definition: taskfn.h:625
void set(const Future< T > &other)
A.set(B) where A & B are futures ensures A has/will have the same value as B.
Definition: worldfut.h:473
const futureT & result() const
Definition: taskfn.h:614
Future< T > holderT
Definition: taskfn.h:198
T type
Definition: taskfn.h:197
enable_if from Boost for conditionally instantiating templates based on type
Definition: enable_if.h:60
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
detail::task_result_type< fnT >::futureT futureT
Definition: taskfn.h:399
const double c
Definition: gfit.cc:200
A wrapper object for holding task function objects.
Definition: taskfn.h:172
TaskFn(const futureT &result, functionT func, const a1T &a1, const a2T &a2, const a3T &a3, const TaskAttributes &attr)
Definition: taskfn.h:526
void register_callback(CallbackInterface *callback)
Registers a callback for when ndepend==0 , immediately invoked if ndepend==0.
Definition: worlddep.h:94
TaskFn(const futureT &result, functionT func, const TaskAttributes &attr)
Definition: taskfn.h:497
Defines DependencyInterface and CallbackInterface.
memfnT get_mem_func_ptr(const MemFuncWrapper< ptrT, memfnT, resT > &)
Definition: worldtask.h:385
Disables default copy constructor and assignment operators.
Definition: nodefaults.h:49
Future< resultT > futureT
Definition: taskfn.h:216