PSCF v1.2
|
Template for dynamic array stored in host CPU memory. More...
#include <HostDArray.h>
Public Types | |
typedef Data | ElementType |
Data type of each element. | |
Public Member Functions | |
HostDArray () | |
Default constructor. | |
HostDArray (int capacity) | |
Allocating constructor. | |
HostDArray (DArray< Data > const &other) | |
Copy constructor. | |
virtual | ~HostDArray () |
Destructor. | |
virtual HostDArray< Data > & | operator= (const DeviceArray< Data > &other) |
Assignment operator, assign from DeviceArray<Data> device array. | |
void | copySlice (DeviceArray< Data > const &other, int beginId) |
Copy a slice of the data from a larger DeviceArray into this array. | |
![]() | |
DArray () | |
Default constructor. | |
DArray (DArray< Data > const &other) | |
Copy constructor. | |
virtual | ~DArray () |
Destructor. | |
DArray< Data > & | operator= (DArray< Data > const &other) |
Assignment operator. | |
void | allocate (int capacity) |
Allocate the underlying C array. | |
void | deallocate () |
Dellocate 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. | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize a DArray to/from an Archive. | |
![]() | |
virtual | ~Array () |
Destructor. | |
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 | |
![]() | |
Array () | |
Default constructor. | |
![]() | |
Data * | data_ |
Pointer to an array of Data elements. | |
int | capacity_ |
Allocated size of the data_ array. | |
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 between corresponding containers that store array data in device vs. 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 the HostDArray with a slice of the data from a larger DeviceArray.
Otherwise, this class is identical to Util::DArray, with the addition of an allocating constructor.
Definition at line 42 of file HostDArray.h.
Data Pscf::HostDArray< Data >::ElementType |
Data type of each element.
Definition at line 50 of file HostDArray.h.
Pscf::HostDArray< Data >::HostDArray | ( | ) |
Default constructor.
Definition at line 123 of file HostDArray.h.
Pscf::HostDArray< Data >::HostDArray | ( | int | capacity | ) |
Allocating constructor.
This function calls allocate(capacity) internally.
capacity | number of elements to allocate |
Definition at line 131 of file HostDArray.h.
References Util::DArray< T >::allocate(), and Util::Array< Data >::capacity().
Pscf::HostDArray< Data >::HostDArray | ( | DArray< Data > const & | other | ) |
Copy constructor.
(Copies from any DArray or HostDArray).
other | DArray<Data> to be copied (input) |
Definition at line 139 of file HostDArray.h.
|
virtual |
Destructor.
Deletes underlying C array, if allocated previously.
Definition at line 147 of file HostDArray.h.
|
virtual |
Assignment operator, assign from DeviceArray<Data> device array.
Performs a deep copy from a RHS DeviceArray<Data> device array to this LHS HostDArray<D> host array, by copying the underlying C array from device memory to host memory.
The RHS DeviceArray<Data> object must be allocated. If this LHS HostDArray<D> is not allocated, the correct size block of memory will be allocated. Otherwise, if this LHS object is allocated on entry, capacity values for LHS and RHS objects must be equal.
Exceptions are thrown if the RHS array is not allocated or if both arrays are allocated but have unequal capacities.
other | DeviceArray<Data> array on RHS of assignment (input) |
Definition at line 155 of file HostDArray.h.
References Util::DArray< T >::allocate(), Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), and UTIL_THROW.
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.
Therefore, the capacity of the DeviceArray must be >= the capacity of this HostDArray plus beginId.
other | DeviceArray<Data> object from which to copy slice |
beginId | index of other array at which slice begins |
Definition at line 184 of file HostDArray.h.
References Pscf::DeviceArray< Data >::capacity(), Pscf::DeviceArray< Data >::cArray(), Pscf::DeviceArray< Data >::isAllocated(), and UTIL_THROW.