MADNESS  version 0.9
worldfut.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 
36 #ifndef MADNESS_WORLD_WORLDFUT_H__INCLUDED
37 #define MADNESS_WORLD_WORLDFUT_H__INCLUDED
38 
42 
43 #include <vector>
44 #include <stack>
45 #include <new>
47 #include <madness/world/worlddep.h>
48 #include <madness/world/array.h>
50 #include <madness/world/worldref.h>
52 #include <madness/world/worldfwd.h>
53 #include <madness/world/move.h>
54 
55 namespace madness {
56 
57  //extern SharedCounter future_count; // For tracking memory leak
58 
59 
60 /*
61 
62 \section gotchas Gotchas
63 
64 \subsection futures Futures and STL vectors (e.g., \c vectors<Future<int>> )
65 
66  This to be turned back into documentation eventually
67 
68 A common misconception is that STL containers initialize their
69 contents by \invoking the default constructor of each item in
70 the container since we are told that the items must be default
71 constructable. But this is \em incorrect. The items are initialized
72 by invoking the copy constructor for each element on a \em single
73 object made with the default constructor. For futures this
74 is a very bad problem. For instance,
75 \code
76  vector< Future<double> > v(3);
77 \endcode
78 is equivalent to the following with an array of three elements
79 \code
80  Future<double> junk;
81  Future<double> v[3] = {junk,junk,junk};
82 \endcode
83 Since the Future copy constructor is by necessity shallow, each
84 element of \c v ends up referring to the future implementation that
85 underlies \c junk. When you assign to an element of \c v, you'll also
86 be assigning to junk. But since futures are single assignment
87 variables, you can only do that once. Hence, when you assign a
88 second element of \c v you'll get a runtime exception.
89 
90 The fix (other than using arrays) is to initialize STL vectors and
91 other containers from the special element returned by
92 \c Future<T>::default_initializer() which if passed into the copy
93 constructor will cause it to behave just like the default contructor.
94 Thus, the following code is what you actually need to use an STL
95 vector of futures
96 \code
97  vector< Future<double> > v(3,Future<double>::default_initializer());
98 \endcode
99 which sucks, so we provide the factory function
100 \code
101  template <typename T>
102  vector< Future<T> > future_vector_factory(std::size_t n);
103 \endcode
104 which enables you to write
105 \code
106  vector< Future<double> > v = future_vector_factory<double>(3);
107 \endcode
108 which merely blows instead of sucking.
109 */
110 
111  template <typename T> class Future;
112 
114 
116  template <typename T>
117  struct is_future : public std::false_type { };
118 
120 
122  template <typename T>
123  struct is_future< Future<T> > : public std::true_type { };
124 
126 
128  template <typename T>
129  struct remove_future {
130  typedef T type;
131  };
132 
134 
136  template <typename T>
137  struct remove_future< Future<T> > {
138  typedef T type;
139  };
140 
142 
144 #define REMFUTURE(T) typename remove_future< T >::type
145 
147 
149  template <typename T>
150  std::ostream& operator<<(std::ostream& out, const Future<T>& f);
151 
152 
154 
156  template <typename T>
157  class FutureImpl : private Spinlock {
158  friend class Future<T>;
159  friend std::ostream& operator<< <T>(std::ostream& out, const Future<T>& f);
160 
161  private:
162  static const int MAXCALLBACKS = 4;
163  typedef std::stack<CallbackInterface*, std::vector<CallbackInterface*> > callbackT;
164  typedef Stack<std::shared_ptr< FutureImpl<T> >,MAXCALLBACKS> assignmentT;
165  volatile callbackT callbacks;
166  volatile mutable assignmentT assignments;
167  volatile bool assigned;
168  RemoteReference< FutureImpl<T> > remote_ref;
169  volatile T t;
170 
172  static void set_handler(const AmArg& arg) {
174  archive::BufferInputArchive input_arch = arg & ref;
175  // The remote reference holds a copy of the shared_ptr, so no need
176  // to take another.
177  {
178  FutureImpl<T>* pimpl = ref.get();
179 
181  if(pimpl->remote_ref) {
182  // Unarchive the value to a temporary since it is going to
183  // be forwarded to another node.
184  T value;
185  input_arch & value;
186 
187  // Copy world and owner from remote_ref since sending remote_ref
188  // will invalidate it.
189  World& world = pimpl->remote_ref.get_world();
190  const ProcessID owner = pimpl->remote_ref.owner();
191  world.am.send(owner, FutureImpl<T>::set_handler,
192  new_am_arg(pimpl->remote_ref, value));
193 
194  pimpl->set_assigned(value);
195  } else {
196  // Unarchive the value of the future
197  input_arch & const_cast<T&>(pimpl->t);
198 
199  pimpl->set_assigned(const_cast<const T&>(pimpl->t));
200  }
201  }
202  ref.reset();
203  }
204 
206  inline void set_assigned(const T& value) {
207  // Assume that whoever is invoking this routine is holding
208  // a copy of our shared pointer on its *stack* so that
209  // if this future is destroyed as a result of a callback
210  // the destructor of this object is not invoked until
211  // we return.
212  //
213  // Also assume that the caller either has the lock
214  // or is sure that we are single threaded.
215  MADNESS_ASSERT(!assigned);
216  assigned = true;
217 
218  assignmentT& as = const_cast<assignmentT&>(assignments);
219  callbackT& cb = const_cast<callbackT&>(callbacks);
220 
221  while (!as.empty()) {
222  MADNESS_ASSERT(as.front());
223  as.top()->set(value);
224  as.pop();
225  }
226 
227  while (!cb.empty()) {
228  MADNESS_ASSERT(cb.top());
229  cb.top()->notify();
230  cb.pop();
231  }
232  }
233 
234  // Pass by value with implied copy to manage lifetime of f
235  inline void add_to_assignments(const std::shared_ptr< FutureImpl<T> > f) {
236  // ASSUME lock is already acquired
237  if (assigned) {
238  f->set(const_cast<T&>(t));
239  }
240  else {
241  assignmentT* as = const_cast<assignmentT*>(&assignments);
242  as->push(f);
243  }
244  }
245 
246 
247  public:
248 
249  // Local unassigned value
251  : callbacks()
252  , assignments()
253  , assigned(false)
254  , remote_ref()
255  , t()
256  { }
257 
258 
259  // Wrapper for a remote future
261  : callbacks()
262  , assignments()
263  , assigned(false)
264  , remote_ref(remote_ref)
265  , t()
266  { }
267 
268 
269  // Returns true if the value has been assigned
270  inline bool probe() const { return assigned; }
271 
272 
273  // Registers a function to be invoked when future is assigned
274 
275  // Callbacks are invoked in the order registered. If the
276  // future is already assigned the callback is immediately
277  // invoked.
278  inline void register_callback(CallbackInterface* callback) {
280  if (assigned) callback->notify();
281  else const_cast<callbackT&>(callbacks).push(callback);
282  }
283 
284 
285  // Sets the value of the future (assignment)
286  template <typename U>
287  void set(const U& value) {
289  if(remote_ref) {
290  // Copy world and owner from remote_ref since sending remote_ref
291  // will invalidate it.
292  World& world = remote_ref.get_world();
293  const ProcessID owner = remote_ref.owner();
294  world.am.send(owner, FutureImpl<T>::set_handler,
295  new_am_arg(remote_ref, unwrap_move(value)));
296  set_assigned(value);
297  } else {
298  set_assigned((const_cast<T&>(t) = value));
299  }
300  }
301 
302  void set(const archive::BufferInputArchive& input_arch) {
304  MADNESS_ASSERT(! remote_ref);
305  input_arch & const_cast<T&>(t);
306  set_assigned(const_cast<T&>(t));
307  }
308 
309  // Gets/forces the value, waiting if necessary (error if not local)
310  T& get() {
311  MADNESS_ASSERT(! remote_ref); // Only for local futures
313  return *const_cast<T*>(&t);
314  }
315 
316  // Gets/forces the value, waiting if necessary (error if not local)
317  const T& get() const {
318  MADNESS_ASSERT(! remote_ref); // Only for local futures
320  return *const_cast<const T*>(&t);
321  }
322 
323  bool is_local() const {
324  return ! remote_ref;
325  }
326 
328  MADNESS_EXCEPTION("IS THIS WORKING? maybe now we have the mutex", 0);
329 // ScopedMutex<Spinlock> fred(this);
330 // MADNESS_ASSERT(!world); // was return false;
331 // MADNESS_ASSERT(!assigned || f->assigned);
332 // if (f->world) {
333 // world = f->world;
334 // remote_ref = f->remote_ref;
335 // f->world = 0;
336 // }
337 // while(f->callbacks.size()) callbacks.push(f->callbacks.pop());
338 // while(f->assignments.size()) assignments.push(f->assignments.pop());
339  return true;
340  }
341 
342  virtual ~FutureImpl() {
343  if (const_cast<callbackT&>(callbacks).size()) {
344  print("Future: uninvoked callbacks being destroyed?", assigned);
345  abort();
346  }
347  if (const_cast<assignmentT&>(assignments).size()) {
348  print("Future: uninvoked assignment being destroyed?", assigned);
349  abort();
350  }
351  }
352  }; // class FutureImpl
353 
354 
356 
368  template <typename T>
369  class Future {
370 
371  friend std::ostream& operator<< <T>(std::ostream& out, const Future<T>& f);
372 
373  private:
374 
375  // This future object can exist in one of three states:
376  // - f == NULL && value == NULL : Default initialized state
377  // This state occurs when the future is constructed via
379  // - f != NULL && value == NULL : FutureImpl object will hold the T object
380  // This state occurs when a future is constructed without a value,
381  // or from a remote reference.
382  // - f == NULL $$ value != NULL : T object is held in buffer
383  // This state occurs when a future is constructed with a value
384  // or from an input archive.
385 
387  char buffer[sizeof(T)];
388  T* const value;
389 
390  class dddd {};
391  explicit Future(const dddd&) : f(), value(NULL) { }
392 
393  public:
395 
397  Future() :
398  f(new FutureImpl<T>()), value(NULL)
399  { }
400 
402  explicit Future(const T& t) :
403  f(), value(new(static_cast<void*>(buffer)) T(t))
404  { }
405 
407  explicit Future(const remote_refT& remote_ref) :
408  f(remote_ref.is_local() ?
409  remote_ref.get_shared() :
410  std::shared_ptr<FutureImpl<T> >(new FutureImpl<T>(remote_ref))),
411  value(NULL)
412  { }
413 
415  explicit Future(const archive::BufferInputArchive& input_arch) :
416  f(), value(new(static_cast<void*>(buffer)) T())
417  {
418  input_arch & (*value);
419  }
420 
422  Future(const Future<T>& other) :
423  f(other.f),
424  value(other.value ?
425  new(static_cast<void*>(buffer)) T(* other.value) :
426  NULL)
427  {
428  if(other.is_default_initialized())
429  f.reset(new FutureImpl<T>()); // Other was default constructed so make a new f
430  }
431 
433  if(value)
434  value->~T();
435  }
436 
437 
439  static const Future<T> default_initializer() { return Future<T>(dddd()); }
440 
442 
445  bool is_default_initialized() const { return ! (f || value); }
446 
448  Future<T>& operator=(const Future<T>& other) {
449  if(this != &other) {
450  MADNESS_ASSERT(!probe());
451  if(f && other.value)
452  set(other);
453  else
454  f = other.f;
455  }
456  return *this;
457  }
458 
460 
473  void set(const Future<T>& other) {
474  MADNESS_ASSERT(f);
475  if(f != other.f) {
476  MADNESS_ASSERT(! f->probe());
477  if (other.probe()) {
478  set(other.get()); // The easy case
479  } else {
480  // Assignment is supposed to happen just once so
481  // safe to assume that this is not being messed
482  // with ... also other might invoke the assignment
483  // callback since it could have been assigned
484  // between the test above and now (and this does
485  // happen)
486  std::shared_ptr< FutureImpl<T> > ff = f; // manage lifetime of me
487  std::shared_ptr< FutureImpl<T> > of = other.f; // manage lifetime of other
488 
489  { // BEGIN CRITICAL SECTION
491  of->add_to_assignments(ff); // Recheck of assigned is performed in here
492  } // END CRITICAL SECTION
493  }
494  }
495  }
496 
498  inline void set(const T& value) {
499  MADNESS_ASSERT(f);
500  std::shared_ptr< FutureImpl<T> > ff = f; // manage life time of f
501  ff->set(value);
502  }
503 
505  inline void set(const archive::BufferInputArchive& input_arch) {
506  MADNESS_ASSERT(f);
507  std::shared_ptr< FutureImpl<T> > ff = f; // manage life time of f
508  ff->set(input_arch);
509  }
510 
511 
513  inline T& get() {
514  MADNESS_ASSERT(f || value); // Check that future is not default initialized
515  return (f ? f->get() : *value);
516  }
517 
519  inline const T& get() const {
520  MADNESS_ASSERT(f || value); // Check that future is not default initialized
521  return (f ? f->get() : *value);
522  }
523 
525 
527  inline bool probe() const { return (f ? f->probe() : bool(value)); }
528 
530  inline operator T&() { return get(); }
531 
533  inline operator const T&() const { return get(); }
534 
535 
537 
552  inline remote_refT remote_ref(World& world) const {
553  MADNESS_ASSERT(!probe());
554  if (f->remote_ref)
555  return f->remote_ref;
556  else
557  return RemoteReference< FutureImpl<T> >(world, f);
558  }
559 
560 
561  inline bool is_local() const { return (f && f->is_local()) || value; }
562 
563  inline bool is_remote() const { return !is_local(); }
564 
565 
567 
571  inline void register_callback(CallbackInterface* callback) {
572  if(probe()) {
573  callback->notify();
574  } else {
575  MADNESS_ASSERT(f);
576  f->register_callback(callback);
577  }
578  }
579  }; // class Future
580 
581 
583 
585  template <typename T> class Future< Future<T> > {
586  Future() {}
587  };
588 
589 
591 
593  template <> class FutureImpl<void> {};
594 
596 
598  template <> class Future<void> {
599  public:
601 
602  static const Future<void> value; // Instantiated in world.cc
603 
604  static remote_refT remote_ref(World&) { return remote_refT(); }
605 
606  Future() {}
607 
609 
610  Future(const archive::BufferInputArchive& input_arch) {
611  input_arch & *this;
612  }
613 
614  inline Future<void>& operator=(const Future<void>&) { return *this; }
615 
616  static void set(const Future<void>&) { }
617  static void set() { }
618 
619  static bool probe() { return true; }
620  }; // class Future<void>
621 
623 
625  template <> class FutureImpl<Void> {};
626 
628 
630  template <> class Future<Void> {
631  public:
633 
634  remote_refT remote_ref(World& /*world*/) const {
635  return remote_refT();
636  }
637 
638  Future() {}
639 
641 
642  inline void set(const Future<Void>& /*f*/) {}
643 
644  inline Future<Void>& operator=(const Future<Void>& /*f*/) {
645  return *this;
646  }
647 
648  inline void set(const Void& /*f*/) {}
649 
650  static bool probe() { return true; }
651  }; // class Future<Void>
652 
654 
660  template <typename T>
661  class Future< std::vector< Future<T> > > : public DependencyInterface, private NO_DEFAULTS {
662  private:
663  typedef typename std::vector< Future<T> > vectorT;
664  vectorT v;
665 
666  public:
667  Future() : v() { }
668 
669  Future(const vectorT& v) : DependencyInterface(v.size()), v(v) {
670  for (int i=0; i<(int)v.size(); ++i) {
671  this->v[i].register_callback(this);
672  }
673  }
674 
676  explicit Future(const archive::BufferInputArchive& input_arch) {
677  input_arch & v;
678  }
679 
680  vectorT& get() { return v; }
681  const vectorT& get() const { return v; }
682  operator vectorT& () { return get(); }
683  operator const vectorT& () const { return get(); }
684 
685  bool probe() const {
686  for(typename std::vector< Future<T> >::const_iterator it = v.begin(); it != v.end(); ++it)
687  if(! it->probe())
688  return false;
689  return true;
690  }
691  }; // class Future< std::vector< Future<T> > >
692 
693 
695 
697  template <typename T>
698  std::vector< Future<T> > future_vector_factory(std::size_t n) {
699  return std::vector< Future<T> >(n, Future<T>::default_initializer());
700  }
701 
702 
703  namespace archive {
705 
707  template <class Archive, typename T>
708  struct ArchiveStoreImpl< Archive, Future<T> > {
709  static inline void store(const Archive& ar, const Future<T>& f) {
710  MAD_ARCHIVE_DEBUG(std::cout << "serializing future" << std::endl);
711  MADNESS_ASSERT(f.probe());
712  ar & f.get();
713  }
714  };
715 
716 
718 
720  template <class Archive, typename T>
721  struct ArchiveLoadImpl< Archive, Future<T> > {
722  static inline void load(const Archive& ar, Future<T>& f) {
723  MAD_ARCHIVE_DEBUG(std::cout << "deserializing future" << std::endl);
724  MADNESS_ASSERT(!f.probe());
725  T value;
726  ar & value;
727  f.set(value);
728  }
729  };
730 
731 
733 
735  template <class Archive>
736  struct ArchiveStoreImpl< Archive, Future<void> > {
737  static inline void store(const Archive&, const Future<void>&) { }
738  };
739 
740 
742 
744  template <class Archive>
745  struct ArchiveLoadImpl< Archive, Future<void> > {
746  static inline void load(const Archive&, const Future<void>&) { }
747  };
748 
750 
752  template <class Archive>
753  struct ArchiveStoreImpl< Archive, Future<Void> > {
754  static inline void store(const Archive&, const Future<Void>&) { }
755  };
756 
757 
759 
761  template <class Archive>
762  struct ArchiveLoadImpl< Archive, Future<Void> > {
763  static inline void load(const Archive&, Future<Void>&) { }
764  };
765 
767  template <class Archive, typename T>
768  struct ArchiveStoreImpl< Archive, std::vector<Future<T> > > {
769  static inline void store(const Archive& ar, const std::vector<Future<T> >& v) {
770  MAD_ARCHIVE_DEBUG(std::cout << "serializing vector of futures" << std::endl);
771  ar & v.size();
772  for(typename std::vector<Future<T> >::const_iterator it = v.begin(); it != v.end(); ++it) {
773  MADNESS_ASSERT(it->probe());
774  ar & it->get();
775  }
776  }
777  };
778 
779 
781 
783  template <class Archive, typename T>
784  struct ArchiveLoadImpl< Archive, std::vector<Future<T> > > {
785  static inline void load(const Archive& ar, std::vector<Future<T> >& v) {
786  MAD_ARCHIVE_DEBUG(std::cout << "deserializing vector of futures" << std::endl);
787  std::size_t n = 0;
788  ar & n;
789  if(v.size() < n)
790  v.reserve(n);
791  if(v.size() > n)
792  v.resize(n);
793  for(typename std::vector<Future<T> >::iterator it = v.begin(); it < v.end(); ++it, --n) {
794  MADNESS_ASSERT(! it->probe());
795  it->set(ar);
796  }
797  for(; n != 0; --n)
798  v.push_back(Future<T>(ar));
799  }
800  };
801  }
802 
804 
806  template <typename T>
807  std::ostream& operator<<(std::ostream& out, const Future<T>& f) ;
808 
809  template <>
810  std::ostream& operator<<(std::ostream& out, const Future<void>& f) ;
811 
812  template <>
813  std::ostream& operator<<(std::ostream& out, const Future<Void>& f) ;
814 
815 #ifdef WORLD_INSTANTIATE_STATIC_TEMPLATES
816 
819  template <typename T>
820  std::ostream& operator<<(std::ostream& out, const Future<T>& f) {
821  if (f.probe()) out << f.get();
822  else if (f.is_remote()) out << f.f->remote_ref;
823  else if (f.f) out << "<unassigned refcnt=" << f.f.use_count() << ">";
824  else out << "<unassigned>";
825  return out;
826  }
827 
828 #endif
829 
830 }
831 
832 
833 #endif // MADNESS_WORLD_WORLDFUT_H__INCLUDED
Future< T > & operator=(const Future< T > &other)
Assignment future = future makes a shallow copy just like copy constructor.
Definition: worldfut.h:448
Mutex that is applied/released at start/end of a scope.
Definition: worldmutex.h:186
static void await(SafeMPI::Request &request, bool dowork=true)
Wait for MPI request to complete.
Definition: worldfwd.h:650
FutureImpl(const RemoteReference< FutureImpl< T > > &remote_ref)
Definition: worldfut.h:260
World & get_world() const
Owning world accessor.
Definition: worldref.h:586
Definition: shared_ptr_bits.h:38
Specialization of FutureImpl for internal convenience ... does nothing useful! ...
Definition: worldfut.h:593
World active message that extends an RMI message.
Definition: worldam.h:81
Boost-type-trait-like mapping of Future to T.
Definition: typestuff.h:73
double fred(const coordT &r)
Definition: tdse4.cc:369
T & get()
Definition: worldfut.h:310
static void load(const Archive &, Future< Void > &)
Definition: worldfut.h:763
static bool probe()
Definition: worldfut.h:619
void register_callback(CallbackInterface *callback)
Definition: worldfut.h:278
Future(const RemoteReference< FutureImpl< void > > &)
Definition: worldfut.h:608
static void store(const Archive &ar, const std::vector< Future< T > > &v)
Definition: worldfut.h:769
Future()
Definition: worldfut.h:606
Future(const archive::BufferInputArchive &input_arch)
Makes an assigned future from an input archive.
Definition: worldfut.h:415
~Future()
Definition: worldfut.h:432
T & unwrap_move(const detail::MoveWrapper< T > &t)
Remove move wrapper from a movable object.
Definition: move.h:119
Boost-type-trait-like testing of if a type is a future.
Definition: worldfut.h:117
static void load(const Archive &ar, Future< T > &f)
Definition: worldfut.h:722
bool replace_with(FutureImpl< T > *f)
Definition: worldfut.h:327
remote_refT remote_ref(World &) const
Definition: worldfut.h:634
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
bool probe() const
Query the whether this future has been assigned.
Definition: worldfut.h:527
detail::ReferenceWrapper< T > const ref(T &t)
Reference wrapper factory function.
Definition: ref.h:132
This class used for callbacks (e.g., for dependency tracking)
Definition: worlddep.h:51
Specialization of Future for internal convenience ... does nothing useful!
Definition: worldfut.h:598
Grossly simplified Boost-like type traits and templates.
Definition: mpreal.h:3066
Future(const archive::BufferInputArchive &input_arch)
Not implemented.
Definition: worldfut.h:676
static void set(const Future< void > &)
Definition: worldfut.h:616
static void store(const Archive &, const Future< Void > &)
Definition: worldfut.h:754
static void set()
Definition: worldfut.h:617
Specialization of Future for internal convenience ... does nothing useful!
Definition: worldfut.h:630
NDIM & f
Definition: mra.h:2179
bool is_remote() const
Definition: worldfut.h:563
bool_constant< true > true_type
Definition: gtest-port.h:1618
Default store of a thingy via serialize(ar,t)
Definition: archive.h:708
void register_callback(CallbackInterface *callback)
Registers an object to be called when future is assigned.
Definition: worldfut.h:571
void set(const Future< Void > &)
Definition: worldfut.h:642
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
bool_constant< false > false_type
Definition: gtest-port.h:1617
Future(const vectorT &v)
Definition: worldfut.h:669
WorldAmInterface & am
AM interface.
Definition: worldfwd.h:460
BindNullaryMemFun< T, resultT > bind_nullary_mem_fun(T *t, resultT(T::*op)())
Factory function for BindNullaryMemFun.
Definition: typestuff.h:143
Simple structure used to manage references/pointers to remote instances.
Definition: worldref.h:59
T * get() const
Definition: shared_ptr_bits.h:485
A simple, fixed-size, stack.
Definition: array.h:499
static bool probe()
Definition: worldfut.h:650
Future< void > & operator=(const Future< void > &)
Definition: worldfut.h:614
static void store(const Archive &ar, const Future< T > &f)
Definition: worldfut.h:709
Future(const remote_refT &remote_ref)
Makes a future wrapping a remote reference.
Definition: worldfut.h:407
RemoteReference< FutureImpl< T > > remote_refT
Definition: worldfut.h:394
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
Provides interface for tracking dependencies.
Definition: worlddep.h:60
bool is_local() const
Definition: worldfut.h:323
std::vector< Future< T > > future_vector_factory(std::size_t n)
Factory for vectors of futures (see section Gotchas on the mainpage)
Definition: worldfut.h:698
Future()
Makes an unassigned future.
Definition: worldfut.h:397
Default load of a thingy via serialize(ar,t)
Definition: archive.h:718
static void load(const Archive &, const Future< void > &)
Definition: worldfut.h:746
virtual ~FutureImpl()
Definition: worldfut.h:342
T type
Definition: worldfut.h:138
void set(const Void &)
Definition: worldfut.h:648
FutureImpl()
Definition: worldfut.h:250
Implements the functionality of Futures.
Definition: worldfut.h:157
ProcessID owner() const
Reference owner accessor.
Definition: worldref.h:580
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
bool is_local() const
Definition: worldfut.h:561
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
RemoteReference< FutureImpl< Void > > remote_refT
Definition: worldfut.h:632
bool probe() const
Definition: worldfut.h:270
#define MAD_ARCHIVE_DEBUG(s)
Definition: archive.h:438
bool is_default_initialized() const
Default initialized query.
Definition: worldfut.h:445
Specialization of FutureImpl for internal convenience ... does nothing useful! ...
Definition: worldfut.h:625
static const Future< T > default_initializer()
See Gotchas on the documentation mainpage about why this exists and how to use it.
Definition: worldfut.h:439
Implements NO_DEFAULTS.
bool probe() const
Definition: worldfut.h:685
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:37
Future(const RemoteReference< FutureImpl< Void > > &)
Definition: worldfut.h:640
Wraps an archive around a memory buffer for input.
Definition: bufar.h:206
void reset()
Definition: shared_ptr_bits.h:459
Future(const Future< T > &other)
Copy constructor is shallow.
Definition: worldfut.h:422
void set(const archive::BufferInputArchive &input_arch)
Definition: worldfut.h:302
remote_refT remote_ref(World &world) const
Returns a structure used to pass references to another process.
Definition: worldfut.h:552
static const Future< void > value
Definition: worldfut.h:602
static void load(const Archive &ar, std::vector< Future< T > > &v)
Definition: worldfut.h:785
Implements RemoteReference which is for internal use.
void set(const T &value)
Assigns the value ... it can only be set ONCE.
Definition: worldfut.h:498
A future is a possibly yet unevaluated value.
Definition: ref.h:210
A type you can return when you want to return void ... use "return None".
Definition: typestuff.h:154
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
static remote_refT remote_ref(World &)
Definition: worldfut.h:604
Future(const archive::BufferInputArchive &input_arch)
Definition: worldfut.h:610
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
RemoteReference< FutureImpl< void > > remote_refT
Definition: worldfut.h:600
Future< Void > & operator=(const Future< Void > &)
Definition: worldfut.h:644
Spinlock using pthread spinlock operations.
Definition: worldmutex.h:200
Implements World.
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
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Future()
Definition: worldfut.h:638
T type
Definition: worldfut.h:130
static void store(const Archive &, const Future< void > &)
Definition: worldfut.h:737
virtual void notify()=0
void register_callback(CallbackInterface *callback)
Registers a callback for when ndepend==0 , immediately invoked if ndepend==0.
Definition: worlddep.h:94
Defines DependencyInterface and CallbackInterface.
void set(const U &value)
Definition: worldfut.h:287
Disables default copy constructor and assignment operators.
Definition: nodefaults.h:49
Future(const T &t)
Makes an assigned future.
Definition: worldfut.h:402
void set(const archive::BufferInputArchive &input_arch)
Assigns the value ... it can only be set ONCE.
Definition: worldfut.h:505