39 #ifndef MADNESS_WORLD_WORLDOBJ_H__INCLUDED
40 #define MADNESS_WORLD_WORLDOBJ_H__INCLUDED
60 : id(id), handler(handler), arg(
copy_am_arg(arg)) {}
79 template <
typename memfunT>
93 , requestor(requestor)
98 template <
typename Archive>
104 template <
typename memfunT>
120 info_base<memfunT>(id, requestor, memfun, attr), ref(ref)
123 template <
typename Archive>
166 template <
class Derived>
168 typedef WorldObject<Derived> objT;
169 typedef std::list<detail::PendingMsg> pendingT;
178 static volatile pendingT pending;
194 obj = arg.
get_world()->
template ptr_from_id<Derived>(
id);
198 if (p->ready || arg.is_pending())
return true;
201 pending_mutex.
lock();
202 if (!obj) obj = arg.
get_world()->
template ptr_from_id<Derived>(
id);
206 if (p->ready || arg.is_pending()) {
211 const_cast<AmArg&
>(
arg).set_pending();
219 template <
typename memfunT,
typename arg1T,
typename arg2T,
typename arg3T,
typename arg4T,
220 typename arg5T,
typename arg6T,
typename arg7T,
typename arg8T,
typename arg9T>
221 static void handler(
const AmArg&
arg) {
223 am_handlerT ptr = handler<memfunT,arg1T,arg2T,arg3T,arg4T,arg5T,arg6T,arg7T,arg8T,arg9T>;
225 if (is_ready(
id,obj,arg,ptr)) {
236 arg & info & arg1 & arg2 & arg3 & arg4 & arg5 & arg6 & arg7 & arg8 & arg9;
239 arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
244 template <
typename taskT>
245 static void spawn_remote_task_handler(
const AmArg& arg) {
246 MADNESS_ASSERT(taskT::arity <= 9u);
248 const uniqueidT&
id = detail::peek(arg);
249 am_handlerT ptr = & objT::template spawn_remote_task_handler<taskT>;
251 if (is_ready(
id,obj,arg,ptr)) {
252 detail::info<typename taskT::functionT::memfn_type> info;
254 archive::BufferInputArchive input_arch = arg & info;
257 taskT*
task =
new taskT(
typename taskT::futureT(info.ref),
261 arg.get_world()->taskq.add(task);
265 template <
typename T>
266 static inline const T& am_arg(
const Future<T>&
f) {
267 MADNESS_ASSERT(f.probe());
271 template <
typename T>
static inline const T& am_arg(
const T& t) {
return t; }
273 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
274 typename a4T,
typename a5T,
typename a6T,
typename a7T,
275 typename a8T,
typename a9T>
276 typename detail::task_result_type<memfnT>::futureT
277 send_am(
ProcessID dest, memfnT memfn,
const a1T&
a1,
const a2T&
a2,
278 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
279 const a7T& a7,
const a8T& a8,
const a9T& a9)
const
281 typename detail::task_result_type<memfnT>::futureT result;
284 a1, a2, a3, a4, a5, a6, a7, a8, a9);
286 detail::info<memfnT> info(objid, me, memfn, result.remote_ref(world));
287 world.
am.
send(dest, & objT::template handler<memfnT, a1T, a2T, a3T, a4T, a5T, a6T, a7T, a8T, a9T>,
288 new_am_arg(info, a1, a2, a3, a4, a5, a6, a7, a8, a9));
294 template <
typename taskT,
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
295 typename a4T,
typename a5T,
typename a6T,
typename a7T,
296 typename a8T,
typename a9T>
297 typename taskT::futureT
298 send_task(
ProcessID dest, memfnT memfn,
const a1T& a1,
299 const a2T& a2,
const a3T& a3,
const a4T& a4,
const a5T& a5,
300 const a6T& a6,
const a7T& a7,
const a8T& a8,
const a9T& a9,
301 const TaskAttributes& attr)
const
303 typename taskT::futureT result;
304 detail::info<memfnT> info(objid, me, memfn, result.remote_ref(world), attr);
305 world.
am.
send(dest, & objT::template spawn_remote_task_handler<taskT>,
306 new_am_arg(info, a1, a2, a3, a4, a5, a6, a7, a8, a9));
311 template <
typename memfnT>
312 typename enable_if_c<detail::memfunc_traits<memfnT>::constness,
const Derived*>::type
313 get_derived()
const {
return static_cast<const Derived*
>(
this); }
316 template <
typename memfnT>
317 typename disable_if_c<detail::memfunc_traits<memfnT>::constness, Derived*>::type
318 get_derived()
const {
return const_cast<Derived*
>(
static_cast<const Derived*
>(
this)); }
338 pending_mutex.
lock();
339 pendingT& nv =
const_cast<pendingT&
>(pending);
340 for (pendingT::iterator it=nv.begin(); it!=nv.end();) {
350 if (tmp.size() == 0) ready=
true;
354 tmp.front().invokehandler();
373 , objid(world.register_ptr(static_cast<Derived*>(this))) {};
386 template <
typename memfnT>
394 template <
typename memfnT,
typename a1T>
402 template <
typename memfnT,
typename a1T,
typename a2T>
405 return send_am(dest, memfn, am_arg(a1), am_arg(a2),
voidT::value,
410 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T>
415 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
420 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
424 const a3T& a3,
const a4T& a4)
const
426 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
431 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
432 typename a4T,
typename a5T>
435 const a3T& a3,
const a4T& a4,
const a5T& a5)
const
437 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
442 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
443 typename a4T,
typename a5T,
typename a6T>
446 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6)
const
448 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
453 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
454 typename a4T,
typename a5T,
typename a6T,
typename a7T>
457 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
460 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
461 am_arg(a4), am_arg(a5), am_arg(a6), am_arg(a7),
voidT::value,
465 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
466 typename a4T,
typename a5T,
typename a6T,
typename a7T,
typename a8T>
469 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
470 const a7T& a7,
const a8T& a8)
const
472 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
473 am_arg(a4), am_arg(a5), am_arg(a6), am_arg(a7), am_arg(a8),
477 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
478 typename a4T,
typename a5T,
typename a6T,
typename a7T,
typename a8T,
482 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
483 const a7T& a7,
const a8T& a8,
const a9T& a9)
const
485 return send_am(dest, memfn, am_arg(a1), am_arg(a2), am_arg(a3),
486 am_arg(a4), am_arg(a5), am_arg(a6), am_arg(a7), am_arg(a8),
491 template <
typename memfnT>
497 return world.
taskq.
add(get_derived<memfnT>(), memfn, attr);
505 template <
typename memfnT,
typename a1T>
513 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, attr);
515 return send_task<taskT>(dest, memfn, am_arg(a1),
voidT::value,
521 template <
typename memfnT,
typename a1T,
typename a2T>
530 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, attr);
532 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
538 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T>
548 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, attr);
550 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
556 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
568 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, attr);
570 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
576 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
577 typename a4T,
typename a5T>
580 const a3T& a3,
const a4T& a4,
const a5T& a5,
590 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, a5, attr);
592 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
598 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
599 typename a4T,
typename a5T,
typename a6T>
602 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
613 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, a5, a6, attr);
615 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
616 am_arg(a3), am_arg(a4), am_arg(a5), am_arg(a6),
622 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
623 typename a4T,
typename a5T,
typename a6T,
typename a7T>
626 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
638 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, a5, a6, a7, attr);
640 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
641 am_arg(a3), am_arg(a4), am_arg(a5), am_arg(a6),
646 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
647 typename a4T,
typename a5T,
typename a6T,
typename a7T,
typename a8T>
650 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
651 const a7T& a7,
const a8T& a8,
664 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, a5, a6, a7, a8, attr);
666 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
667 am_arg(a3), am_arg(a4), am_arg(a5), am_arg(a6),
673 template <
typename memfnT,
typename a1T,
typename a2T,
typename a3T,
674 typename a4T,
typename a5T,
typename a6T,
typename a7T,
typename a8T,
678 const a3T& a3,
const a4T& a4,
const a5T& a5,
const a6T& a6,
679 const a7T& a7,
const a8T& a8,
const a9T& a9,
693 return world.
taskq.
add(get_derived<memfnT>(), memfn, a1, a2, a3, a4, a5, a6, a7, a8, a9, attr);
695 return send_task<taskT>(dest, memfn, am_arg(a1), am_arg(a2),
696 am_arg(a3), am_arg(a4), am_arg(a5), am_arg(a6),
697 am_arg(a7), am_arg(a8), am_arg(a9), attr);
707 template <
class Derived>
713 MADNESS_ASSERT(world);
715 if (!ptr)
MADNESS_EXCEPTION(
"WorldObj: remote operation attempting to use a locally uninitialized object",0);
719 template <
class Derived>
726 template <
class Derived>
732 MADNESS_ASSERT(world);
734 if (!ptr)
MADNESS_EXCEPTION(
"WorldObj: remote operation attempting to use a locally uninitialized object",0);
738 template <
class Derived>
747 #ifdef WORLD_INSTANTIATE_STATIC_TEMPLATES
748 template <
typename Derived>
755 #endif // MADNESS_WORLD_WORLDOBJ_H__INCLUDED
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4) const
Definition: worldobj.h:423
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, 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=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6,a7,a8)".
Definition: worldobj.h:649
void free_am_arg(AmArg *arg)
Frees an AmArg allocated with alloc_am_arg.
Definition: worldam.h:178
World * get_world() const
For incoming AM gives the associated world.
Definition: worldam.h:155
void process_pending()
To be called from derived constructor to process pending messages.
Definition: worldobj.h:330
void(* am_handlerT)(const AmArg &)
Type of AM handler functions.
Definition: worldam.h:78
World active message that extends an RMI message.
Definition: worldam.h:81
World & get_world() const
Returns a reference to the world.
Definition: worldobj.h:382
RemoteReference< FutureImpl< REMFUTURE(MEMFUN_RETURNT(memfunT)) > > refT
Definition: worldobj.h:107
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6) const
Definition: worldobj.h:445
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1)".
Definition: worldobj.h:507
static void store(const BufferOutputArchive &ar, const WorldObject< Derived > *const &ptr)
Definition: worldobj.h:740
AmArg * arg
Definition: worldobj.h:57
PendingMsg(uniqueidT id, am_handlerT handler, const AmArg &arg)
Definition: worldobj.h:59
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3)".
Definition: worldobj.h:540
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const a7T &a7) const
Definition: worldobj.h:456
AmArg * new_am_arg(const A &a, const B &b, const C &c, const D &d, const E &e, const F &f, const G &g, const H &h, const I &i, const J &j)
Convenience template for serializing arguments into a new AmArg.
Definition: worldam.h:185
Definition: worldobj.h:54
Definition: uniqueid.h:46
void unlock() const
Free a spinlock owned by this thread.
Definition: worldmutex.h:230
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn) const
Definition: worldobj.h:388
Specialization of Future for internal convenience ... does nothing useful!
Definition: worldfut.h:598
static void store(const BufferOutputArchive &ar, WorldObject< Derived > *const &ptr)
Definition: worldobj.h:721
void lock() const
Acquire the spinlock waiting if necessary.
Definition: worldmutex.h:224
info(const uniqueidT &id, ProcessID requestor, memfunT memfun, const refT &ref, const TaskAttributes &attr=TaskAttributes())
Definition: worldobj.h:118
const uniqueidT & id() const
Returns the globally unique object ID.
Definition: worldobj.h:377
NDIM & f
Definition: mra.h:2179
Definition: worldobj.h:105
Default store of a thingy via serialize(ar,t)
Definition: archive.h:708
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3) const
Definition: worldobj.h:412
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
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1) const
Definition: worldobj.h:396
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, 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
Definition: worldobj.h:468
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6)".
Definition: worldobj.h:601
static World * world_from_id(unsigned long id)
Convert world id to world pointer.
Definition: worldfwd.h:628
WorldAmInterface & am
AM interface.
Definition: worldfwd.h:460
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5) const
Definition: worldobj.h:434
T type
Definition: taskfn.h:191
am_handlerT handler
Definition: worldobj.h:56
Future< REMFUTURE(MEMFUN_RETURNT(memfunT)) > futureT
Definition: worldobj.h:106
Wraps an archive around a memory buffer for output.
Definition: bufar.h:58
void serialize(const Archive &ar)
Definition: worldobj.h:124
const double a2
Definition: vnucso.cc:91
info_base(const uniqueidT &id, ProcessID requestor, memfunT memfun, const TaskAttributes &attr=TaskAttributes())
Definition: worldobj.h:90
memfunT memfun
Definition: worldobj.h:83
Simple structure used to manage references/pointers to remote instances.
Definition: worldref.h:59
refT ref
Definition: worldobj.h:108
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
info_base()
Definition: worldobj.h:88
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5)".
Definition: worldobj.h:579
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6,a7,a8,a9)".
Definition: worldobj.h:493
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, 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=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6,a7,a8,a9)".
Definition: worldobj.h:677
ProcessID requestor
Definition: worldobj.h:82
MemFuncWrapper< objT *, memfnT, typename result_of< memfnT >::type > wrap_mem_fn(objT &obj, memfnT memfn)
Definition: worldtask.h:358
Implements Dqueue, Thread, ThreadBase and ThreadPool.
Default load of a thingy via serialize(ar,t)
Definition: archive.h:718
uniqueidT id
Definition: worldobj.h:81
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2) const
Definition: worldobj.h:404
void unregister_ptr(T *ptr)
Unregister a unique id for a local pointer.
Definition: worldfwd.h:575
bool initialized()
Definition: world.cc:70
uniqueidT id
Definition: worldobj.h:55
RMI::Request send(const ProcessID dest, am_handlerT op, const AmArg *arg, const int attr=RMI::ATTR_ORDERED, const bool managed=true)
Sends an unmanaged non-blocking active message.
Definition: worldam.h:386
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const a5T &a5, const a6T &a6, const a7T &a7, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4,a5,a6,a7)".
Definition: worldobj.h:625
Implements most parts of a globally addressable object (via unique ID)
Definition: worldam.h:74
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2)".
Definition: worldobj.h:523
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
Wrap a callable object and its arguments into a task function.
Definition: taskfn.h:388
Definition: worldobj.h:80
detail::task_result_type< memfnT >::futureT task(ProcessID dest, memfnT memfn, const a1T &a1, const a2T &a2, const a3T &a3, const a4T &a4, const TaskAttributes &attr=TaskAttributes()) const
Sends task to derived class method "returnT (this->*memfn)(a1,a2,a3,a4)".
Definition: worldobj.h:559
archive_array< unsigned char > wrap_opaque(const T *, unsigned int)
Factory function to wrap pointer to contiguous data as opaque (uchar) archive_array.
Definition: archive.h:827
void add(TaskInterface *t)
Add a new local task taking ownership of the pointer.
Definition: worldtask.h:473
TaskAttributes attr
Definition: worldobj.h:84
WorldTaskQueue & taskq
Task queue.
Definition: worldfwd.h:461
Contains attributes of a task.
Definition: worldthread.h:208
const double a1
Definition: vnucso.cc:90
void serialize(const Archive &ar)
Definition: worldobj.h:99
static const Future< void > value
Definition: worldfut.h:602
WorldObject(World &world)
Associates object with globally unique ID.
Definition: worldobj.h:369
detail::task_result_type< memfnT >::futureT send(ProcessID dest, memfnT memfn, 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
Definition: worldobj.h:481
Defines TaskInterface and implements WorldTaskQueue and associated stuff.
T * ptr_from_id(uniqueidT id) const
Look up local pointer from world-wide unique id.
Definition: worldfwd.h:597
info(const AmArg &arg)
Definition: worldobj.h:112
A future is a possibly yet unevaluated value.
Definition: ref.h:210
AmArg * copy_am_arg(const AmArg &arg)
Definition: worldam.h:171
virtual ~WorldObject()
Definition: worldobj.h:700
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
Spinlock using pthread spinlock operations.
Definition: worldmutex.h:200
info()
Definition: worldobj.h:110
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
void invokehandler()
Definition: worldobj.h:62
unsigned char * buf() const
Returns a pointer to the user's payload (aligned in same way as AmArg)
Definition: worldam.h:133
World & world
Think globally act locally.
Definition: worldobj.h:171