PSCF v1.5.0
Pscf::FftwDRArray< Data > Class Template Reference

Dynamic reference counted array for use with FFTW library. More...

#include <FftwDRArray.h>

Inheritance diagram for Pscf::FftwDRArray< Data >:
Util::Array< Data > Util::ReferenceCounter Pscf::BackendArray< Data, CPT >

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.

Detailed Description

template<typename Data>
class Pscf::FftwDRArray< Data >

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.

Member Typedef Documentation

◆ ValueType

template<typename Data>
using Pscf::FftwDRArray< Data >::ValueType = Data

Data type of each array element.

Definition at line 79 of file FftwDRArray.h.

Constructor & Destructor Documentation

◆ FftwDRArray() [1/3]

template<typename Data>
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=().

◆ FftwDRArray() [2/3]

template<typename Data>
Pscf::FftwDRArray< Data >::FftwDRArray ( int capacity)

Allocating constructor.

This function calls allocate(capacity) internally.

Parameters
capacitynumber of elements to allocate

Definition at line 31 of file FftwDRArray.tpp.

References allocate(), and Util::Array< Data >::capacity().

◆ FftwDRArray() [3/3]

template<typename Data>
Pscf::FftwDRArray< Data >::FftwDRArray ( FftwDRArray< Data > const & other)

◆ ~FftwDRArray()

template<typename Data>
Pscf::FftwDRArray< Data >::~FftwDRArray ( )
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().

Member Function Documentation

◆ operator=() [1/2]

template<typename Data>
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.

Exceptions
Exceptionif other array is not allocated
Exceptionif arrays are allocated with unequal capacities
Parameters
otherarray 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.

◆ operator=() [2/2]

template<typename Data>
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.

Exceptions
Exceptionif other array is not allocated
Exceptionif arrays are allocated with unequal capacities
Parameters
otherarray 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.

◆ allocate()

template<typename Data>
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.

Exceptions
Exceptionif this array is allocated on entry.
Parameters
capacitynumber 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().

◆ deallocate()

template<typename Data>
void Pscf::FftwDRArray< Data >::deallocate ( )
virtual

Dellocate an underlying C array that is owned by this container.

After exit, isAllocated(), isOwner(), and isAssociated() will all return false.

Exceptions
Exceptionif 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().

◆ associate() [1/2]

template<typename Data>
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.

Exceptions
Exceptionif this array is allocated on entry.
Exceptionif other array is not a data owner on entry.
Parameters
otherparent array that owns the data
beginIdindex in of other array at which slice begins
capacitynumber 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().

◆ associate() [2/2]

template<typename Data>
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.

Exceptions
Exceptionif this array is allocated
Exceptionif other array is not a data owner
Parameters
otherarray that owns the data

Definition at line 187 of file FftwDRArray.tpp.

References associate(), Util::Array< Data >::capacity(), and FftwDRArray().

◆ dissociate()

template<typename Data>
void Pscf::FftwDRArray< Data >::dissociate ( )

Dissociate this object from an externally owned array slice.

After exit, isAllocated(), isOwner(), and isAssociated() will all return false.

Exceptions
Exceptionif 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.

◆ serialize()

template<typename Data>
template<class Archive>
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.

Exceptions
Exceptionif a write is attempted for a data user
Parameters
ararchive
versionarchive 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().

◆ isOwner()

template<typename Data>
bool Pscf::FftwDRArray< Data >::isOwner ( ) const
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().

◆ isAssociated()

template<typename Data>
bool Pscf::FftwDRArray< Data >::isAssociated ( ) const
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_.


The documentation for this class was generated from the following files: