PSCF v1.4.0
Pscf::HostDArray< Data > Class Template Reference

Template for dynamic array stored in host CPU memory. More...

#include <HostDArray.h>

Inheritance diagram for Pscf::HostDArray< Data >:
Util::DArray< Data > Util::Array< Data >

Public Types

using ValueType = Data
 Data type of each element.

Public Member Functions

 HostDArray ()
 Default constructor.
 HostDArray (int capacity)
 Allocating constructor.
 HostDArray (DeviceArray< Data > const &other)
 Copy constructor (copies from device to host).
virtual ~HostDArray ()
 Destructor.
HostDArray< Data > & operator= (DeviceArray< Data > const &other)
 Assignment operator, assign from a DeviceArray<Data>.
void copySlice (DeviceArray< Data > const &other, int beginId)
 Copy a slice of the data from a larger DeviceArray into this array.
Public Member Functions inherited from Util::DArray< Data >
 DArray ()
 Default constructor.
 DArray (int capacity)
 Allocating constructor.
 DArray (DArray< Data > const &other)
 Copy constructor.
virtual ~DArray ()
 Destructor.
DArray< Data > & operator= (DArray< Data > const &other)
 Assignment from a DArray<Data> container.
DArray< Data > & operator= (Array< Data > const &other)
 Assignment from an Array<Data> container.
void allocate (int capacity)
 Allocate the underlying C array.
void deallocate ()
 Deallocate the underlying C array.
void reallocate (int capacity)
 Reallocate the underlying C array and copy to new location.
bool isAllocated () const
 Return true if this DArray has been allocated, false otherwise.
template<class Archive>
void serialize (Archive &ar, const unsigned int version)
 Serialize a DArray to/from an Archive.
Public Member Functions inherited from Util::Array< Data >
int capacity () const
 Return allocated size.
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 & operator[] (int i)
 Get an element by non-const reference.
Data const & operator[] (int i) const
 Get an element by const reference.
Data * cArray ()
 Return a pointer to the underlying C array.
Data const * cArray () const
 Return pointer to const to the underlying C array.

Additional Inherited Members

Protected Member Functions inherited from Util::Array< Data >
 Array ()
 Constructor (protected to provent 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::HostDArray< Data >

Template for dynamic array stored in host CPU memory.

This class is provided as a convenience to allow the use of assigment (=) operators to copy data from device to host memory. A HostDArray<Data> stores data in a dynamically allocated array in host CPU memory, whereas a DeviceArray<Data> stores analogous data in global GPU device memory. Each of these classes defines
an assignment operation that allows assignment from the other, which silently copies the underlying arrays between device and host memory. Additionally, a method HostDArray::copySlice is provided, which populates a HostDArray with a slice of a larger DeviceArray.

Otherwise, this class is identical to Util::DArray, with the addition of an allocating constructor.

Definition at line 40 of file HostDArray.h.

Member Typedef Documentation

◆ ValueType

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

Data type of each element.

Definition at line 48 of file HostDArray.h.

Constructor & Destructor Documentation

◆ HostDArray() [1/3]

template<typename Data>
Pscf::HostDArray< Data >::HostDArray ( )

Default constructor.

Definition at line 134 of file HostDArray.h.

References Util::DArray< Data >::DArray().

Referenced by operator=().

◆ HostDArray() [2/3]

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

Allocating constructor.

This function calls allocate(capacity) internally.

Parameters
capacitynumber of elements to allocate

Definition at line 142 of file HostDArray.h.

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

◆ HostDArray() [3/3]

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

Copy constructor (copies from device to host).

Parameters
otherDeviceArray<Data> to be copied (input)

Definition at line 150 of file HostDArray.h.

References Util::DArray< Data >::allocate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Util::DArray< Data >::DArray(), and Pscf::DeviceArray< Data >::isAllocated().

◆ ~HostDArray()

template<typename Data>
Pscf::HostDArray< Data >::~HostDArray ( )
virtual

Destructor.

Deletes underlying C array, if allocated previously.

Definition at line 168 of file HostDArray.h.

Member Function Documentation

◆ operator=()

template<typename Data>
HostDArray< Data > & Pscf::HostDArray< Data >::operator= ( DeviceArray< Data > const & other)

Assignment operator, assign from a DeviceArray<Data>.

Performs a deep copy from a RHS DeviceArray<Data> to this LHS HostDArray<D>, by copying the underlying data from device memory to host memory.

Preconditions: The RHS DeviceArray<Data> object must be allocated.
If this LHS HostDArray<D> is not allocated, the required memory will be allocated before values are copied. Otherwise, if this LHS array is allocated on entry, capacites for LHS and RHS objects must be equal.

Exceptions
Exceptionif the RHS array is not allocated on entry
Exceptionif LHS and RHS have unequal nonzero capacities
Parameters
otherDeviceArray<Data> array on RHS of assignment (input)

Definition at line 176 of file HostDArray.h.

References Util::DArray< Data >::allocate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Util::DArray< Data >::DArray(), HostDArray(), Pscf::DeviceArray< Data >::isAllocated(), Util::DArray< Data >::isAllocated(), and UTIL_THROW.

◆ copySlice()

template<typename Data>
void Pscf::HostDArray< Data >::copySlice ( DeviceArray< Data > const & other,
int beginId )

Copy a slice of the data from a larger DeviceArray into this array.

This method will populate this HostDArray with data from a slice of a DeviceArray. The size of the slice is the capacity of this HostDArray (i.e., this entire array will be populated), and the position of the slice within the DeviceArray is indicated by the input parameter beginId.

The capacity of the RHS DeviceArray must thus be greater than or equal to the sum of beginId and the capacity of this HostDArray.

Parameters
otherDeviceArray<Data> object from which to copy slice
beginIdindex of other array at which slice begins

Definition at line 205 of file HostDArray.h.

References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Util::DArray< Data >::DArray(), Pscf::DeviceArray< Data >::isAllocated(), Util::DArray< Data >::isAllocated(), and UTIL_THROW.


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