33#ifndef MADNESS_WORLD_WORLDREF_H__INCLUDED
34#define MADNESS_WORLD_WORLDREF_H__INCLUDED
48#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
55 template <
typename T>
class RemoteReference;
63 template <
typename T>
class RemoteCounterImpl;
93 virtual void*
key()
const = 0;
105 template <
typename T>
117#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
119 print(
">>> RemoteCounterBase(", this->
key(),
") +ref count=", c + 1);
130#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
132 print(
">>> RemoteCounterBase(", this->
key(),
") -ref count=", c - 1);
146 template <
typename T>
174 virtual void*
key()
const {
return static_cast<void*
>(
pointer_.get()); }
213#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
214 print(
">>> RemoteCounter::unregister_ptr_: key=",
pimpl_->key(),
", value=",
pimpl_);
237 template <
typename T>
240 if(
p.get() ==
nullptr)
243 pimpl_mapT::accessor acc;
245 if(
pimpl_map_.insert(acc,
static_cast<void*
>(
p.get()))) {
257#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
258 print(
">>> RemoteCounter::register_ptr_(new): key=",
p.get(),
", pimpl=", acc->second);
263#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
264 print(
">>> RemoteCounter::register_ptr_(existing): key=", acc->second->key(),
", pimpl=", acc->second);
266 acc->second->add_ref();
296 template <
typename T>
328 template <
typename T>
340 template <
typename,
typename,
typename>
343 template <
typename,
typename,
typename>
346 template <
typename Archive>
352#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
357 template <
typename Archive>
361 if(! ar.count_only()) {
362#ifdef MADNESS_REMOTE_REFERENCE_DEBUG
377 std::ostream&
operator<<(std::ostream& out,
const RemoteCounter& counter);
394 template <
typename T>
443 template <
typename U>
463 template <
typename U>
489 operator bool()
const {
551 template <
typename U>
580 template <
typename Archive>
593 out <<
"RemoteReference( pointer=" << ref.
pointer_ <<
" counter=" << ref.
counter_ <<
")";
604 template <
typename T,
typename U>
614 template <
typename T>
619 template <
typename Archive>
626 template <
typename Archive>
double w(double t, double eps)
Definition DKops.h:22
Interface templates for the archives (serialization).
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
Simple structure used to manage references/pointers to remote instances.
Definition worldref.h:395
RemoteReference< T > & operator=(const RemoteReference< U > &other)
Copy conversion assignment operator.
Definition worldref.h:464
pointerT operator->() const
Reference object pointer accessor.
Definition worldref.h:527
T * pointerT
Definition worldref.h:398
RemoteReference< T > & operator=(const RemoteReference< T > &other)
Copy conversion assignment operator.
Definition worldref.h:453
bool unique() const
Get uniqueness.
Definition worldref.h:543
static void reset_handler(const AmArg &arg)
Definition worldref.h:410
pointerT pointer_
World pointer.
Definition worldref.h:401
const std::shared_ptr< T > & get_shared() const
Reference shared_ptr accessor.
Definition worldref.h:506
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
World & get_world() const
Owning world accessor.
Definition worldref.h:574
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
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
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
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:205
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 &)
virtual void * key() const =0
Counter key accessor.
bool release()
Decrement the reference count.
Definition worldref.h:129
void add_ref()
Increment the reference count.
Definition worldref.h:116
RemoteCounterBase()
Definition worldref.h:85
const std::shared_ptr< T > & get_shared() const
Shared pointer accessor.
Definition worldref.h:106
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
const std::shared_ptr< T > & get_shared() const
Shared pointer accessor.
Definition worldref.h:167
virtual ~RemoteCounterImpl()
Definition worldref.h:162
RemoteCounterImpl(const std::shared_ptr< T > &p)
Definition worldref.h:158
virtual void * key() const
Counter key accessor.
Definition worldref.h:174
std::shared_ptr< T > pointer_
pointer that is remotely referenced
Definition worldref.h:155
Remote reference counter.
Definition worldref.h:190
void load_(const Archive &ar)
Definition worldref.h:347
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
RemoteCounter & operator=(const RemoteCounter &other)
Definition worldref.h:303
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
bool empty() const
Definition worldref.h:322
WorldPtr< implT >::worldidT get_worldid() const
Definition worldref.h:332
World & get_world() const
Definition worldref.h:333
const std::shared_ptr< T > & get_shared() const
Definition worldref.h:329
bool is_local() const
Definition worldref.h:324
static WorldPtr< implT > register_ptr_(World &w, const std::shared_ptr< T > &p)
Register a local shared pointer.
Definition worldref.h:238
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
void swap(WorldPtr< U > &other)
Swap the content of this with other.
Definition worldptr.h:347
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:2503
#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
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
constexpr void swap(Vector< T, N > &l, Vector< T, N > &r)
Swap the contents of two Vectors.
Definition vector.h:518
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
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