|
PSCF v1.5.0
|
Dynamic reference counted array for use with FFTW library. More...
#include <FftwDRArray.h>
Public Types | |
| using | ValueType = Data |
| Data type of each array element. | |
Public Member Functions | |
| FftwDRArray () | |
| Default constructor. | |
| FftwDRArray (int capacity) | |
| Allocating constructor. | |
| FftwDRArray (FftwDRArray< Data > const &other) | |
| Copy constructor. | |
| virtual | ~FftwDRArray () |
| Destructor. | |
| FftwDRArray< Data > & | operator= (FftwDRArray< Data > const &other) |
| Assignment from another FftwDRArray<Data> container. | |
| FftwDRArray< Data > & | operator= (Array< Data > const &other) |
| Assignment from an Array<Data> container. | |
| void | allocate (int capacity) |
| Allocate an underlying C array, which this container then owns. | |
| virtual void | deallocate () |
| Dellocate an underlying C array that is owned by this container. | |
| void | associate (FftwDRArray< Data > &other, int beginId, int capacity) |
| Associate this object with a slice of a different FftwDRArray. | |
| void | associate (FftwDRArray< Data > &other) |
| Associate this object with all of a different FftwDRArray. | |
| void | dissociate () |
| Dissociate this object from an externally owned array slice. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int version) |
| Serialize an FftwDRArray to/from an Archive. | |
| bool | isOwner () const |
| Does this container own a dynamically allocated C array? | |
| bool | isAssociated () const |
| Is this container associated with a C array it does not own? | |
| Public Member Functions inherited from Util::Array< Data > | |
| Data & | operator[] (int i) |
| Get an element by non-const reference. | |
| Data const & | operator[] (int i) const |
| Get an element by const reference. | |
| void | begin (ArrayIterator< Data > &iterator) |
| Set an iterator to begin this Array. | |
| void | begin (ConstArrayIterator< Data > &iterator) const |
| Set a const iterator to begin this array. | |
| Data * | cArray () |
| Return a pointer to the underlying C array (non-const data). | |
| Data const * | cArray () const |
| Return pointer to the underlying C array (const data). | |
| bool | isAllocated () const |
| Does this array have associated data? | |
| int | size () const |
| Return logical size of array. | |
| int | capacity () const |
| Return allocated size. | |
| Public Member Functions inherited from Util::ReferenceCounter | |
| ReferenceCounter () | |
| Constructor. | |
| int | nRef () const |
| Get the number of references to a shareable resource. | |
| bool | hasRefs () const |
| Does this counter have references (is nRef > 0)? | |
Additional Inherited Members | |
| Protected Member Functions inherited from Util::Array< Data > | |
| Array () | |
| Constructor (protected to prevent direct instantiation). | |
| ~Array () | |
| Destructor (protected to prevent direct destruction). | |
| Protected Attributes inherited from Util::Array< Data > | |
| Data * | data_ |
| Pointer to an array of Data elements. | |
| int | capacity_ |
| Allocated size of the data_ array. | |
Dynamic reference counted array for use with FFTW library.
The allocate and deallocate functions of this class use functions provided by the FFTW library to allocate and free aligned memory.
A FftwDRArray may be in any of three states:
(1) Unallocated: In this state, there is no associated memory, so capacity() returns 0, while isAllocated(), isOwner() and isAssociated() all return false.
(2) A data owner: In this case, this object owns a C array that it is responsible for de-allocating. In this state, capacity() returns a positive integer, isAllocated() and isOwner() return true, and isAssociated() returns false.
(3) A data user: In this case, this object has a pointer to a C array that is owned by a different FftwDRArray object. In this state, capacity() returns a positive value, isAllocated() and isAssociated() return true, and isOwner() returns false.
An FftwDArray that is a data user is said to be "associated" with a C array that is owned by another object (the data owner), or to "reference" that array.
An FftwDRArray is said to be "allocated" if it refers to memory, as either a data owner or a data user. When an FftwDRArray is allocated, array elements may be accessed via a subscript ([]) operator that is inherited from the Array<Data> base class.
A FftwDRArray that owns a C array that is referenced by one or more other associated FftwDRArray objects maintains a count of how many other such objects reference its data. This counter is automatically incremented when an association is created and decremented when such an association is released.
Member functions allow a FftwDRArray to allocate or deallocate a C array that it owns, or to create or release an association with an array slice that it references but does not own. It is a logical error to invoke the deallocate() member function of a FftwDRArray that is not allocated or that references data that it does not own. In either case, an Exception is thrown. It is also an error to attempt to deallocate an FftwDRArray that is referenced by one other associated FftwDRArray data users.
Definition at line 71 of file FftwDRArray.h.
| using Pscf::FftwDRArray< Data >::ValueType = Data |
Data type of each array element.
Definition at line 79 of file FftwDRArray.h.
| Pscf::FftwDRArray< Data >::FftwDRArray | ( | ) |
Default constructor.
Definition at line 24 of file FftwDRArray.tpp.
Referenced by associate(), associate(), Pscf::BackendArray< Data, CPT >::BackendArray(), FftwDRArray(), and operator=().
| Pscf::FftwDRArray< Data >::FftwDRArray | ( | int | capacity | ) |
Allocating constructor.
This function calls allocate(capacity) internally.
| capacity | number of elements to allocate |
Definition at line 31 of file FftwDRArray.tpp.
References allocate(), and Util::Array< Data >::capacity().
| Pscf::FftwDRArray< Data >::FftwDRArray | ( | FftwDRArray< Data > const & | other | ) |
Copy constructor.
| other | the FftwDRArray to be copied |
Definition at line 38 of file FftwDRArray.tpp.
References allocate(), Util::Array< Data >::capacity_, Util::Array< Data >::cArray(), Util::Array< Data >::data_, FftwDRArray(), Util::Array< Data >::isAllocated(), and UTIL_THROW.
|
virtual |
Destructor.
Deletes any C array that is owned by this object, and releases any association with a C Array that is referred to but not owned by this object. If this object owns an array that is referred to by one or more other FftwDRArray objects, an error message is written to std::cout.
Definition at line 51 of file FftwDRArray.tpp.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::ReferenceCounter::hasRefs(), Util::ReferenceCounter::nRef(), and Util::Memory::sub().
| FftwDRArray< Data > & Pscf::FftwDRArray< Data >::operator= | ( | FftwDRArray< Data > const & | other | ) |
Assignment from another FftwDRArray<Data> container.
Performs a deep copy, by copying values of all elements of another FftwDRArray<Data> container. If this LHS array is already allocated on entry, it must have the same capacity as the other RHS array. If this LHS array is not allocated on entry, required memory is allocated before copying values. After exit, isAllocated() and isOwner() return true, while isAssociated() returns false.
| Exception | if other array is not allocated |
| Exception | if arrays are allocated with unequal capacities |
| other | array container on RHS of assigment (input) |
Definition at line 78 of file FftwDRArray.tpp.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::cArray(), Util::Array< Data >::data_, FftwDRArray(), Util::Array< Data >::isAllocated(), and UTIL_CHECK.
| FftwDRArray< Data > & Pscf::FftwDRArray< Data >::operator= | ( | Array< Data > const & | other | ) |
Assignment from an Array<Data> container.
Performs a deep copy, by copying values of all elements of an Array<Data> container. If this (LHS) array is already allocated on entry, it must have the same capacity as the other (RHS) array. If this LHS array is not allocated on entry, required memory is allocated before copying values. After exit, isAllocated() and isOwner() return true, while isAssociated() returns false.
| Exception | if other array is not allocated |
| Exception | if arrays are allocated with unequal capacities |
| other | array container on RHS of assigment (input) |
Definition at line 103 of file FftwDRArray.tpp.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::cArray(), Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_CHECK.
| void Pscf::FftwDRArray< Data >::allocate | ( | int | capacity | ) |
Allocate an underlying C array, which this container then owns.
On entry, this object must be unallocated, i.e., it must not have data that it either owns or references. After exit, isAllocated() and isOwner() will return true, while isAssociated() will return false.
| Exception | if this array is allocated on entry. |
| capacity | number of elements to allocate |
Definition at line 127 of file FftwDRArray.tpp.
References Util::Memory::add(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_THROW.
Referenced by Pscf::CField< D, CPT >::allocate(), Pscf::RField< D, CPT >::allocate(), Pscf::RFieldDft< D, CPT >::allocate(), FftwDRArray(), FftwDRArray(), operator=(), operator=(), and serialize().
|
virtual |
Dellocate an underlying C array that is owned by this container.
After exit, isAllocated(), isOwner(), and isAssociated() will all return false.
| Exception | if this object does not own data. |
Definition at line 144 of file FftwDRArray.tpp.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::ReferenceCounter::hasRefs(), Util::Memory::sub(), and UTIL_CHECK.
Referenced by Pscf::CField< D, CPT >::deallocate(), Pscf::RField< D, CPT >::deallocate(), and Pscf::RFieldDft< D, CPT >::deallocate().
| void Pscf::FftwDRArray< Data >::associate | ( | FftwDRArray< Data > & | other, |
| int | beginId, | ||
| int | capacity ) |
Associate this object with a slice of a different FftwDRArray.
On entry, this object must be not be allocated, i.e., it must not have data that it either owns or references. After exit, isAllocated() and isAssociated() will return true, while isOwner() will return false.
| Exception | if this array is allocated on entry. |
| Exception | if other array is not a data owner on entry. |
| other | parent array that owns the data |
| beginId | index in of other array at which slice begins |
| capacity | number of elements in the slice |
Definition at line 159 of file FftwDRArray.tpp.
References Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::cArray(), Util::Array< Data >::data_, FftwDRArray(), Util::Array< Data >::isAllocated(), isOwner(), and UTIL_CHECK.
Referenced by associate().
| void Pscf::FftwDRArray< Data >::associate | ( | FftwDRArray< Data > & | other | ) |
Associate this object with all of a different FftwDRArray.
This function associates this FftwDRArray with all of another FftwDRArray that is a data owner. The function associate(other) is equivalent to associate(other, 0, other.capacity()).
On entry, this object must be not be allocated, i.e., it must not have data that it either owns or references, while the other array must own data. After exit, isAllocated() and isAssociated() will return true, while isOwner() will return false.
| other | array that owns the data |
Definition at line 187 of file FftwDRArray.tpp.
References associate(), Util::Array< Data >::capacity(), and FftwDRArray().
| void Pscf::FftwDRArray< Data >::dissociate | ( | ) |
Dissociate this object from an externally owned array slice.
After exit, isAllocated(), isOwner(), and isAssociated() will all return false.
| Exception | if this is not associated with another array |
Definition at line 194 of file FftwDRArray.tpp.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, and UTIL_CHECK.
| void Pscf::FftwDRArray< Data >::serialize | ( | Archive & | ar, |
| const unsigned int | version ) |
Serialize an FftwDRArray to/from an Archive.
Precondition: To serialize to a write archive, this array must be unallocated or a data owner.
| Exception | if a write is attempted for a data user |
| ar | archive |
| version | archive version id |
Definition at line 294 of file FftwDRArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), isOwner(), and UTIL_CHECK.
Referenced by Pscf::CField< D, CPT >::serialize(), Pscf::RField< D, CPT >::serialize(), and Pscf::RFieldDft< D, CPT >::serialize().
|
inline |
Does this container own a dynamically allocated C array?
If isAllocated() is false, isOwner() is also false. If isAllocated() is true, either isOwner() or isAsssociated() must be true, but not both.
Definition at line 279 of file FftwDRArray.h.
References Util::Array< Data >::data_.
Referenced by associate(), and serialize().
|
inline |
Is this container associated with a C array it does not own?
If isAllocated() is false, isAssociated() is also false.
Definition at line 286 of file FftwDRArray.h.
References Util::Array< Data >::data_.