MADNESS  0.10.1
worldref.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 
33 #ifndef MADNESS_WORLD_WORLDREF_H__INCLUDED
34 #define MADNESS_WORLD_WORLDREF_H__INCLUDED
35 
36 /// \file worldref.h
37 /// \brief Implements RemoteReference which is for internal use
38 
39 #include <madness/world/atomicint.h> // for AtomicInt
40 #include <madness/world/worldtypes.h> // for ProcessID
41 #include <madness/world/archive.h> // for wrap_opaque
42 #include <madness/world/worldam.h> // for new_am_arg
43 #include <madness/world/worldptr.h> // for WorldPtr
44 #include <madness/world/worldhashmap.h> // for ConcurrentHashMap
45 #include <iosfwd> // for std::ostream
46 
47 //#define MADNESS_REMOTE_REFERENCE_DEBUG
48 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
49 #include <madness/world/print.h> // for print
50 #endif
51 
52 namespace madness {
53 
54  class World;
55  template <typename T> class RemoteReference;
56 //
57 // template <typename T>
58 // std::ostream& operator<<(std::ostream& s, const RemoteReference<T>& ref);
59 
60  namespace detail {
61 
62 
63  template <typename T> class RemoteCounterImpl;
64 
65  /// Base class for remote counter implementation objects
66 
67  /// This class only holds an atomic counter. The use counter tracks
68  /// local copies of the counter an references that have been copied as
69  /// part of the communication process. This class also provides a
70  /// mechanism for hiding the pointer type.
71  /// \note The actual counter manipulation is handled by RemoteCounter.
72  /// This class only provides the counter interface.
73  /// \note This class is considered an implementation detail and may
74  /// change at any time. You should not use this class directly.
76  private:
77  madness::AtomicInt count_; ///< reference count
78 
79  // Copy not allowed
82 
83  public:
84 
86  virtual ~RemoteCounterBase() { }
87 
88  /// Counter key accessor
89 
90  /// The key is the pointer for which the remote counter is counting
91  /// references.
92  /// \return The pointer that is being counted.
93  virtual void* key() const = 0;
94 
95  /// Remote and local counter accessor
96 
97  /// The use counter tracks local copies of the counter an references
98  /// that have been copied as part othe communication process
99  long use_count() const { return count_; }
100 
101  /// Shared pointer accessor
102 
103  /// \tparam T The stored pointer type
104  /// \return A const reference to the stored shared pointer
105  template <typename T>
106  const std::shared_ptr<T>& get_shared() const {
107  return static_cast<const RemoteCounterImpl<T>*>(this)->get_shared();
108  }
109 
110  /// Increment the reference count
111 
112  /// The reference count should be incremented when a local copy of
113  /// the counter is created or the when the counter is serialized as
114  /// part of communication.
115  /// \throw nothing
116  void add_ref() {
117 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
118  long c = count_++;
119  print(">>> RemoteCounterBase(", this->key(), ") +ref count=", c + 1);
120 #else
121  count_++;
122 #endif
123  }
124 
125  /// Decrement the reference count
126 
127  /// \return true if the reference count has dropped to zero
128  /// \throw nothing
129  bool release() {
130 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
131  long c = count_;
132  print(">>> RemoteCounterBase(", this->key(), ") -ref count=", c - 1);
133 #endif
134  return count_.dec_and_test();
135  }
136  }; // class RemoteCounterBase
137 
138  /// Remote counter implementation object.
139 
140  /// This class stores a shared pointer in memory to ensure that the
141  /// referenced object is valid as long as there are outstanding remote
142  /// references.
143  /// \tparam T The type of the referenced shared_ptr object.
144  /// \note This class is considered an implementation detail and may
145  /// change at any time. You should not use this class directly.
146  template <typename T>
148  private:
149  // At some point this should probably be changed to a quick allocator
150  // When that happens, also uncomment the new and delete operators
151 // typedef std::allocator<RemoteCounterImpl<T> > A;
152 
153  // Keep a copy of the shared pointer to make sure it stays in memory
154  // while we have outstanding remote references to it.
155  std::shared_ptr<T> pointer_; ///< pointer that is remotely referenced
156 
157  public:
158  explicit RemoteCounterImpl(const std::shared_ptr<T>& p) :
160  { }
161 
162  virtual ~RemoteCounterImpl() { }
163 
164  /// Shared pointer accessor
165 
166  /// \return A const reference to the stored shared pointer
167  const std::shared_ptr<T>& get_shared() const { return pointer_; }
168 
169  /// Counter key accessor
170 
171  /// The key is the pointer for which the remote counter is counting
172  /// references.
173  /// \return The pointer that is being counted.
174  virtual void* key() const { return static_cast<void*>(pointer_.get()); }
175 
176 // void* operator new(std::size_t) {
177 // return A().allocate(1);
178 // }
179 //
180 // void operator delete(void * p) {
181 // A().deallocate(static_cast<RemoteCounterImpl<T> *>(p), 1);
182 // }
183  }; // class RemoteCounterImpl
184 
185  /// Remote reference counter
186 
187  /// Automatically counts local and remote references to an object. The
188  /// reference count is incremented when the object is copied locally or
189  /// serialized as part of communication.
191  private:
194 
195  static pimpl_mapT pimpl_map_; ///< A map of currently registered
196  ///< implementation objects. The key is
197  ///< it's referenced pointer.
198 
199  /// Pointer to the shared counter implementation object
201 
202  /// Clean-up the implementation object
203 
204  /// Here we check that the pimpl has been initialized, and if so, we
205  /// release the current reference. If the count drops to zero, then
206  /// this is the last reference to the pimpl and it should be deleted.
207  void destroy() {
208  if(pimpl_.is_local()) {
209  if(pimpl_->release()) {
210  // No one else is referencing this pointer.
211  // We can safely dispose of it.
212 
213 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
214  print(">>> RemoteCounter::unregister_ptr_: key=", pimpl_->key(), ", value=", pimpl_);
215 #endif
216  unregister_ptr_(pimpl_->key());
217  delete pimpl_.get();
218  }
219  }
220 
222  }
223 
224  /// Register a local shared pointer
225 
226  /// This function will first search the local pointer register for
227  /// the shared pointer \c p. If found the pimpl for that pointer
228  /// will be returned. Otherwise a new pimpl will be created and
229  /// returned.
230  /// \tparam T The shared pointer type to register
231  /// \param w The world where the pointer lives
232  /// \param p The shared pointer to register
233  /// \return A world pointer to the pimpl
234  /// \throw std::bad_alloc If pimpl allocation fails.
235  /// \throw madness::MadnessException If pointer cannot be inserted
236  /// into the pointer registration map.
237  template <typename T>
238  static WorldPtr<implT> register_ptr_(World& w, const std::shared_ptr<T>& p) {
239  // Check for a null pointer
240  if(p.get() == nullptr)
241  return WorldPtr<implT>(w, nullptr);
242 
244  // Pointer is local and non-null
245  if(pimpl_map_.insert(acc,static_cast<void*>(p.get()))) {
246  // The pointer is not registered so we need to make a
247  // new pimpl.
248  implT* pimpl = new RemoteCounterImpl<T>(p);
249 
250  try{
251  acc->second = WorldPtr<implT>(w, pimpl);
252  } catch(...) {
253  delete pimpl;
254  throw;
255  }
256 
257 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
258  print(">>> RemoteCounter::register_ptr_(new): key=", p.get(), ", pimpl=", acc->second);
259 #endif
260  } else {
261  // The pointer is already registered, so we just need
262  // increment the counter.
263 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
264  print(">>> RemoteCounter::register_ptr_(existing): key=", acc->second->key(), ", pimpl=", acc->second);
265 #endif
266  acc->second->add_ref();
267  }
268 
269  return acc->second;
270  }
271 
272  /// Unregister a local shared pointer reference
273 
274  /// \param key The key of the \c RemoteReference object to be unregistered.
275  /// \throw MadnessException If \c key is not found in the pointer map.
276  static void unregister_ptr_(void* key) {
277  auto erased = pimpl_map_.try_erase(key);
278  if (!erased) MADNESS_EXCEPTION("worldref: unregister_ptr failed", erased);
279  }
280 
282  pimpl_(p)
283  { }
284 
285  public:
286 
288 
289  RemoteCounter(const RemoteCounter& other) :
290  pimpl_(other.pimpl_)
291  {
292  if(pimpl_ && pimpl_.is_local())
293  pimpl_->add_ref();
294  }
295 
296  template <typename T>
297  explicit RemoteCounter(World& w, const std::shared_ptr<T>& p) :
299  { }
300 
302 
304  WorldPtr<implT> temp = other.pimpl_;
305 
306  if(pimpl_ != temp) {
307  if(temp)
308  temp->add_ref();
309  destroy();
310  pimpl_ = temp;
311  }
312 
313  return *this;
314  }
315 
316  /// Counter accessor
317 
318  /// \return The number of local and remote references
319  /// \throw none
320  long use_count() const { return (pimpl_.is_local() ? pimpl_->use_count() : 0); }
321  bool unique() const { return use_count() == 1; }
322  bool empty() const { return ! pimpl_; }
323 
324  bool is_local() const { return pimpl_.is_local(); }
325  bool has_owner() const { return pimpl_.has_owner(); }
326  ProcessID owner() const { return pimpl_.owner(); }
327 
328  template <typename T>
329  const std::shared_ptr<T>& get_shared() const { return pimpl_->get_shared<T>(); }
330 
332  get_worldid() const { return pimpl_.get_worldid(); }
333  World& get_world() const { return pimpl_.get_world(); }
334  void swap(RemoteCounter& other) {
336  }
337 
338  private:
339 
340  template <typename, typename, typename>
342 
343  template <typename, typename, typename>
345 
346  template <typename Archive>
347  void load_(const Archive& ar) {
349  ar & p;
350  RemoteCounter(p).swap(*this);
351 
352 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
353  print(">>> RemoteCounter::load: pimpl=", pimpl_);
354 #endif
355  }
356 
357  template <typename Archive>
358  void store_(const Archive& ar) const {
359  ar & pimpl_;
360 
361  if(! ar.count_only()) {
362 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG
363  print(">>> RemoteCounter::store: pimpl=", pimpl_);
364 #endif
365  if(pimpl_.is_local())
366  pimpl_->add_ref();
367  else
369  }
370  }
371 
372 
373  }; // class RemoteCounter
374 
375  inline void swap(RemoteCounter& l, RemoteCounter& r) { l.swap(r); }
376 
377  std::ostream& operator<<(std::ostream& out, const RemoteCounter& counter);
378 
379  } // namespace detail
380 
381 
382  /// Simple structure used to manage references/pointers to remote instances
383 
384  /// This class was intended only for internal use and is still rather
385  /// poorly thought through, however, it seems to fill a wider need.
386  /// \note Do not serialize via wrap_opaque().
387  /// \note Ownership of a reference is transferred when serialized on a remote
388  /// node. You should not attempt to send a remote reference to more than one
389  /// node except from the owning node. If you do serialize more than once,
390  /// this will cause an invalid memory access on the owning node.
391  /// \note !!! It is YOUR RESPONSIBILITY to release the reference count. This
392  /// can be done by sending the remote reference back to the owner or by
393  /// calling reset(). If this is not done, you will have a memory leak.
394  template <typename T>
396  public:
398  typedef T* pointerT;
399 
400  private:
401  mutable pointerT pointer_; ///< World pointer
402  detail::RemoteCounter counter_; ///< Remote reference counter
403 
404  // This is for RemoteReferences of other types, so they can still access
405  // private members.
406  template <typename>
407  friend class RemoteReference;
408 
409  // Handles reset of a remote reference from another node.
410  static void reset_handler(const AmArg& arg) {
412  arg & r;
413  // r resets on scope exit.
414  }
415 
416  public:
417 
418  /// Makes a non-shared (no reference count) null pointer
420  pointer_(), counter_() {};
421 
422  /// Construct a remote reference to p.
423 
424  /// \param w The world that \c p belongs to.
425  /// \param p The \c shared_ptr that is to be referenced.
426  /// \note \c p must be locally addressable pointer
427  RemoteReference(World& w, const std::shared_ptr<T>& p) :
428  pointer_(p.get()), counter_(w, p)
429  { }
430 
431  /// Copy constructor
432 
433  /// \param other The reference to be copied
435  pointer_(other.pointer_), counter_(other.counter_)
436  { }
437 
438  /// Copy conversion constructor
439 
440  /// \tparam U The remote reference type to be copied
441  /// \param other The reference to be copied
442  /// \note \c U* must be implicitly convertible to \c T*
443  template <typename U>
445  pointer_(other.pointer_), counter_(other.counter_)
446  { }
447 
449 
450  /// Copy conversion assignment operator
451 
452  /// \param other The reference to be copied
454  RemoteReference<T>(other).swap(*this);
455  return *this;
456  }
457 
458  /// Copy conversion assignment operator
459 
460  /// \tparam U The remote reference type to be copied
461  /// \param other The reference to be copied
462  /// \note \c U* must be implicitly convertible to \c T*
463  template <typename U>
465  RemoteReference<T>(other).swap(*this);
466  return *this;
467  }
468 
469 
470  /// Release this reference
471 
472  /// This function will clear the reference and leave it in the default
473  /// constructed state. If the reference is non-local, then a message is
474  /// sent to the reference owner that releases the reference.
475  /// \warning Only call this function for non-local references when it
476  /// will not otherwise be returned to the reference owner as part of a
477  /// message.
478  void reset() {
479  if((! (counter_.is_local())) && counter_.has_owner())
481  else
482  RemoteReference<T>().swap(*this);
483  }
484 
485  /// Boolean conversion operator
486 
487  /// \return true when the reference is initialized to a non zero value
488  /// or uninitialized, otherwise false
489  operator bool() const {
490  return ! counter_.empty();
491  }
492 
493  /// Reference pointer accessor
494 
495  /// \return The referenced pointer
496  /// \throw MadnessException If the pointer is not local
497  pointerT get() const {
499  return pointer_;
500  }
501 
502  /// Reference shared_ptr accessor
503 
504  /// \return A const reference to the references shared pointer
505  /// \throw MadnessException If the pointer is not local
506  const std::shared_ptr<T>& get_shared() const {
508  return counter_.get_shared<T>();
509  }
510 
511  /// Reference object accessor
512 
513  /// \return A reference to the referenced object
514  /// \throw MadnessException If the pointer is uninitialized
515  /// \throw MadnessException If the pointer is not local
517  MADNESS_ASSERT(pointer_ != nullptr);
519  return *pointer_;
520  }
521 
522  /// Reference object pointer accessor
523 
524  /// \return A pointer to the referenced object
525  /// \throw MadnessException If the pointer is uninitialized
526  /// \throw MadnessException If the pointer is not local
528  MADNESS_ASSERT(pointer_ != nullptr);
530  return pointer_;
531  }
532 
533  /// Reference count accessor
534 
535  /// \return The total number of local and remote references.
536  /// \throw nothing
537  long use_count() const { return counter_.use_count(); }
538 
539  /// Get uniqueness
540 
541  /// \return True when the use count is equal to exactly 1.
542  /// \throw nothing
543  bool unique() const { return counter_.unique(); }
544 
545  /// Swap references
546 
547  /// Exchange the value of this \c RemoteReference with \c other
548  /// \c RemoteReference
549  /// \tparam U The type of the other remote reference.
550  /// \note U* must be implicitly convertible to T*.
551  template <typename U>
552  void swap(RemoteReference<U>& other) {
553  std::swap(pointer_, other.pointer_);
555  }
556 
557  /// Locally owned reference
558 
559  /// \return true if owner is equal to the current rank of the owning
560  /// world, otherwise false
561  /// \throw nothing
562  inline bool is_local() const { return counter_.is_local(); }
563 
564  /// Reference owner accessor
565 
566  /// \return rank of owning process, or -1 if not initialized
567  /// \throw nothing
568  inline ProcessID owner() const { return counter_.owner(); }
569 
570  /// Owning world accessor
571 
572  /// \return A reference to the world that owns the pointer
573  /// \throw MadnessException If the reference is uninitialized
574  World& get_world() const { return counter_.get_world(); }
575 
576  /// Serialize the remote reference
577 
578  /// \tparam Archive The serialization archive type
579  /// \param ar The serialization archive object.
580  template <typename Archive>
581  void serialize(const Archive& ar) const {
582  // All of the interesting stuff happens in the counter serialization.
584  }
585 
586  public:
587 
588  /// Add the remote reference to the given \c std::ostream, \c out.
589 
590  /// \param out The output stream to add \c ref to.
591  /// \param ref The remote reference to add to the out stream
592  friend std::ostream& operator<<(std::ostream& out, const RemoteReference<T>& ref) {
593  out << "RemoteReference( pointer=" << ref.pointer_ << " counter=" << ref.counter_ << ")";
594  return out;
595  }
596  }; // class RemoteReference
597 
598 
599  /// Swap the two remote references
600 
601  /// \param l The left reference to be swapped with \c r
602  /// \param r The right reference to be swapped with \c l
603  /// \note T* must be implicitly convertible to U* and vis versa.
604  template <typename T, typename U>
606  l.swap(r);
607  }
608 
609  namespace archive {
610 
611  // This function is not allowed. Therefore it is not implemented so that
612  // a compiler error is generated it it is called. This still does not
613  // prevent remote references from being wrapped as part of another object.
614  template <typename T>
616 
617  // Remote counter serialization
618 
619  template <typename Archive>
620  struct ArchiveLoadImpl<Archive, detail::RemoteCounter > {
621  static inline void load(const Archive& ar, detail::RemoteCounter& c) {
622  c.load_(ar);
623  }
624  };
625 
626  template <typename Archive>
627  struct ArchiveStoreImpl<Archive, detail::RemoteCounter > {
628  static inline void store(const Archive& ar, const detail::RemoteCounter& c) {
629  c.store_(ar);
630  }
631  };
632 
633  } // namespace archive
634 } // namespace madness
635 
636 #endif // MADNESS_WORLD_WORLDREF_H__INCLUDED
double w(double t, double eps)
Definition: DKops.h:22
Interface templates for the archives (serialization).
Implements AtomicInt.
World active message that extends an RMI message.
Definition: worldam.h:80
An integer with atomic set, get, read+increment, read+decrement, and decrement+test operations.
Definition: atomicint.h:126
bool dec_and_test()
Decrements the counter and returns true if the new value is zero,.
Definition: atomicint.h:297
Definition: worldhashmap.h:396
std::pair< iterator, bool > insert(const datumT &datum)
Definition: worldhashmap.h:468
bool try_erase(const keyT &key)
Definition: worldhashmap.h:502
Definition: worldhashmap.h:330
Simple structure used to manage references/pointers to remote instances.
Definition: worldref.h:395
RemoteReference< T > & operator=(const RemoteReference< T > &other)
Copy conversion assignment operator.
Definition: worldref.h:453
pointerT operator->() const
Reference object pointer accessor.
Definition: worldref.h:527
T * pointerT
Definition: worldref.h:398
RemoteReference< T > & operator=(const RemoteReference< U > &other)
Copy conversion assignment operator.
Definition: worldref.h:464
bool unique() const
Get uniqueness.
Definition: worldref.h:543
static void reset_handler(const AmArg &arg)
Definition: worldref.h:410
World & get_world() const
Owning world accessor.
Definition: worldref.h:574
pointerT pointer_
World pointer.
Definition: worldref.h:401
void reset()
Release this reference.
Definition: worldref.h:478
long use_count() const
Reference count accessor.
Definition: worldref.h:537
void swap(RemoteReference< U > &other)
Swap references.
Definition: worldref.h:552
void serialize(const Archive &ar) const
Serialize the remote reference.
Definition: worldref.h:581
RemoteReference(const RemoteReference< U > &other)
Copy conversion constructor.
Definition: worldref.h:444
RemoteReference(const RemoteReference< T > &other)
Copy constructor.
Definition: worldref.h:434
bool is_local() const
Locally owned reference.
Definition: worldref.h:562
ProcessID owner() const
Reference owner accessor.
Definition: worldref.h:568
pointerT get() const
Reference pointer accessor.
Definition: worldref.h:497
referenceT operator*() const
Reference object accessor.
Definition: worldref.h:516
detail::RemoteCounter counter_
Remote reference counter.
Definition: worldref.h:402
~RemoteReference()
Definition: worldref.h:448
const std::shared_ptr< T > & get_shared() const
Reference shared_ptr accessor.
Definition: worldref.h:506
RemoteReference()
Makes a non-shared (no reference count) null pointer.
Definition: worldref.h:419
RemoteReference(World &w, const std::shared_ptr< T > &p)
Construct a remote reference to p.
Definition: worldref.h:427
detail::ptr_traits< T >::reference referenceT
Definition: worldref.h:397
friend std::ostream & operator<<(std::ostream &out, const RemoteReference< T > &ref)
Add the remote reference to the given std::ostream, out.
Definition: worldref.h:592
void send(ProcessID dest, am_handlerT op, const AmArg *arg, const int attr=RMI::ATTR_ORDERED)
Sends a managed non-blocking active message.
Definition: worldam.h:278
A parallel world class.
Definition: world.h:132
WorldAmInterface & am
AM interface.
Definition: world.h:203
Wrapper for dynamic arrays and pointers.
Definition: archive.h:890
Base class for remote counter implementation objects.
Definition: worldref.h:75
madness::AtomicInt count_
reference count
Definition: worldref.h:77
RemoteCounterBase & operator=(const RemoteCounterBase &)
bool release()
Decrement the reference count.
Definition: worldref.h:129
virtual void * key() const =0
Counter key accessor.
const std::shared_ptr< T > & get_shared() const
Shared pointer accessor.
Definition: worldref.h:106
void add_ref()
Increment the reference count.
Definition: worldref.h:116
RemoteCounterBase()
Definition: worldref.h:85
long use_count() const
Remote and local counter accessor.
Definition: worldref.h:99
RemoteCounterBase(const RemoteCounterBase &)
virtual ~RemoteCounterBase()
Definition: worldref.h:86
Remote counter implementation object.
Definition: worldref.h:147
virtual void * key() const
Counter key accessor.
Definition: worldref.h:174
virtual ~RemoteCounterImpl()
Definition: worldref.h:162
RemoteCounterImpl(const std::shared_ptr< T > &p)
Definition: worldref.h:158
std::shared_ptr< T > pointer_
pointer that is remotely referenced
Definition: worldref.h:155
const std::shared_ptr< T > & get_shared() const
Shared pointer accessor.
Definition: worldref.h:167
Remote reference counter.
Definition: worldref.h:190
void load_(const Archive &ar)
Definition: worldref.h:347
RemoteCounter & operator=(const RemoteCounter &other)
Definition: worldref.h:303
World & get_world() const
Definition: worldref.h:333
void swap(RemoteCounter &other)
Definition: worldref.h:334
RemoteCounter(const RemoteCounter &other)
Definition: worldref.h:289
static pimpl_mapT pimpl_map_
Definition: worldref.h:195
static void unregister_ptr_(void *key)
Unregister a local shared pointer reference.
Definition: worldref.h:276
RemoteCounter()
Definition: worldref.h:287
ProcessID owner() const
Definition: worldref.h:326
void store_(const Archive &ar) const
Definition: worldref.h:358
bool has_owner() const
Definition: worldref.h:325
RemoteCounter(const WorldPtr< implT > &p)
Definition: worldref.h:281
ConcurrentHashMap< void *, WorldPtr< implT > > pimpl_mapT
Definition: worldref.h:193
void destroy()
Clean-up the implementation object.
Definition: worldref.h:207
WorldPtr< implT > pimpl_
Pointer to the shared counter implementation object.
Definition: worldref.h:200
RemoteCounterBase implT
Definition: worldref.h:192
RemoteCounter(World &w, const std::shared_ptr< T > &p)
Definition: worldref.h:297
long use_count() const
Counter accessor.
Definition: worldref.h:320
static WorldPtr< implT > register_ptr_(World &w, const std::shared_ptr< T > &p)
Register a local shared pointer.
Definition: worldref.h:238
WorldPtr< implT >::worldidT get_worldid() const
Definition: worldref.h:332
bool empty() const
Definition: worldref.h:322
const std::shared_ptr< T > & get_shared() const
Definition: worldref.h:329
bool is_local() const
Definition: worldref.h:324
bool unique() const
Definition: worldref.h:321
~RemoteCounter()
Definition: worldref.h:301
A global pointer address, valid anywhere in the world.
Definition: worldptr.h:78
unsigned long worldidT
World ID type.
Definition: worldptr.h:80
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition: derivatives.cc:72
auto T(World &world, response_space &f) -> response_space
Definition: global_functions.cc:34
archive_array< unsigned char > wrap_opaque(const T *, unsigned int)
Factory function to wrap a pointer to contiguous data as an opaque (uchar) archive_array.
Definition: archive.h:925
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:2502
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition: madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition: madness_exception.h:134
void swap(WorldPtr< T > &l, WorldPtr< T > &r)
Swap the content of l with r.
Definition: worldptr.h:407
std::ostream & operator<<(std::ostream &out, const RemoteCounter &counter)
Definition: worldref.cc:42
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
AmArg * new_am_arg(const argT &... args)
Convenience template for serializing arguments into a new AmArg.
Definition: worldam.h:194
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition: print.h:225
void swap(RemoteReference< T > &l, RemoteReference< U > &r)
Swap the two remote references.
Definition: worldref.h:605
void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition: vector.h:497
Defines simple templates for printing to std::cout "a la Python".
static const double c
Definition: relops.cc:10
static void load(const Archive &ar, detail::RemoteCounter &c)
Definition: worldref.h:621
Default load of an object via serialize(ar, t).
Definition: archive.h:666
static void store(const Archive &ar, const detail::RemoteCounter &c)
Definition: worldref.h:628
Default store of an object via serialize(ar, t).
Definition: archive.h:611
U & reference
Definition: worldptr.h:62
Implements active message layer for World on top of RMI layer.
Defines and implements a concurrent hashmap.
The madness::detail::WorldPtr class for global pointers.
Defines types used by the parallel runtime.
int ProcessID
Used to clearly identify process number/rank.
Definition: worldtypes.h:43