36 #ifndef MADNESS_WORLD_WORLDREF_H__INCLUDED 
   37 #define MADNESS_WORLD_WORLDREF_H__INCLUDED 
   52 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
   65         template <
typename, 
typename>
 
   66         struct ArchiveLoadImpl;
 
   68         template <
typename, 
typename>
 
   69         struct ArchiveStoreImpl;
 
  105             virtual void* 
key() 
const = 0;
 
  117             template <
typename T>
 
  129 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  131                 print(
">>> RemoteCounterBase(", this->
key(), 
") +ref count=", c + 1);
 
  142 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  144                 print(
">>> RemoteCounterBase(", this->
key(), 
") -ref count=", c - 1);
 
  158         template <
typename T>
 
  159         class RemoteCounterImpl : 
public RemoteCounterBase {
 
  186             virtual void* 
key()
 const { 
return static_cast<void*
>(pointer_.
get()); }
 
  207             static pimpl_mapT pimpl_map_;   
 
  221                     if(pimpl_->release()) {
 
  225 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  226                         print(
">>> RemoteCounter::unregister_ptr_: key=", pimpl_->key(), 
", value=", pimpl_);
 
  228                         unregister_ptr_(pimpl_->key());
 
  249             template <
typename T>
 
  257                 if(pimpl_map_.
insert(acc,static_cast<void*>(p.
get()))) {
 
  269 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  270                         print(
">>> RemoteCounter::register_ptr_(new): key=", p.
get(), 
", pimpl=", acc->second);
 
  275 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  276                     print(
">>> RemoteCounter::register_ptr_(existing): key=", acc->second->key(), 
", pimpl=", acc->second);
 
  278                     acc->second->add_ref();
 
  288             static void unregister_ptr_(
void* key) {
 
  289                 std::size_t ereased = pimpl_map_.
erase(key);
 
  290                 MADNESS_ASSERT(ereased > 0);
 
  308             template <
typename T>
 
  310                 pimpl_(register_ptr_(w, p))
 
  334             bool empty()
 const { 
return ! pimpl_; }
 
  340             template <
typename T>
 
  352             template <
typename, 
typename>
 
  355             template <
typename, 
typename>
 
  358             template <
typename Archive>
 
  359             void load_(
const Archive& ar) {
 
  364 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  365                 print(
">>> RemoteCounter::load: pimpl=", pimpl_);
 
  369             template <
typename Archive>
 
  370             void store_(
const Archive& ar)
 const {
 
  373                 if(! ar.count_only()) {
 
  374 #ifdef MADNESS_REMOTE_REFERENCE_DEBUG 
  375                     print(
">>> RemoteCounter::store: pimpl=", pimpl_);
 
  377                     if(pimpl_.is_local())
 
  389         std::ostream& 
operator<<(std::ostream& out, 
const RemoteCounter& counter);
 
  406     template <
typename T>
 
  407     class RemoteReference {
 
  413         mutable pointerT pointer_;      
 
  422         static void reset_handler(
const AmArg& 
arg) {
 
  432             pointer_(), counter_() {};
 
  440             pointer_(p.
get()), counter_(w, p)
 
  447             pointer_(other.pointer_), counter_(other.counter_)
 
  455         template <
typename U>
 
  457             pointer_(other.pointer_), counter_(other.counter_)
 
  475         template <
typename U>
 
  501         operator bool()
 const {
 
  502             return ! counter_.
empty();
 
  509         pointerT 
get() 
const {
 
  510             MADNESS_ASSERT(counter_.
is_local());
 
  519             MADNESS_ASSERT(counter_.
is_local());
 
  529             MADNESS_ASSERT(pointer_ != NULL);
 
  530             MADNESS_ASSERT(counter_.
is_local());
 
  540             MADNESS_ASSERT(pointer_ != NULL);
 
  541             MADNESS_ASSERT(counter_.
is_local());
 
  563         template <
typename U>
 
  592         template <
typename Archive>
 
  604         friend std::ostream& operator<<(std::ostream& out, const RemoteReference<T>& 
ref) {
 
  605             out << 
"RemoteReference( pointer=" << 
ref.pointer_ << 
" counter=" << 
ref.counter_ << 
")";
 
  616     template <
typename T, 
typename U>
 
  626         template <
typename T>
 
  627         archive_array<unsigned char> 
wrap_opaque(
const RemoteReference<T>& t);
 
  631         template <
typename Archive>
 
  638         template <
typename Archive>
 
  648 #endif // MADNESS_WORLD_WORLDREF_H__INCLUDED 
Remote reference counter. 
Definition: worldref.h:202
long use_count() const 
Counter accessor. 
Definition: worldref.h:332
World & get_world() const 
Owning world accessor. 
Definition: worldref.h:586
Definition: shared_ptr_bits.h:38
World active message that extends an RMI message. 
Definition: worldam.h:81
Remote counter implementation object. 
Definition: worldref.h:75
pointerT get() const 
Reference pointer accessor. 
Definition: worldref.h:509
Definition: worldhashmap.h:332
bool empty() const 
Definition: worldref.h:334
ProcessID owner() const 
Definition: worldref.h:338
std::ostream & operator<<(std::ostream &out, const RemoteCounter &counter)
Definition: worldref.cc:42
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
detail::ReferenceWrapper< T > const ref(T &t)
Reference wrapper factory function. 
Definition: ref.h:132
long use_count() const 
Remote and local counter accessor. 
Definition: worldref.h:111
~RemoteReference()
Definition: worldref.h:460
Base class for remote counter implementation objects. 
Definition: worldref.h:87
T * pointerT
Definition: worldref.h:410
const std::shared_ptr< T > & get_shared() const 
Shared pointer accessor. 
Definition: worldref.h:179
Interface templates for the archives (serialization) 
void swap(WorldPtr< T > &l, WorldPtr< T > &r)
Swap the content of l with r. 
Definition: worldptr.h:356
void reset()
Release this reference. 
Definition: worldref.h:490
virtual void * key() const =0
Counter key accessor. 
WorldPtr< implT >::worldidT get_worldid() const 
Definition: worldref.h:344
bool dec_and_test()
Decrements the counter and returns true if the new value is zero. 
Definition: atomicint.h:178
RemoteReference(const RemoteReference< U > &other)
Copy conversion constructor. 
Definition: worldref.h:456
RemoteReference(World &w, const std::shared_ptr< T > &p)
Construct a remote reference to p. 
Definition: worldref.h:439
Default store of a thingy via serialize(ar,t) 
Definition: archive.h:708
World & get_world() const 
Definition: worldref.h:345
Definition: worldhashmap.h:57
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
U & reference
Definition: worldptr.h:51
WorldAmInterface & am
AM interface. 
Definition: worldfwd.h:460
referenceT operator*() const 
Reference object accessor. 
Definition: worldref.h:528
RemoteCounter(World &w, const std::shared_ptr< T > &p)
Definition: worldref.h:309
unsigned long worldidT
World ID type. 
Definition: worldptr.h:67
pointerT operator->() const 
Reference object pointer accessor. 
Definition: worldref.h:539
bool has_owner() const 
Definition: worldref.h:337
virtual void * key() const 
Counter key accessor. 
Definition: worldref.h:186
const std::shared_ptr< T > & get_shared() const 
Shared pointer accessor. 
Definition: worldref.h:118
Simple structure used to manage references/pointers to remote instances. 
Definition: worldref.h:59
ProcessID owner() const 
Rank accessor. 
Definition: worldptr.h:301
T * get() const 
Definition: shared_ptr_bits.h:485
void swap(RemoteReference< U > &other)
Swap references. 
Definition: worldref.h:564
worldidT get_worldid() const 
World ID accessor. 
Definition: worldptr.h:294
std::size_t erase(const keyT &key)
Definition: worldhashmap.h:503
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
void add_ref()
Increment the reference count. 
Definition: worldref.h:128
World & get_world() const 
World accessor. 
Definition: worldptr.h:285
RemoteReference()
Makes a non-shared (no reference count) null pointer. 
Definition: worldref.h:431
void swap(RemoteCounter &other)
Definition: worldref.h:346
Implements active message layer for World on top of RMI layer. 
std::pair< iterator, bool > insert(const datumT &datum)
Definition: worldhashmap.h:469
Default load of a thingy via serialize(ar,t) 
Definition: archive.h:718
bool is_local() const 
Locally owned reference. 
Definition: worldref.h:574
ProcessID owner() const 
Reference owner accessor. 
Definition: worldref.h:580
bool is_local() const 
Definition: worldref.h:336
An integer with atomic set, get, read+inc, read+dec, dec+test operations. 
Definition: atomicint.h:73
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
A parallel world with full functionality wrapping an MPI communicator. 
Definition: worldfwd.h:416
static void store(const Archive &ar, const detail::RemoteCounter &c)
Definition: worldref.h:640
bool unique() const 
Definition: worldref.h:333
pointer get() const 
Pointer accessor. 
Definition: worldptr.h:195
bool unique() const 
Get uniqueness. 
Definition: worldref.h:555
int ProcessID
Used to clearly identify process number/rank. 
Definition: worldtypes.h:37
RemoteCounter & operator=(const RemoteCounter &other)
Definition: worldref.h:315
RemoteCounterImpl(const std::shared_ptr< T > &p)
Definition: worldref.h:170
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
Defines simple templates for printing to std::cout "a la Python". 
bool has_owner() const 
Check that the world pointer has an owner. 
Definition: worldptr.h:185
void serialize(const Archive &ar) const 
Serialize the remote reference. 
Definition: worldref.h:593
RemoteCounter(const RemoteCounter &other)
Definition: worldref.h:301
RemoteCounterBase()
Definition: worldref.h:97
void swap(Vector< T, N > &l, Vector< T, N > &r)
Definition: array.h:308
const std::shared_ptr< T > & get_shared() const 
Definition: worldref.h:341
A global pointer address, valid anywhere in the world. 
Definition: worldptr.h:65
void print(const A &a)
Print a single item to std::cout terminating with new line. 
Definition: print.h:122
virtual ~RemoteCounterBase()
Definition: worldref.h:98
RemoteReference(const RemoteReference< T > &other)
Copy constructor. 
Definition: worldref.h:446
static void load(const Archive &ar, detail::RemoteCounter &c)
Definition: worldref.h:633
bool release()
Decrement the reference count. 
Definition: worldref.h:141
RemoteReference< T > & operator=(const RemoteReference< T > &other)
Copy conversion assignment operator. 
Definition: worldref.h:465
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces. 
Definition: chem/atomutil.cc:45
detail::ptr_traits< T >::reference referenceT
Definition: worldref.h:409
const double c
Definition: gfit.cc:200
RemoteReference< T > & operator=(const RemoteReference< U > &other)
Copy conversion assignment operator. 
Definition: worldref.h:476
long use_count() const 
Reference count accessor. 
Definition: worldref.h:549
void swap(mpfr::mpreal &x, mpfr::mpreal &y)
Definition: mpreal.h:3069
RemoteCounter()
Definition: worldref.h:299
virtual ~RemoteCounterImpl()
Definition: worldref.h:174
~RemoteCounter()
Definition: worldref.h:313
bool is_local() const 
Check that the world pointer references a local pointer. 
Definition: worldptr.h:179
const std::shared_ptr< T > & get_shared() const 
Reference shared_ptr accssor. 
Definition: worldref.h:518
Defines and implements a concurrent hashmap.